diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-04-12 23:17:26 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 15:17:26 +0200 |
commit | 7960d2ad27ac68ea9dcfaf848bd611b13db0af87 (patch) | |
tree | a875bcc3b55c501d27cdcbfa6d7af1260556efab /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 30b0321f8c7de975375252c7a49b03baa605db6f (diff) | |
download | skyhanni-7960d2ad27ac68ea9dcfaf848bd611b13db0af87.tar.gz skyhanni-7960d2ad27ac68ea9dcfaf848bd611b13db0af87.tar.bz2 skyhanni-7960d2ad27ac68ea9dcfaf848bd611b13db0af87.zip |
Backend: Update farming weight api links and format (#1308)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 87a265c84..3d6f0e74e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelPlayerApiJson import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson import at.hannibal2.skyhanni.events.NeuProfileDataLoadedEvent @@ -11,9 +12,14 @@ import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.isInt import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.JsonObject import com.google.gson.JsonPrimitive +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.notenoughupdates.NEUManager import io.github.moulberry.notenoughupdates.NEUOverlay import io.github.moulberry.notenoughupdates.NotEnoughUpdates @@ -43,6 +49,37 @@ object NEUItems { private val recipesCache = mutableMapOf<NEUInternalName, Set<NeuRecipe>>() private val ingredientsCache = mutableMapOf<NeuRecipe, Set<Ingredient>>() + private val hypixelApiGson by lazy { + ConfigManager.createBaseGsonBuilder() + .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()) + .create() + } + var allItemsCache = mapOf<String, NEUInternalName>() // item name -> internal name val allInternalNames = mutableListOf<NEUInternalName>() val ignoreItemsFilter = MultiFilter() @@ -70,7 +107,7 @@ object NEUItems { fun onProfileDataLoaded(event: ProfileDataLoadedEvent) { val apiData = event.data ?: return try { - val playerData = ConfigManager.gson.fromJson<HypixelPlayerApiJson>(apiData) + val playerData = hypixelApiGson.fromJson<HypixelPlayerApiJson>(apiData) NeuProfileDataLoadedEvent(playerData).postAndCatch() } catch (e: Exception) { |