From ce765217f8f2f4732e5d55323f0bf2f58f7df2e3 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 1 May 2023 23:14:12 +0200 Subject: Fixed crashes and config resets because of averageBlocksPerSecond is 'not a number' --- src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt | 1 + .../hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index f35f08c96..e32f1d899 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -18,6 +18,7 @@ class ConfigManager { companion object { val gson = GsonBuilder().setPrettyPrinting() .excludeFieldsWithoutExposeAnnotation() + .serializeSpecialFloatingPointValues() .registerTypeAdapterFactory(PropertyTypeAdapterFactory()) .create() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index 0124d75ca..2ff5706b2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -68,7 +68,7 @@ object GardenCropSpeed { if (blocksBroken == 0) { if (blocksSpeedList.size == 0) return - secondsStopped ++ + secondsStopped++ } else { if (secondsStopped >= config.blocksBrokenResetTime) { resetSpeed() @@ -82,7 +82,9 @@ object GardenCropSpeed { blocksSpeedList.removeFirst() blocksSpeedList.add(blocksBroken) } - averageBlocksPerSecond = blocksSpeedList.dropLast(1).average() + averageBlocksPerSecond = if (blocksSpeedList.size > 1) { + blocksSpeedList.dropLast(1).average() + } else 0.0 GardenAPI.getCurrentlyFarmedCrop()?.let { latestBlocksPerSecond[it] = averageBlocksPerSecond } -- cgit