diff options
author | appable <16139460+appable0@users.noreply.github.com> | 2024-06-23 09:18:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-23 18:18:01 +0200 |
commit | b08dc623846886802093f0a00893ed96dc248ea9 (patch) | |
tree | e6252ecb774c52c3b26f3d8ec233ebc6c7a9d09d | |
parent | cc291932906c38943e20cee29ee591695a9875b5 (diff) | |
download | skyhanni-b08dc623846886802093f0a00893ed96dc248ea9.tar.gz skyhanni-b08dc623846886802093f0a00893ed96dc248ea9.tar.bz2 skyhanni-b08dc623846886802093f0a00893ed96dc248ea9.zip |
Replace: Time Tower Reminder feature (#2133)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
2 files changed, 29 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index c1da5e511..39758745a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -113,7 +113,7 @@ public class ChocolateFactoryConfig { public boolean timeTowerWarning = false; @Expose - @ConfigOption(name = "Time Tower Reminder", desc = "Notify a minute before the time tower ends.") + @ConfigOption(name = "Time Tower Expiry Reminder", desc = "Notify when the time tower ends and you have one or more remaining charges.") @ConfigEditorBoolean @FeatureToggle public boolean timeTowerReminder = true; diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt index a853b4741..9df1be965 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration import kotlin.time.Duration.Companion.hours @@ -22,7 +23,12 @@ object ChocolateFactoryTimeTowerManager { private val profileStorage get() = ChocolateFactoryAPI.profileStorage private var lastTimeTowerWarning = SimpleTimeMark.farPast() - private var lastTimeTowerReminder = SimpleTimeMark.farPast() + private var wasTimeTowerRecentlyActive = false + + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + wasTimeTowerRecentlyActive = false + } private const val HOVER_TEXT = "§eClick to run /cf!" @@ -35,11 +41,9 @@ object ChocolateFactoryTimeTowerManager { profileStorage.currentTimeTowerEnds = SimpleTimeMark.farPast() } - if (ChocolateFactoryAPI.inChocolateFactory) return + checkTimeTowerExpired() - if (config.timeTowerReminder) { - timeTowerReminder() - } + if (ChocolateFactoryAPI.inChocolateFactory) return val nextCharge = profileStorage.nextTimeTower @@ -49,10 +53,10 @@ object ChocolateFactoryTimeTowerManager { val nextTimeTower = profileStorage.nextTimeTower + profileStorage.timeTowerCooldown.hours profileStorage.nextTimeTower = nextTimeTower - if (!config.timeTowerWarning) return + if (!config.timeTowerWarning || timeTowerActive()) return ChatUtils.clickableChat( "Your Time Tower has another charge available §7(${timeTowerCharges()})§e, " + - "Click here to use one", + "Click here to use one.", onClick = { HypixelCommands.chocolateFactory() }, HOVER_TEXT, ) @@ -63,6 +67,22 @@ object ChocolateFactoryTimeTowerManager { checkTimeTowerWarning(false) } + private fun checkTimeTowerExpired() { + val isTimeTowerActive = timeTowerActive() + if (!isTimeTowerActive && wasTimeTowerRecentlyActive && config.timeTowerReminder && currentCharges() > 0) { + val charges = StringUtils.pluralize(currentCharges(), "charge", "charges", withNumber = true) + ChatUtils.clickableChat( + "§cYour Time Tower just expired and has $charges remaining. Click here to use one.", + onClick = { + HypixelCommands.chocolateFactory() + }, + hover = "§eClick to run /cf!", + ) + SoundUtils.playBeepSound() + } + wasTimeTowerRecentlyActive = isTimeTowerActive + } + fun checkTimeTowerWarning(inInventory: Boolean) { if (!ChocolateFactoryAPI.isEnabled()) return if (!config.timeTowerWarning) return @@ -76,7 +96,7 @@ object ChocolateFactoryTimeTowerManager { "§cYour Time Tower is full §7(${timeTowerCharges()})§c, " + "Use one to avoid wasting time tower usages!", onClick = { HypixelCommands.chocolateFactory() }, - HOVER_TEXT + HOVER_TEXT, ) SoundUtils.playBeepSound() lastTimeTowerWarning = SimpleTimeMark.now() @@ -105,22 +125,6 @@ object ChocolateFactoryTimeTowerManager { private fun timeTowerEnds(): SimpleTimeMark = profileStorage?.currentTimeTowerEnds ?: SimpleTimeMark.farPast() - private fun timeTowerReminder() { - if (lastTimeTowerReminder.passedSince() < 20.seconds) return - - val timeUntil = timeTowerEnds().timeUntil() - if (timeUntil < 1.minutes && timeUntil.isPositive()) { - ChatUtils.clickableChat( - "§cYour Time Tower is about to end! " + - "Open the Chocolate Factory to avoid wasting the multiplier!", - onClick = { HypixelCommands.chocolateFactory() }, - HOVER_TEXT - ) - SoundUtils.playBeepSound() - lastTimeTowerReminder = SimpleTimeMark.now() - } - } - fun timeTowerFullTimeMark(): SimpleTimeMark { val profileStorage = profileStorage ?: return SimpleTimeMark.farPast() if (timeTowerFull()) return SimpleTimeMark.farPast() |