diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-04-04 20:16:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 20:16:43 +0200 |
commit | 82f1db03538817fbb1cb56a492149759d855d0a7 (patch) | |
tree | 28a509a01728fdaf392660e990c7957422752c0a /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 49f34426da64d41cf1e560f8eb6f2824fc21c83e (diff) | |
download | skyhanni-82f1db03538817fbb1cb56a492149759d855d0a7.tar.gz skyhanni-82f1db03538817fbb1cb56a492149759d855d0a7.tar.bz2 skyhanni-82f1db03538817fbb1cb56a492149759d855d0a7.zip |
Fix: Pest Tp Delay (#1357)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt | 37 |
1 files changed, 33 insertions, 4 deletions
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 89404cbe0..4a1a626b8 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 @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent @@ -18,9 +19,10 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -31,6 +33,8 @@ object PestAPI { var scoreboardPests = 0 + var lastPestKillTime = SimpleTimeMark.farPast() + val vacuumVariants = listOf( "SKYMART_VACUUM".asInternalName(), "SKYMART_TURBO_VACUUM".asInternalName(), @@ -48,6 +52,7 @@ object PestAPI { "scoreboard.pests", " §7⏣ §[ac]The Garden §4§lൠ§7 x(?<pests>.*)" ) + /** * REGEX-TEST: §7⏣ §aPlot §7- §b22a * REGEX-TEST: §7⏣ §aThe Garden @@ -56,6 +61,7 @@ object PestAPI { "scoreboard.nopests", " §7⏣ §a(?:The Garden|Plot §7- §b.+)$" ) + /** * REGEX-TEST: §aPlot §7- §b4 §4§lൠ§7 x1 */ @@ -63,6 +69,7 @@ object PestAPI { "scoreboard.plot.pests", "\\s*(?:§.)*Plot (?:§.)*- (?:§.)*(?<plot>.+) (?:§.)*ൠ(?:§.)* x(?<pests>\\d+)" ) + /** * REGEX-TEST: §aPlot §7- §b3 */ @@ -74,6 +81,7 @@ object PestAPI { "inventory", "§4§lൠ §cThis plot has §6(?<amount>\\d) Pests?§c!" ) + /** * REGEX-TEST: Plots: §r§b4§r§f, §r§b12§r§f, §r§b13§r§f, §r§b18§r§f, §r§b20 */ @@ -82,6 +90,19 @@ object PestAPI { "\\sPlots: (?<plots>.*)" ) + /** + * REGEX-TEST: §eYou received §a7x Enchanted Potato §efor killing a §6Locust§e! + * REGEX-TEST: §eYou received §a6x Enchanted Cocoa Beans §efor killing a §6Moth§e! + */ + private val pestDeathChatPattern by patternGroup.pattern( + "chat.pestdeath", + "§eYou received §a(?<amount>[0-9]*)x (?<item>.*) §efor killing an? §6(?<pest>.*)§e!" + ) + private val noPestsChatPattern by patternGroup.pattern( + "chat.nopests", + "§cThere are not any Pests on your Garden right now! Keep farming!" + ) + private fun fixPests() { val accurateAmount = getPlotsWithAccuratePests().sumOf { it.pests } val inaccurateAmount = getPlotsWithInaccuratePests().size @@ -177,9 +198,8 @@ object PestAPI { for (line in event.newList) { // gets the total amount of pests in the garden pestsInScoreboardPattern.matchMatcher(line) { - val newPests = group("pests").formatNumber().toInt() + val newPests = group("pests").formatInt() if (newPests != scoreboardPests) { - removePests(scoreboardPests - newPests) scoreboardPests = newPests updatePests() } @@ -220,11 +240,20 @@ object PestAPI { @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!GardenAPI.inGarden()) return - if (event.message == "§cThere are not any Pests on your Garden right now! Keep farming!") { + if (pestDeathChatPattern.matches(event.message)) { + lastPestKillTime = SimpleTimeMark.now() + removeNearestPest() + } + if (noPestsChatPattern.matches(event.message)) { resetAllPests() } } + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + lastPestKillTime = SimpleTimeMark.farPast() + } + private fun getPlotsWithAccuratePests() = GardenPlotAPI.plots.filter { it.pests > 0 && !it.isPestCountInaccurate } private fun getPlotsWithInaccuratePests() = GardenPlotAPI.plots.filter { it.pests == 0 && it.isPestCountInaccurate } |