From 4f3309f1f2d17e3cde4544dc9f6325b0d9bfd721 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sat, 24 Feb 2024 10:17:22 +1100 Subject: Make hypixel items api response a proper json object #1039 --- .../skyhanni/features/bazaar/BazaarDataHolder.kt | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt index 44ce4b481..02e1f1446 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.features.bazaar import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.jsonobjects.other.SkyblockItemsDataJson import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.APIUtil @@ -11,8 +13,7 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.getDoubleOrNull -import at.hannibal2.skyhanni.utils.getStringOrNull +import at.hannibal2.skyhanni.utils.fromJson import kotlinx.coroutines.launch import kotlin.concurrent.fixedRateTimer @@ -28,28 +29,21 @@ class BazaarDataHolder { private fun loadNpcPrices(): MutableMap { val list = mutableMapOf() - val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/v2/resources/skyblock/items") - + val apiResponse = APIUtil.getJSONResponse("https://api.hypixel.net/v2/resources/skyblock/items") try { - val motesPrice = mutableMapOf() - for (item in itemsData.getAsJsonArray("items")) { - val itemData = item.asJsonObject + val itemsData = ConfigManager.gson.fromJson(apiResponse) - val hypixelId = itemData.getStringOrNull("id") ?: continue - val neuItemId = NEUItems.transHypixelNameToInternalName(hypixelId) - - itemData.getDoubleOrNull("npc_sell_price")?.let { - list[neuItemId] = it - } - itemData.getDoubleOrNull("motes_sell_price")?.let { - motesPrice[neuItemId] = it - } + val motesPrice = mutableMapOf() + for (item in itemsData.items) { + val neuItemId = NEUItems.transHypixelNameToInternalName(item.id ?: continue) + item.npcPrice?.let { list[neuItemId] = it } + item.motesPrice?.let { motesPrice[neuItemId] = it } } RiftAPI.motesPrice = motesPrice } catch (e: Throwable) { ErrorManager.logErrorWithData( e, "Error getting npc sell prices", - "hypixelApiResponse" to itemsData + "hypixelApiResponse" to apiResponse ) } return list -- cgit