From 32a6b798111dac52fdcf94532bc268a1235b5be0 Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Mon, 13 May 2024 18:13:10 +0200 Subject: Improvement: Fixpests delay (#1764) --- .../skyhanni/features/garden/pests/PestAPI.kt | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt index 1351ab5bd..1d1c4e0b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt @@ -121,28 +121,27 @@ object PestAPI { var firstScoreboardCheck = false private fun fixPests(loop: Int = 2) { - val accurateAmount = getPlotsWithAccuratePests().sumOf { it.pests } - val inaccurateAmount = getPlotsWithInaccuratePests().size - if (scoreboardPests == accurateAmount + inaccurateAmount) { // if we can assume all inaccurate plots have 1 pest each - for (plot in getPlotsWithInaccuratePests()) { - plot.pests = 1 + DelayedRun.runDelayed(2.seconds) { + val accurateAmount = getPlotsWithAccuratePests().sumOf { it.pests } + val inaccurateAmount = getPlotsWithInaccuratePests().size + if (scoreboardPests == accurateAmount + inaccurateAmount) { // if we can assume all inaccurate plots have 1 pest each + for (plot in getPlotsWithInaccuratePests()) { + plot.pests = 1 + plot.isPestCountInaccurate = false + } + } else if (inaccurateAmount == 1) { // if we can assume all the inaccurate pests are in the only inaccurate plot + val plot = getPlotsWithInaccuratePests().firstOrNull() ?: return@runDelayed + plot.pests = scoreboardPests - accurateAmount plot.isPestCountInaccurate = false - } - } else if (inaccurateAmount == 1) { // if we can assume all the inaccurate pests are in the only inaccurate plot - val plot = getPlotsWithInaccuratePests().firstOrNull() ?: return - plot.pests = scoreboardPests - accurateAmount - plot.isPestCountInaccurate = false - } else if (accurateAmount + inaccurateAmount > scoreboardPests) { // when logic fails and we reach impossible pest counts - getInfestedPlots().forEach { - it.pests = 0 - it.isPestCountInaccurate = true - } - if (loop > 0) { - DelayedRun.runDelayed(2.seconds) { - fixPests(loop - 1) + } else if (accurateAmount + inaccurateAmount > scoreboardPests) { // when logic fails and we reach impossible pest counts + getInfestedPlots().forEach { + it.pests = 0 + it.isPestCountInaccurate = true } + if (loop > 0) { + fixPests(loop - 1) + } else sendPestError() } - else sendPestError() } } -- cgit