aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
index e8491ae96..41976bf07 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt
@@ -426,19 +426,31 @@ class FarmingWeightDisplay {
try {
val result = withContext(dispatcher) { APIUtil.getJSONResponse(url) }.asJsonObject
- for (profileEntry in result["profiles"].asJsonArray) {
- val profile = profileEntry.asJsonObject
- val profileName = profile["profileName"].asString.lowercase()
- if (profileName == localProfile) {
- profileId = profile["profileId"].asString
- weight = profile["totalWeight"].asDouble
+ val selectedProfileId = result["selectedProfileId"].asString
+ val profileEntries = result["profiles"].asJsonArray
+
+ var selectedProfileEntry = profileEntries.find {
+ it.asJsonObject["profileId"].asString == selectedProfileId
+ }?.asJsonObject
+
+ // If the selected profile is not found or if the cute name doesn't match look for a different profile
+ // While it's not optimal to loop twice, this shouldn't happen often
+ if (selectedProfileEntry == null || selectedProfileEntry["profileName"].asString.lowercase() != localProfile) {
+ selectedProfileEntry = profileEntries.find {
+ it.asJsonObject["profileName"].asString.lowercase() == localProfile
+ }?.asJsonObject
+ }
- localCounter.clear()
- dirtyCropWeight = true
+ if (selectedProfileEntry != null) {
+ profileId = selectedProfileEntry["profileId"].asString
+ weight = selectedProfileEntry["totalWeight"].asDouble
- return
- }
+ localCounter.clear()
+ dirtyCropWeight = true
+
+ return
}
+
println("localProfile: '$localProfile'")
println("url: '$url'")
println("result: '$result'")
@@ -531,4 +543,4 @@ class FarmingWeightDisplay {
class UpcomingPlayer(val name: String, val weight: Double)
}
-} \ No newline at end of file
+}