diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-15 14:10:38 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-15 14:10:38 +0100 |
commit | 33636b0be087ed19c1092a65356a2a6b15f200fa (patch) | |
tree | ba89f111a74d2c8d8bc837dd94953b471744af1f /src | |
parent | 5a5de07c999d05d372f31c79e2b51b2cfabbebb5 (diff) | |
download | skyhanni-33636b0be087ed19c1092a65356a2a6b15f200fa.tar.gz skyhanni-33636b0be087ed19c1092a65356a2a6b15f200fa.tar.bz2 skyhanni-33636b0be087ed19c1092a65356a2a6b15f200fa.zip |
More consistent error handling in EliteFarmingWeight
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt index a8dda617d..a78f9d0ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt @@ -66,7 +66,7 @@ class EliteFarmingWeight { private var lastLeaderboardUpdate = 0L private var apiError = false private var leaderboardPosition = -1 - private var bonusWeight = -1 + private var bonusWeight = -2 private var cropWeight = 0.0 private var dirtyCropWeight = false private var isLoadingWeight = false @@ -74,18 +74,23 @@ class EliteFarmingWeight { private fun update() { if (!GardenAPI.inGarden()) return - if (apiError) return + if (apiError) { + display = "§6Farming Weight§7: §cAPI Error!" + return + } + if (bonusWeight == -2) { + display = "§6Farming Weight§7: §eLoading.." + return + } - if (bonusWeight == -1) { + if (bonusWeight == -1) { if (!isLoadingWeight) { isLoadingWeight = true SkyHanniMod.coroutineScope.launch { - bonusWeight = loadBonusWeight() + loadBonusWeight() isLoadingWeight = false } } - - display = "§6Farming Weight§7: §eLoading.." return } @@ -155,26 +160,29 @@ class EliteFarmingWeight { -1 } - private suspend fun loadBonusWeight(): Int { + private suspend fun loadBonusWeight() { + val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toString().replace("-", "") + val url = "https://elitebot.dev/api/weight/$uuid" try { - val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toString().replace("-", "") - val url = "https://elitebot.dev/api/weight/$uuid" val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject - + val localProfile = HyPixelData.profileName for (profileEntry in result["profiles"].asJsonObject.entrySet()) { val profile = profileEntry.value.asJsonObject val profileName = profile["cute_name"].asString.lowercase() - if (profileName == HyPixelData.profileName) { + if (profileName == localProfile) { profileId = profileEntry.key - return profile["farming"].asJsonObject["bonus"].asInt + bonusWeight = profile["farming"].asJsonObject["bonus"].asInt + return } } + println("url: '$url'") + println("result: '$result'") } catch (e: Exception) { - apiError = true - LorenzUtils.error("[SkyHanni] Failed to load farming weight data from elitebot.dev! please report this on discord!") + println("url: '$url'") e.printStackTrace() } - return -1 + apiError = true + LorenzUtils.error("[SkyHanni] Failed to load farming weight data from elitebot.dev! please report this on discord!") } private fun calculateCollectionWeight(): MutableMap<String, Double> { |