diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-03-22 18:04:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 18:04:45 +0100 |
commit | a8973b851ad4d3edb0e6c605eb7aea29c6e66938 (patch) | |
tree | 4bb7e04fdc48022fb7d9bdcd42915078bf4f7952 /src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt | |
parent | 6231ce3132dd22b539ed76d5999d281d9109ae0b (diff) | |
download | skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.tar.gz skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.tar.bz2 skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.zip |
Improvement: Load Trophy Fishing from NEU (#1123)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 5b095fa74..4d98581c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson +import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory @@ -15,6 +16,7 @@ import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil.isInt import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker @@ -22,6 +24,7 @@ import com.google.gson.GsonBuilder import com.google.gson.JsonObject import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis @@ -134,6 +137,32 @@ class ConfigManager { return reader.nextString().toLong().asTimeMark() } }.nullSafe()) + .registerTypeAdapter(HypixelApiTrophyFish::class.java, object : TypeAdapter<HypixelApiTrophyFish>() { + override fun write(out: JsonWriter, value: HypixelApiTrophyFish) {} + + override fun read(reader: JsonReader): HypixelApiTrophyFish { + val trophyFish = mutableMapOf<String, Int>() + var totalCaught = 0 + reader.beginObject() + while (reader.hasNext()) { + val key = reader.nextName() + if (key == "total_caught") { + totalCaught = reader.nextInt() + continue + } + if (reader.peek() == JsonToken.NUMBER) { + val valueAsString = reader.nextString() + if (valueAsString.isInt()) { + trophyFish[key] = valueAsString.toInt() + continue + } + } + reader.skipValue() + } + reader.endObject() + return HypixelApiTrophyFish(totalCaught, trophyFish) + } + }.nullSafe()) .enableComplexMapKeySerialization() .create() |