From 26c7d6e52a87cecba7da9af7975363cf798eb110 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 May 2023 11:55:34 +0200 Subject: Fixed bug that 5 seconds till next milestone warning spams indefinitely --- .../garden/farming/GardenCropMilestoneDisplay.kt | 26 +++++++++++++--------- .../features/garden/farming/GardenCropSpeed.kt | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt index 5d98bd05d..3186d78b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt @@ -173,17 +173,7 @@ object GardenCropMilestoneDisplay { GardenBestCropTime.timeTillNextCrop[crop] = millis val biggestUnit = TimeUnit.values()[config.cropMilestoneHighestTimeFormat.get()] val duration = TimeUtils.formatDuration(millis, biggestUnit) - if (config.cropMilestoneWarnClose) { - if (millis < 5_900) { - if (System.currentTimeMillis() > lastPlaySoundTime + 1_000) { - lastPlaySoundTime = System.currentTimeMillis() - SoundUtils.playBeepSound() - } - if (!needsInventory) { - TitleUtils.sendTitle("§b${crop.cropName} $nextTier in $duration", 1_500) - } - } - } + tryWarn(millis, "§b${crop.cropName} $nextTier in $duration") val speedText = "§7In §b$duration" lineMap[3] = Collections.singletonList(speedText) GardenAPI.itemInHand?.let { @@ -208,6 +198,20 @@ object GardenCropMilestoneDisplay { return formatDisplay(lineMap) } + private fun tryWarn(millis: Long, title: String) { + if (!config.cropMilestoneWarnClose) return + if (GardenCropSpeed.lastBrokenTime + 500 <= System.currentTimeMillis()) return + if (millis > 5_900) return + + if (System.currentTimeMillis() > lastPlaySoundTime + 1_000) { + lastPlaySoundTime = System.currentTimeMillis() + SoundUtils.playBeepSound() + } + if (!needsInventory) { + TitleUtils.sendTitle(title, 1_500) + } + } + private fun formatDisplay(lineMap: HashMap>): MutableList> { val newList = mutableListOf>() for (index in config.cropMilestoneText) { 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 3c61691ef..7903c2199 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 @@ -19,6 +19,7 @@ object GardenCropSpeed { private val latestBlocksPerSecond: MutableMap? get() = GardenAPI.config?.latestBlocksPerSecond var lastBrokenCrop: CropType? = null + var lastBrokenTime = 0L var averageBlocksPerSecond = 0.0 @@ -62,6 +63,7 @@ object GardenCropSpeed { if (event.clickType != ClickType.LEFT_CLICK) return lastBrokenCrop = event.crop + lastBrokenTime = System.currentTimeMillis() blocksBroken++ } -- cgit