From b5b29450446248337a08ed358169e69faebba5c1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 18 May 2024 19:51:22 +0200 Subject: Fix: Farming Contest bugs (#1829) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/garden/contest/FarmingContestAPI.kt | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index fb82c8be9..9b866bd3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -1,10 +1,11 @@ package at.hannibal2.skyhanni.features.garden.contest +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.FarmingContestEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut @@ -12,6 +13,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isAnyOf import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyBlockTime @@ -39,7 +41,13 @@ object FarmingContestAPI { ) private val contests = mutableMapOf() - var inContest = false + private var internalContest = false + val inContest + get() = internalContest && LorenzUtils.skyBlockIsland.isAnyOf( + IslandType.GARDEN, + IslandType.HUB, + IslandType.THE_FARMING_ISLANDS + ) var contestCrop: CropType? = null private var startTime = SimpleTimeMark.farPast() var inInventory = false @@ -49,21 +57,20 @@ object FarmingContestAPI { } @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (event.repeatSeconds(1)) { - if (!LorenzUtils.inSkyBlock) return - if (!GardenAPI.inGarden()) return + fun onSecondPassed(event: SecondPassedEvent) { + if (!LorenzUtils.inSkyBlock) return - checkActiveContest() + if (internalContest && startTime.passedSince() > 20.minutes) { + FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() + internalContest = false } + + if (!GardenAPI.inGarden()) return + + checkActiveContest() } private fun checkActiveContest() { - if (inContest && startTime.passedSince() > 20.minutes) { - FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() - inContest = false - } - val currentCrop = readCurrentCrop() val currentContest = currentCrop != null @@ -76,7 +83,7 @@ object FarmingContestAPI { FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() } } - inContest = currentContest + internalContest = currentContest } else { if (currentCrop != contestCrop && currentCrop != null) { FarmingContestEvent(currentCrop, FarmingContestPhase.CHANGE).postAndCatch() -- cgit