aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt39
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) {