aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-23 21:40:47 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-23 21:40:47 +0100
commit8e0a917ba5e84148d9afbdd35c49c8fe29c6a667 (patch)
tree540b95b8f27bc9318b1338f12bbb86c0f4ff686a /src
parent9d2b10c3858dcd4aebe60eb28b982b9b31ce3f21 (diff)
downloadskyhanni-8e0a917ba5e84148d9afbdd35c49c8fe29c6a667.tar.gz
skyhanni-8e0a917ba5e84148d9afbdd35c49c8fe29c6a667.tar.bz2
skyhanni-8e0a917ba5e84148d9afbdd35c49c8fe29c6a667.zip
Fixed crashes when first time joining garden with skyhanni
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt50
2 files changed, 31 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
index fafdbe700..8c18659d0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -66,7 +66,7 @@ class GardenAPI {
fun onProfileJoin(event: ProfileJoinEvent) {
if (cropsPerSecond.isEmpty()) {
for (cropType in CropType.values()) {
- cropsPerSecond[cropType] = -1
+ cropType.setSpeed(-1)
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
index e33c29ffd..69b530bc0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -94,29 +94,39 @@ class GardenCropMilestoneDisplay {
@SubscribeEvent
fun onOwnInventoryItemUpdate(event: OwnInventorItemUpdateEvent) {
- val item = event.itemStack
- val counter = GardenAPI.readCounter(item)
- if (counter == -1) return
- val crop = GardenAPI.getCropTypeFromItem(item) ?: return
- if (cultivatingData.containsKey(crop)) {
- val old = cultivatingData[crop]!!
- val addedCounter = counter - old
- // TODO remove try catch
- try {
+ // TODO remove try catch
+ try {
+ val item = event.itemStack
+ val counter = GardenAPI.readCounter(item)
+ if (counter == -1) return
+ val crop = GardenAPI.getCropTypeFromItem(item) ?: return
+ if (cultivatingData.containsKey(crop)) {
+ val old = cultivatingData[crop]!!
+ val addedCounter = counter - old
+
+ if (GardenCropMilestones.cropCounter.isEmpty()) {
+ for (innerCrop in CropType.values()) {
+ innerCrop.setCounter(0)
+ }
+ }
+ if (GardenAPI.isSpeedDataEmpty()) {
+ for (cropType in CropType.values()) {
+ cropType.setSpeed(-1)
+ }
+ }
+
crop.setCounter(crop.getCounter() + addedCounter)
- } catch (e: NullPointerException) {
- println("crop: '$crop'")
- println("GardenCropMilestones.cropCounter: '${GardenCropMilestones.cropCounter.keys}'")
- LorenzUtils.debug("NPE at OwnInventorItemUpdateEvent with GardenCropMilestones.cropCounter")
- e.printStackTrace()
- }
- EliteFarmingWeight.addCrop(crop, addedCounter)
- if (currentCrop == crop) {
- calculateSpeed(addedCounter)
- update()
+ EliteFarmingWeight.addCrop(crop, addedCounter)
+ if (currentCrop == crop) {
+ calculateSpeed(addedCounter)
+ update()
+ }
}
+ cultivatingData[crop] = counter
+ } catch (e: Throwable) {
+ LorenzUtils.error("[SkyHanni] Error in OwnInventorItemUpdateEvent")
+ e.printStackTrace()
}
- cultivatingData[crop] = counter
}
@SubscribeEvent