Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: No Bits Warning #1286

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.features.misc.MiscFeatures
import at.hannibal2.skyhanni.features.misc.MovementSpeedDisplay
import at.hannibal2.skyhanni.features.misc.NoBitsWarning
import at.hannibal2.skyhanni.features.misc.NonGodPotEffectDisplay
import at.hannibal2.skyhanni.features.misc.ParticleHider
import at.hannibal2.skyhanni.features.misc.PartyMemberOutlines
Expand Down Expand Up @@ -817,6 +818,7 @@ class SkyHanniMod {
loadModule(RareDropMessages())
loadModule(CraftMaterialsFromBazaar())
loadModule(PestProfitTracker)
loadModule(NoBitsWarning())

init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ 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
Expand Up @@ -46,6 +46,6 @@ public class Storage {
public Map<UUID, PlayerSpecificStorage> players = new HashMap<>();

@Expose
public String currentFameRank = null;
public String currentFameRank = "New player";

}
22 changes: 19 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.FameRanks.getFameRankByNameOrNull
import at.hannibal2.skyhanni.events.BitsUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
Expand Down Expand Up @@ -117,8 +118,8 @@ object BitsAPI {
if (amount > bits) {
bitsToClaim -= amount - bits
ChatUtils.debug("You have gained §3${amount - bits} Bits §7according to the scoreboard!")
sendEvent()
}
bits = amount

return
}
Expand All @@ -133,12 +134,14 @@ object BitsAPI {
bitsFromFameRankUpChatPattern.matchMatcher(message) {
val amount = group("amount").formatInt()
bitsToClaim += amount
sendEvent()

return
}

boosterCookieAte.matchMatcher(message) {
bitsToClaim += (defaultcookiebits * (currentFameRank?.bitsMultiplier ?: return)).toInt()
sendEvent()

return
}
Expand All @@ -161,7 +164,11 @@ object BitsAPI {

for (line in cookieStack.getLore()) {
bitsAvailableMenuPattern.matchMatcher(line) {
bitsToClaim = group("toClaim").formatInt()
val amount = group("toClaim").formatInt()
if (bitsToClaim != amount) {
bitsToClaim = amount
sendEvent()
}

return
}
Expand Down Expand Up @@ -207,14 +214,23 @@ object BitsAPI {

line@ for (line in bitsStack.getLore()) {
bitsAvailableMenuPattern.matchMatcher(line) {
bitsToClaim = group("toClaim").formatInt()
val amount = group("toClaim").formatInt()
if (amount != bitsToClaim) {
bitsToClaim = amount
sendEvent()
}


continue@line
}
}
}
}

private fun sendEvent() {
BitsUpdateEvent(bits, bitsToClaim).postAndCatch()
}

fun isEnabled() = LorenzUtils.inSkyBlock && profileStorage != null

class FameRankNotFoundException(rank: String) : Exception("FameRank not found: $rank")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/events/BitsUpdateEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package at.hannibal2.skyhanni.events

class BitsUpdateEvent(val bits: Int, val bitsToClaim: Int) : LorenzEvent()
30 changes: 30 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package at.hannibal2.skyhanni.features.misc

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.BitsUpdateEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.SoundUtils.createSound
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

class NoBitsWarning {

private val config get() = SkyHanniMod.feature.misc.noBitsWarning

@SubscribeEvent
fun onBitsUpdate(event: BitsUpdateEvent) {
if (!isEnabled()) return
if (event.bitsToClaim != 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))
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config
}
Loading