Skip to content

Commit c8ca60a

Browse files
authored
Remove submodules (#238)
* Removed submodules - No one used the libs anyways - Was making things unnecessary complicated * Remove weird import artifact * Still waiting for GitHub to allow delete caches. * Remove sourceSets * Not yet working * Cleanup error handling
1 parent 3d0452d commit c8ca60a

File tree

206 files changed

+2351
-327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+2351
-327
lines changed

.github/workflows/nightly_build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ jobs:
1717
- name: Check out repository
1818
uses: actions/checkout@v2
1919

20-
- name: Check out submodules
21-
uses: snickerbockers/submodules-init@v4
22-
2320
- name: Set up JDK
2421
uses: actions/setup-java@v1
2522
with:
2623
java-version: 1.8
2724

25+
- name: Fix wrapper permissions
26+
run: chmod +x ./gradlew
27+
2828
- name: Gradle cache
2929
uses: actions/cache@v2
3030
with:
3131
path: |
3232
~/.gradle/caches
3333
~/.gradle/wrapper
34-
key: ${{ runner.os }}-gradle-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/*.gradle*') }}
34+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
3535
restore-keys: |
36-
${{ runner.os }}-gradle-${{ secrets.CACHE_VERSION }}-
36+
${{ runner.os }}-gradle-
3737
3838
- name: Prepare workspace
3939
run: ./gradlew --no-daemon classes
4040

41-
- name : Build forge mod
42-
run : ./gradlew --build-cache build
41+
- name: Build forge mod
42+
run: ./gradlew --build-cache build
4343

4444
- name: Rename built forge mod
4545
run: mv build/libs/lambda-*.jar lambda-${{ github.run_number }}.jar

build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ apply plugin: 'net.minecraftforge.gradle'
2222
apply plugin: 'org.jetbrains.dokka'
2323
apply plugin: 'org.spongepowered.mixin'
2424

25-
sourceSets.main.java {
26-
srcDirs += 'src/main/cape-api'
27-
srcDirs += 'src/main/command'
28-
srcDirs += 'src/main/commons'
29-
srcDirs += 'src/main/event'
30-
}
31-
3225
compileJava {
3326
sourceCompatibility = targetCompatibility = '1.8'
3427
options.encoding = 'UTF-8'

setupWorkspace.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,15 @@
99
# To allow use from outside the lambda directory
1010
cd "$(dirname "$0")" || exit
1111

12-
echo "[$(date +"%H:%M:%S")] Checking if git is installed..."
13-
if [ -z "$(which git)" ]; then
14-
echo "[$(date +"%H:%M:%S")] ERROR: Git is not installed, please make sure you install the CLI version of git, not some desktop wrapper for it" >&2
15-
exit 1
16-
fi
17-
echo "[$(date +"%H:%M:%S")] Git is installed!"
18-
19-
#
20-
21-
echo "[$(date +"%H:%M:%S")] Checking for .git dir..."
22-
if [ ! -d ".git" ]; then
23-
echo "[$(date +"%H:%M:%S")] ERROR: Could not detect git repository, exiting" >&2
24-
exit 1
25-
fi
26-
echo "[$(date +"%H:%M:%S")] Found git repository!"
27-
28-
#
29-
30-
echo "[$(date +"%H:%M:%S")] Downloading git submodules..."
31-
git submodule update --init --recursive || {
32-
echo "[$(date +"%H:%M:%S")] ERROR: Failed to init git submodules"
33-
exit 1
34-
}
35-
echo "[$(date +"%H:%M:%S")] Downloaded git submodules!"
36-
37-
#
38-
3912
echo "[$(date +"%H:%M:%S")] Running gradlew classes without daemon..."
4013
./gradlew --no-daemon classes || {
4114
echo "[$(date +"%H:%M:%S")] ERROR: Running gradlew build failed! Run './gradlew --no-daemon classes' manually"
4215
exit 1
4316
}
4417

45-
#
46-
4718
cat logo_ascii.txt 2>/dev/null
4819
echo "=========================================================================="
4920
echo ""
50-
echo "[$(date +"%H:%M:%S")] Build succeeded! All checks passed, you can build normally now!"
21+
echo "[$(date +"%H:%M:%S")] Build succeeded! All checks passed, you can build normally now! Welcome to Lambda."
5122
echo ""
5223
echo "=========================================================================="

src/main/cape-api

Submodule cape-api deleted from e361382

src/main/command

Submodule command deleted from ab82bfc

src/main/commons

Submodule commons deleted from 6240ffb

src/main/event

Submodule event deleted from b6576a1
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package com.lambda.client.capeapi
2+
3+
import com.google.gson.GsonBuilder
4+
import com.google.gson.JsonParser
5+
import com.google.gson.reflect.TypeToken
6+
import com.lambda.client.commons.extension.synchronized
7+
import com.lambda.client.commons.utils.ConnectionUtils
8+
import org.apache.logging.log4j.Logger
9+
import java.io.File
10+
import java.io.FileWriter
11+
import java.util.*
12+
13+
abstract class AbstractUUIDManager(
14+
filePath: String,
15+
private val logger: Logger,
16+
private val maxCacheSize: Int = 500
17+
) {
18+
19+
private val file = File(filePath)
20+
21+
@Suppress("DEPRECATION")
22+
private val parser = JsonParser()
23+
private val gson = GsonBuilder().setPrettyPrinting().create()
24+
private val type = TypeToken.getArray(PlayerProfile::class.java).type
25+
26+
private val nameProfileMap = LinkedHashMap<String, PlayerProfile>().synchronized()
27+
private val uuidNameMap = LinkedHashMap<UUID, PlayerProfile>().synchronized()
28+
29+
fun getByString(stringIn: String?) = stringIn?.let { string ->
30+
UUIDUtils.fixUUID(string)?.let { getByUUID(it) } ?: getByName(string)
31+
}
32+
33+
fun getByUUID(uuid: UUID?) = uuid?.let {
34+
uuidNameMap.getOrPut(uuid) {
35+
getOrRequest(uuid.toString())?.also { profile ->
36+
// If UUID already present in nameUuidMap but not in uuidNameMap (user changed name)
37+
nameProfileMap[profile.name]?.let { uuidNameMap.remove(it.uuid) }
38+
nameProfileMap[profile.name] = profile
39+
} ?: return null
40+
}.also {
41+
trimMaps()
42+
}
43+
}
44+
45+
fun getByName(name: String?) = name?.let {
46+
nameProfileMap.getOrPut(name.lowercase()) {
47+
getOrRequest(name)?.also { profile ->
48+
// If UUID already present in uuidNameMap but not in nameUuidMap (user changed name)
49+
uuidNameMap[profile.uuid]?.let { nameProfileMap.remove(it.name) }
50+
uuidNameMap[profile.uuid] = profile
51+
} ?: return null
52+
}.also {
53+
trimMaps()
54+
}
55+
}
56+
57+
private fun trimMaps() {
58+
while (nameProfileMap.size > maxCacheSize) {
59+
nameProfileMap.remove(nameProfileMap.keys.first())?.also {
60+
uuidNameMap.remove(it.uuid)
61+
}
62+
}
63+
}
64+
65+
/**
66+
* Overwrites this if you want to get UUID from other source
67+
* eg. online player in game client
68+
*/
69+
protected open fun getOrRequest(nameOrUUID: String): PlayerProfile? {
70+
return requestProfile(nameOrUUID)
71+
}
72+
73+
private fun requestProfile(nameOrUUID: String): PlayerProfile? {
74+
val isUUID = UUIDUtils.isUUID(nameOrUUID)
75+
val response = if (isUUID) requestProfileFromUUID(nameOrUUID) else requestProfileFromName(nameOrUUID)
76+
77+
return if (response.isNullOrBlank()) {
78+
logger.error("Response is null or blank, internet might be down")
79+
null
80+
} else {
81+
try {
82+
@Suppress("DEPRECATION") val jsonElement = parser.parse(response)
83+
if (isUUID) {
84+
val name = jsonElement.asJsonArray.last().asJsonObject["name"].asString
85+
PlayerProfile(UUID.fromString(nameOrUUID), name)
86+
} else {
87+
val id = jsonElement.asJsonObject["id"].asString
88+
val name = jsonElement.asJsonObject["name"].asString
89+
PlayerProfile(UUIDUtils.fixUUID(id)!!, name) // let it throw a NPE if failed to parse the string to UUID
90+
}
91+
} catch (e: Exception) {
92+
logger.error("Failed parsing profile", e)
93+
null
94+
}
95+
}
96+
}
97+
98+
private fun requestProfileFromUUID(uuid: String): String? {
99+
return request("https://api.mojang.com/user/profiles/${UUIDUtils.removeDashes(uuid)}/names")
100+
}
101+
102+
private fun requestProfileFromName(name: String): String? {
103+
return request("https://api.mojang.com/users/profiles/minecraft/$name")
104+
}
105+
106+
private fun request(url: String): String? {
107+
return ConnectionUtils.requestRawJsonFrom(url) {
108+
logger.error("Failed requesting from Mojang API", it)
109+
}
110+
}
111+
112+
fun load(): Boolean {
113+
fixEmptyJson(file)
114+
return try {
115+
val cacheList = file.bufferedReader().use {
116+
gson.fromJson<Array<PlayerProfile>>(it, type)
117+
}
118+
uuidNameMap.clear()
119+
nameProfileMap.clear()
120+
uuidNameMap.putAll(cacheList.associateBy { it.uuid })
121+
nameProfileMap.putAll(cacheList.associateBy { it.name.lowercase() })
122+
logger.info("UUID cache loaded")
123+
true
124+
} catch (e: Exception) {
125+
logger.warn("Failed loading UUID cache", e)
126+
false
127+
}
128+
}
129+
130+
fun save(): Boolean {
131+
return try {
132+
val cacheList = uuidNameMap.values.sortedBy { it.name }
133+
file.bufferedWriter().use {
134+
gson.toJson(cacheList, it)
135+
}
136+
logger.info("UUID cache saved")
137+
true
138+
} catch (e: Exception) {
139+
logger.warn("Failed saving UUID cache", e)
140+
false
141+
}
142+
}
143+
144+
private fun fixEmptyJson(file: File) {
145+
if (!file.exists()) file.createNewFile()
146+
var notEmpty = false
147+
file.forEachLine { notEmpty = notEmpty || it.trim().isNotBlank() || it == "[]" || it == "{}" }
148+
149+
if (!notEmpty) {
150+
val fileWriter = FileWriter(file)
151+
try {
152+
fileWriter.write("[]")
153+
} catch (e: Exception) {
154+
logger.error("Failed to fix empty json", e)
155+
} finally {
156+
fileWriter.close()
157+
}
158+
}
159+
}
160+
161+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.lambda.client.capeapi
2+
3+
import com.google.gson.annotations.SerializedName
4+
import java.util.*
5+
6+
data class CapeUser(
7+
val id: Long,
8+
val capes: ArrayList<Cape>,
9+
@SerializedName("is_premium")
10+
var isPremium: Boolean = false
11+
) {
12+
override fun equals(other: Any?): Boolean {
13+
return this === other
14+
|| other is CapeUser
15+
&& other.id == this.id
16+
&& other.capes == capes
17+
}
18+
19+
override fun hashCode(): Int {
20+
return 31 * id.hashCode() + capes.hashCode()
21+
}
22+
}
23+
24+
data class Cape(
25+
@SerializedName("cape_uuid")
26+
val capeUUID: String = UUID.randomUUID().toString().substring(0, 5),
27+
@SerializedName("player_uuid")
28+
var playerUUID: UUID? = null,
29+
val type: CapeType,
30+
var color: CapeColor = type.color
31+
) {
32+
override fun equals(other: Any?): Boolean {
33+
return this === other
34+
|| other is Cape
35+
&& other.capeUUID == capeUUID
36+
&& other.type == other.type
37+
}
38+
39+
override fun hashCode(): Int {
40+
return 31 * capeUUID.hashCode() + type.hashCode()
41+
}
42+
}
43+
44+
data class CapeColor(
45+
val primary: String,
46+
val border: String
47+
) {
48+
override fun toString(): String {
49+
return "#$primary, #$border"
50+
}
51+
}
52+
53+
data class PlayerProfile(
54+
@SerializedName("uuid", alternate = ["UUID"])
55+
val uuid: UUID,
56+
@SerializedName("name", alternate = ["Name"])
57+
val name: String
58+
) {
59+
override fun equals(other: Any?): Boolean {
60+
return this === other
61+
|| other is PlayerProfile
62+
&& other.uuid == uuid
63+
}
64+
65+
override fun hashCode(): Int {
66+
return uuid.hashCode()
67+
}
68+
}
69+
70+
enum class CapeType(val realName: String, val imageKey: String, val color: CapeColor) {
71+
CONTRIBUTOR("Contributor", "github", CapeColor("272727", "363636"))
72+
}
73+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lambda.client.capeapi
2+
3+
import java.util.*
4+
5+
object UUIDUtils {
6+
private val uuidRegex = "[a-z0-9].{7}-[a-z0-9].{3}-[a-z0-9].{3}-[a-z0-9].{3}-[a-z0-9].{11}".toRegex()
7+
8+
fun fixUUID(string: String): UUID? {
9+
if (isUUID(string)) return UUID.fromString(string)
10+
if (string.length < 32) return null
11+
val fixed = insertDashes(string)
12+
return if (isUUID(fixed)) UUID.fromString(fixed)
13+
else null
14+
}
15+
16+
fun isUUID(string: String) = uuidRegex.matches(string)
17+
18+
fun removeDashes(string: String) = string.replace("-", "")
19+
20+
private fun insertDashes(string: String) = StringBuilder(string)
21+
.insert(8, '-')
22+
.insert(13, '-')
23+
.insert(18, '-')
24+
.insert(23, '-')
25+
.toString()
26+
}

0 commit comments

Comments
 (0)