Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: ReforgeAPI fix hard crash for unkown stat #2562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/api/ReforgeAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.model.SkyblockStat
import at.hannibal2.skyhanni.data.model.SkyblockStatList
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
Expand Down Expand Up @@ -176,7 +177,18 @@ object ReforgeAPI {
while (reader.hasNext()) {
val name = reader.nextName()
val value = reader.nextDouble()
list[SkyblockStat.valueOf(name.uppercase())] = value

val stat = SkyblockStat.getValueOrNull(name.uppercase()) ?: run {
ErrorManager.logErrorStateWithData(
"Unknown stat: '${name.uppercase()}'",
"Stat list could not parse stat",
"failed" to name.uppercase(),
betaOnly = true,
)
continue
}

list[stat] = value
}
reader.endObject()
return list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ enum class SkyblockStat(val icon: String) {

FEAR("§a☠"),
HEAT_RESISTANCE("§c♨"),

UNKNOWN("§c?")
;

val capitalizedName = name.lowercase().allLettersFirstUppercase()
Expand All @@ -65,6 +67,10 @@ enum class SkyblockStat(val icon: String) {
val fontSizeOfLargestIcon by lazy {
entries.maxOf { Minecraft.getMinecraft().fontRendererObj.getStringWidth(it.icon) } + 1
}

fun getValueOrNull(string: String): SkyblockStat? = entries.firstOrNull { it.name == string }

fun getValue(string: String): SkyblockStat = getValueOrNull(string) ?: UNKNOWN
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object SkyHanniTypeAdapters {

val SKYBLOCK_STAT: TypeAdapter<SkyblockStat> = SimpleStringTypeAdapter(
{ name.lowercase() },
{ SkyblockStat.valueOf(this.uppercase()) },
{ SkyblockStat.getValue(this.uppercase()) },
)

val TRACKER_DISPLAY_MODE = SimpleStringTypeAdapter.forEnum<SkyHanniTracker.DefaultDisplayMode>()
Expand Down
Loading