Skip to content

Commit

Permalink
Fixed crashes when first time joining garden with skyhanni
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Mar 23, 2023
1 parent d660e6e commit b41ed23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GardenAPI {
fun onProfileJoin(event: ProfileJoinEvent) {
if (cropsPerSecond.isEmpty()) {
for (cropType in CropType.values()) {
cropsPerSecond[cropType] = -1
cropType.setSpeed(-1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b41ed23

Please sign in to comment.