Skip to content

Commit

Permalink
Fix + Improvement: No Bits Warning (#1425)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEmpa authored Apr 12, 2024
1 parent 388819e commit d070889
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public class MiscConfig {
@Accordion
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
Expand Down Expand Up @@ -131,12 +136,6 @@ public class MiscConfig {
@FeatureToggle
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static class BitsStorage {
public int bits = -1;

@Expose
public int bitsToClaim = -1;
public int bitsAvailable = -1;

@Expose
public Long boosterCookieExpiryTime = null;
Expand Down
50 changes: 29 additions & 21 deletions src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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()
}
}
}
Expand All @@ -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
}
Expand All @@ -190,17 +194,17 @@ 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
}

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) {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

0 comments on commit d070889

Please sign in to comment.