Skip to content

Commit

Permalink
Fix minecraft default image.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 authored Nov 12, 2024
1 parent 12ef101 commit fcf1e6f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/MinecraftManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object MinecraftManager : BetterHudManager {
return map
}

private class MinecraftAsset(val namespace: String, val width: Int, val height: Int) {
private data class MinecraftAsset(val namespace: String, val width: Int, val height: Int) {
fun toJson(json: JsonArray, char: String, ascent: Int, scale: Double, font: Key): WidthComponent {
val newHeight = (height.toDouble() * scale).roundToInt()
val newWidth = (width.toDouble() / height.toDouble() * newHeight).roundToInt()
Expand All @@ -49,8 +49,15 @@ object MinecraftManager : BetterHudManager {
override fun start() {
}

private var previous = ""

override fun reload(sender: Audience, resource: GlobalResource) {
if (ConfigManagerImpl.loadMinecraftDefaultTextures) {
val current = if (ConfigManagerImpl.minecraftJarVersion == "bukkit") BOOTSTRAP.minecraftVersion() else ConfigManagerImpl.minecraftJarVersion
if (previous != current) {
previous = current
} else return
assetsMap.clear()
val cache = DATA_FOLDER.subFolder(".cache")
runWithExceptionHandling(sender, "Unable to load minecraft default textures.") {
val client = HttpClient.newHttpClient()
Expand All @@ -61,7 +68,6 @@ object MinecraftManager : BetterHudManager {
.build(), HttpResponse.BodyHandlers.ofInputStream()).body()).buffered().use {
parseJson(it)
}.asJsonObject
val current = if (ConfigManagerImpl.minecraftJarVersion == "bukkit") BOOTSTRAP.minecraftVersion() else ConfigManagerImpl.minecraftJarVersion
info("Current minecraft version: $current")
val file = File(cache, "$current.jar")
if (!file.exists() || file.length() == 0L) {
Expand Down Expand Up @@ -118,4 +124,4 @@ object MinecraftManager : BetterHudManager {

override fun end() {
}
}
}

0 comments on commit fcf1e6f

Please sign in to comment.