From 268b9a75050bffcbea90f8f89ab54006de832dc1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 30 Sep 2023 09:51:38 +0200 Subject: Workaround for wrong contest times. --- .../features/garden/contest/FarmingContestAPI.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main/java/at/hannibal2') 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 a39efa894..8d7e1eae1 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 @@ -11,10 +11,12 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.minutes object FarmingContestAPI { private val timePattern = "§a(?.*) (?.*)(?:rd|st|nd|th), Year (?.*)".toPattern() @@ -22,6 +24,7 @@ object FarmingContestAPI { private val cropPattern = "§8(?.*) Contest".toPattern() var inContest = false var contestCrop: CropType? = null + private var startTime = SimpleTimeMark.farPast() private val sidebarCropPattern = "§e○ §f(?.*) §a.*".toPattern() var inInventory = false @@ -37,19 +40,30 @@ object FarmingContestAPI { } private fun checkActiveContest() { + if (inContest) { + if (startTime.passedSince() > 20.minutes) { + FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() + inContest = false + } + } + val currentCrop = readCurrentCrop() val currentContest = currentCrop != null if (inContest != currentContest) { if (currentContest) { FarmingContestEvent(currentCrop!!, FarmingContestPhase.START).postAndCatch() + startTime = SimpleTimeMark.now() } else { - FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() + if (startTime.passedSince() > 2.minutes) { + FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() + } } inContest = currentContest } else { if (currentCrop != contestCrop) { FarmingContestEvent(currentCrop!!, FarmingContestPhase.CHANGE).postAndCatch() + startTime = SimpleTimeMark.now() } } contestCrop = currentCrop -- cgit