From 4ce974d559a080ac8ac95c8cae9147938fc97123 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Sat, 28 Sep 2024 15:48:48 -0400 Subject: Fix: Race Condition in Hoppity Duplicate Number & Stray no-fire (#2595) --- .../skyhanni/features/event/hoppity/HoppityAPI.kt | 15 +++++++++++++-- .../features/event/hoppity/HoppityEggsCompactChat.kt | 2 +- .../skyhanni/features/event/hoppity/HoppityEggsManager.kt | 7 +++++-- .../chocolatefactory/ChocolateFactoryBarnManager.kt | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt index 93c9efc04..881b8b5e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityAPI.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.events.hoppity.RabbitFoundEvent import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_FACTORY_MILESTONE import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.CHOCOLATE_SHOP_MILESTONE import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.SIDE_DISH +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.STRAY import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.eggFoundPattern import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.getEggType import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI @@ -103,8 +104,18 @@ object HoppityAPI { ChocolateFactoryStrayTracker.strayCaughtPattern.matchMatcher(it.stack.displayName) { ChocolateFactoryStrayTracker.handleStrayClicked(it) when (groupOrNull("name") ?: return@matchMatcher) { - "Fish the Rabbit" -> EggFoundEvent(HoppityEggType.STRAY, it.slotNumber, null).post() - "El Dorado" -> EggFoundEvent(HoppityEggType.STRAY, it.slotNumber, null).post() + "Fish the Rabbit" -> { + EggFoundEvent(STRAY, it.slotNumber, null).post() + lastName = "§9Fish the Rabbit" + lastMeal = STRAY + attemptFireRabbitFound() + } + "El Dorado" -> { + EggFoundEvent(STRAY, it.slotNumber, null).post() + lastName = "§6El Dorado" + lastMeal = STRAY + attemptFireRabbitFound() + } else -> return@matchMatcher } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt index 4a33820d8..0803cd0ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt @@ -95,7 +95,7 @@ object HoppityEggsCompactChat { } ?: "?" val dupeNumberFormat = if (eventConfig.showDuplicateNumber) { - (HoppityCollectionStats.getRabbitCount(this.lastName) - 1).takeIf { it > 1}?.let { + (HoppityCollectionStats.getRabbitCount(this.lastName)).takeIf { it > 0 }?.let { " §7(§b#$it§7)" } ?: "" } else "" diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt index b8143d311..bdbe4cd7e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt @@ -25,6 +25,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.now import at.hannibal2.skyhanni.utils.SkyBlockTime import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.TimeUtils.format +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Matcher import kotlin.time.Duration.Companion.minutes @@ -120,9 +121,11 @@ object HoppityEggsManager { lastNote = event.note } - @HandleEvent + @HandleEvent(priority = HandleEvent.LOWEST) fun onRabbitFound(event: RabbitFoundEvent) { - HoppityCollectionStats.incrementRabbitCount(event.rabbitName) + DelayedRun.runDelayed(1.seconds) { + HoppityCollectionStats.incrementRabbitCount(event.rabbitName) + } } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt index a2b264b35..8ce0047d0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt @@ -62,7 +62,7 @@ object ChocolateFactoryBarnManager { HoppityAPI.attemptFireRabbitFound(lastDuplicateAmount = amount) if (hoppityConfig.showDuplicateNumber && !hoppityConfig.compactChat) { - (HoppityCollectionStats.getRabbitCount(HoppityAPI.getLastRabbit()) - 1).takeIf { it > 1 }?.let { + (HoppityCollectionStats.getRabbitCount(HoppityAPI.getLastRabbit())).takeIf { it > 0 }?.let { event.chatComponent = ChatComponentText( event.message.replace("§7§lDUPLICATE RABBIT!", "§7§lDUPLICATE RABBIT! §7(Duplicate §b#$it§7)§r"), ) -- cgit