diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-04-21 23:00:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-21 23:00:12 +0200 |
commit | 2c448cf20f20936c3d4c83ff29c0bf043fe6394f (patch) | |
tree | 305134f64853ccf31e9718e7110d936cc16402c8 /src | |
parent | f978de08fe03fe1808e611ea75bf14cbae904d44 (diff) | |
download | skyhanni-2c448cf20f20936c3d4c83ff29c0bf043fe6394f.tar.gz skyhanni-2c448cf20f20936c3d4c83ff29c0bf043fe6394f.tar.bz2 skyhanni-2c448cf20f20936c3d4c83ff29c0bf043fe6394f.zip |
Fix: Fixed Bits Gained Chat Messages randomly being send (#1503)
Diffstat (limited to 'src')
3 files changed, 21 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt index d400959c0..c580e00d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.events.BitsUpdateEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent -import at.hannibal2.skyhanni.features.misc.NoBitsWarning.sendBitsGainChatMessage import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -153,10 +152,10 @@ object BitsAPI { if (amount == bits) return if (amount > bits) { - bitsAvailable -= amount - bits - sendBitsGainChatMessage(amount - bits) + val difference = amount - bits + bitsAvailable -= difference bits = amount - sendBitsGainEvent() + sendBitsGainEvent(difference) } else { bits = amount sendBitsSpentEvent() @@ -228,7 +227,6 @@ object BitsAPI { val difference = bits - bitsAvailable if (difference > 0) { - sendBitsGainChatMessage(difference) bits += difference } } @@ -308,7 +306,7 @@ object BitsAPI { fun hasCookieBuff() = cookieBuffTime?.isInFuture() ?: false - private fun sendBitsGainEvent() = BitsUpdateEvent.BitsGain(bits, bitsAvailable).postAndCatch() + private fun sendBitsGainEvent(difference: Int) = BitsUpdateEvent.BitsGain(bits, bitsAvailable, difference).postAndCatch() private fun sendBitsSpentEvent() = BitsUpdateEvent.BitsSpent(bits, bitsAvailable).postAndCatch() private fun sendBitsAvailableGainedEvent() = BitsUpdateEvent.BitsAvailableGained(bits, bitsAvailable).postAndCatch() diff --git a/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt index 47472b3f4..78ff15bae 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.events -open class BitsUpdateEvent(val bits: Int, val bitsAvailable: Int) : LorenzEvent() { - class BitsGain(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable) +open class BitsUpdateEvent(val bits: Int, val bitsAvailable: Int, val difference: Int = 0) : LorenzEvent() { + class BitsGain(bits: Int, bitsAvailable: Int, difference: Int) : BitsUpdateEvent(bits, bitsAvailable, difference) class BitsSpent(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable) class BitsAvailableGained(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt index 350e95384..fbaba9095 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.misc +import akka.event.NoLogging.isWarningEnabled import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.BitsUpdateEvent @@ -15,23 +16,22 @@ object NoBitsWarning { private val config get() = SkyHanniMod.feature.misc.bits - fun sendBitsGainChatMessage(bits: Int) { - if (!isChatMessageEnabled()) return - if (bits < config.threshold) return - ChatUtils.chat("You have gained §b${bits.addSeparators()} §eBits.") - } - @SubscribeEvent fun onBitsGain(event: BitsUpdateEvent.BitsGain) { - if (!isWarningEnabled()) return - if (event.bitsAvailable != 0) return - - ChatUtils.clickableChat( - "§bNo Bits Available! §eClick to run /bz booster cookie.", - "bz booster cookie" - ) - LorenzUtils.sendTitle("§bNo Bits Available", 5.seconds) - if (config.notificationSound) SoundUtils.repeatSound(100, 10, createSound("note.pling", 0.6f)) + if (isWarningEnabled() && event.bitsAvailable == 0) { + + ChatUtils.clickableChat( + "§bNo Bits Available! §eClick to run /bz booster cookie.", + "bz booster cookie" + ) + LorenzUtils.sendTitle("§bNo Bits Available", 5.seconds) + if (config.notificationSound) SoundUtils.repeatSound(100, 10, createSound("note.pling", 0.6f)) + } + + if (isChatMessageEnabled()) { + if (event.bits < config.threshold) return + ChatUtils.chat("You have gained §b${event.difference.addSeparators()} §eBits.") + } } @SubscribeEvent |