diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
8 files changed, 72 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 1e768df6e..7907c0f37 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -11,7 +11,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 34 + const val CONFIG_VERSION = 35 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index 785499f3e..f4e5fd032 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -93,6 +93,11 @@ public class MiscConfig { public PetCandyDisplayConfig petCandy = new PetCandyDisplayConfig(); @Expose + @ConfigOption(name = "No Bits Warning", desc = "") + @Accordion + public NoBitsWarningConfig noBitsWarning = new NoBitsWarningConfig(); + + @Expose @ConfigOption(name = "Show Outside SB", desc = "Show these features outside of SkyBlock.") @ConfigEditorDraggableList public List<OutsideSbFeature> showOutsideSB = new ArrayList<>(); @@ -132,12 +137,6 @@ public class MiscConfig { public boolean colorMonthNames = false; @Expose - @ConfigOption(name = "No Bits Warning", desc = "Alerts you when you have no bits available.") - @ConfigEditorBoolean - @FeatureToggle - public boolean noBitsWarning = true; - - @Expose @ConfigOption(name = "Explosions Hider", desc = "Hide explosions.") @ConfigEditorBoolean @FeatureToggle diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/NoBitsWarningConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/NoBitsWarningConfig.java new file mode 100644 index 000000000..2542d7728 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/NoBitsWarningConfig.java @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.config.features.misc; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class NoBitsWarningConfig { + @Expose + @ConfigOption(name = "Enabled", desc = "Alerts you when you have no bits available.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Notification Sound", desc = "Plays a notification sound when you get a warning.") + @ConfigEditorBoolean + public boolean notificationSound = true; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index 1a2d98223..f10d3d01c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -80,7 +80,7 @@ public class ProfileSpecificStorage { public int bits = -1; @Expose - public int bitsToClaim = -1; + public int bitsAvailable = -1; @Expose public Long boosterCookieExpiryTime = null; diff --git a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt index a13ee259b..eca5bbcc3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.FameRanks.getFameRankByNameOrNull import at.hannibal2.skyhanni.events.BitsUpdateEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -40,10 +41,10 @@ object BitsAPI { playerStorage?.currentFameRank = value.name } } - var bitsToClaim: Int - get() = profileStorage?.bitsToClaim ?: 0 + var bitsAvailable: Int + get() = profileStorage?.bitsAvailable ?: 0 private set(value) { - profileStorage?.bitsToClaim = value + profileStorage?.bitsAvailable = value } var cookieBuffTime: SimpleTimeMark? @@ -147,11 +148,14 @@ object BitsAPI { if (amount == bits) return if (amount > bits) { - bitsToClaim -= amount - bits + bitsAvailable -= amount - bits ChatUtils.debug("You have gained §3${amount - bits} Bits §7according to the scoreboard!") + bits = amount + sendBitsGainEvent() + } else { + bits = amount + sendBitsSpentEvent() } - bits = amount - sendEvent() } } } @@ -163,17 +167,17 @@ object BitsAPI { bitsFromFameRankUpChatPattern.matchMatcher(message) { val amount = group("amount").formatInt() - bitsToClaim += amount - sendEvent() + bitsAvailable += amount + sendBitsAvailableGainedEvent() return } boosterCookieAte.matchMatcher(message) { - bitsToClaim += (defaultcookiebits * (currentFameRank?.bitsMultiplier ?: return)).toInt() + bitsAvailable += (defaultcookiebits * (currentFameRank?.bitsMultiplier ?: return)).toInt() val cookieTime = cookieBuffTime cookieBuffTime = if (cookieTime == null) SimpleTimeMark.now() + 4.days else cookieTime + 4.days - sendEvent() + sendBitsAvailableGainedEvent() return } @@ -190,7 +194,7 @@ object BitsAPI { // If the cookie stack is null, then the player should not have any bits to claim if (cookieStack == null) { - bitsToClaim = 0 + bitsAvailable = 0 cookieBuffTime = SimpleTimeMark.farPast() return } @@ -198,9 +202,9 @@ object BitsAPI { val lore = cookieStack.getLore() lore.matchFirst(bitsAvailableMenuPattern) { val amount = group("toClaim").formatInt() - if (bitsToClaim != amount) { - bitsToClaim = amount - sendEvent() + if (bitsAvailable != amount) { + bitsAvailable = amount + sendBitsAvailableGainedEvent() } } lore.matchFirst(cookieDurationPattern) { @@ -254,12 +258,11 @@ object BitsAPI { line@ for (line in bitsStack.getLore()) { bitsAvailableMenuPattern.matchMatcher(line) { val amount = group("toClaim").formatInt() - if (amount != bitsToClaim) { - bitsToClaim = amount - sendEvent() + if (amount != bitsAvailable) { + bitsAvailable = amount + sendBitsAvailableGainedEvent() } - continue@line } } @@ -279,11 +282,16 @@ object BitsAPI { fun hasCookieBuff() = cookieBuffTime?.isInFuture() ?: false - private fun sendEvent() { - BitsUpdateEvent(bits, bitsToClaim).postAndCatch() - } + private fun sendBitsGainEvent() = BitsUpdateEvent.BitsGain(bits, bitsAvailable).postAndCatch() + private fun sendBitsSpentEvent() = BitsUpdateEvent.BitsSpent(bits, bitsAvailable).postAndCatch() + private fun sendBitsAvailableGainedEvent() = BitsUpdateEvent.BitsAvailableGained(bits, bitsAvailable).postAndCatch() fun isEnabled() = LorenzUtils.inSkyBlock && profileStorage != null + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(35, "#profile.bits.bitsToClaim", "#profile.bits.bitsAvailable") + } + class FameRankNotFoundException(rank: String) : Exception("FameRank not found: $rank") } diff --git a/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt index 3bdbf286d..47472b3f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt @@ -1,3 +1,7 @@ package at.hannibal2.skyhanni.events -class BitsUpdateEvent(val bits: Int, val bitsToClaim: Int) : LorenzEvent() +open class BitsUpdateEvent(val bits: Int, val bitsAvailable: Int) : LorenzEvent() { + class BitsGain(bits: Int, bitsAvailable: Int) : BitsUpdateEvent(bits, bitsAvailable) + 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/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index 6de6ea4f0..8c1c1afc1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -372,10 +372,10 @@ private fun getBankShowWhen() = !inAnyIsland(IslandType.THE_RIFT) private fun getBitsDisplayPair(): List<ScoreboardElementType> { val bits = BitsAPI.bits.coerceAtLeast(0).formatNum() - val bitsToClaim = if (BitsAPI.bitsToClaim == -1) { + val bitsToClaim = if (BitsAPI.bitsAvailable == -1) { "§cOpen Sbmenu§b" } else { - BitsAPI.bitsToClaim.coerceAtLeast(0).formatNum() + BitsAPI.bitsAvailable.coerceAtLeast(0).formatNum() } return listOf( 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 0b2e6069e..2529c026b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.BitsUpdateEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils @@ -14,17 +15,22 @@ class NoBitsWarning { private val config get() = SkyHanniMod.feature.misc.noBitsWarning @SubscribeEvent - fun onBitsUpdate(event: BitsUpdateEvent) { + fun onBitsGain(event: BitsUpdateEvent.BitsGain) { if (!isEnabled()) return - if (event.bitsToClaim != 0) 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) - SoundUtils.repeatSound(100,10, createSound("note.pling", 0.6f)) + if (config.notificationSound) SoundUtils.repeatSound(100, 10, createSound("note.pling", 0.6f)) } - private fun isEnabled() = LorenzUtils.inSkyBlock && config + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(35, "misc.noBitsWarning", "misc.noBitsWarning.enabled") + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled } |