From 779b62a4df0f90e03b670a2bf9c1c146e520aaf4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:56:50 +0100 Subject: Fixed Ashfang Freeze Cooldown being off by one second. Fixed Fire Veil line gets shown even while frozen. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- .../itemabilities/FireVeilWandParticles.kt | 3 ++ .../abilitycooldown/ItemAbilityCooldown.kt | 3 ++ .../nether/ashfang/AshfangFreezeCooldown.kt | 33 +++++++++++++--------- .../java/at/hannibal2/skyhanni/utils/TimeUtils.kt | 1 + 5 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index ae24e155f..a58c50ec0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -483,7 +483,7 @@ class SkyHanniMod { loadModule(AuctionHouseCopyUnderbidPrice()) loadModule(AnvilCombineHelper()) loadModule(SeaCreatureMessageShortener()) - loadModule(AshfangFreezeCooldown()) + loadModule(AshfangFreezeCooldown) loadModule(AshfangNextResetCooldown()) loadModule(SummoningSoulsName()) loadModule(AshfangGravityOrbs()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt index 3841df899..b16354567 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/FireVeilWandParticles.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.events.ItemClickEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.features.nether.ashfang.AshfangFreezeCooldown import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils @@ -41,6 +42,8 @@ class FireVeilWandParticles { if (event.clickType != ClickType.RIGHT_CLICK) return val internalName = event.itemInHand?.getInternalName() + if (AshfangFreezeCooldown.iscurrentlyFrozen()) return + if (internalName == item) { lastClick = SimpleTimeMark.now() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt index fcb3d746f..ffb457ebf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.events.RenderItemTipEvent import at.hannibal2.skyhanni.events.RenderObject import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbility.Companion.getMultiplier +import at.hannibal2.skyhanni.features.nether.ashfang.AshfangFreezeCooldown import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.cleanName @@ -160,6 +161,7 @@ class ItemAbilityCooldown { @SubscribeEvent fun onItemClick(event: ItemClickEvent) { + if (AshfangFreezeCooldown.iscurrentlyFrozen()) return handleItemClick(event.itemInHand) } @@ -205,6 +207,7 @@ class ItemAbilityCooldown { } private fun handleOldAbilities(message: String) { + // TODO use regex if (message.contains(" (§6") && message.contains("§b) ")) { val name: String = message.between(" (§6", "§b) ") if (name == lastAbility) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt index 447884c05..85c9c66b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt @@ -8,17 +8,19 @@ import at.hannibal2.skyhanni.features.combat.damageindicator.BossType import at.hannibal2.skyhanni.features.combat.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.TimeUtils.format import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds -class AshfangFreezeCooldown { +object AshfangFreezeCooldown { private val config get() = SkyHanniMod.feature.crimsonIsle.ashfang // TODO USE SH-REPO private val cryogenicBlastPattern = "§cAshfang Follower's Cryogenic Blast hit you for (.*) damage!".toPattern() - private var lastHit = 0L + private var lastHit = SimpleTimeMark.farPast() @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { @@ -26,19 +28,19 @@ class AshfangFreezeCooldown { val message = event.message cryogenicBlastPattern.matchMatcher(message) { - lastHit = System.currentTimeMillis() + lastHit = SimpleTimeMark.now() } } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - val duration = System.currentTimeMillis() - lastHit - val maxDuration = 3_000 - val remainingLong = maxDuration - duration - if (remainingLong > 0) { - val format = TimeUtils.formatDuration(remainingLong, showMilliSeconds = true) + val passedSince = lastHit.passedSince() + val maxDuration = 3.seconds + val duration = maxDuration - passedSince + if (duration > 0.seconds) { + val format = duration.format(showMilliSeconds = true) config.freezeCooldownPos.renderString( "§cAshfang Freeze: §a$format", posLabel = "Ashfang Freeze Cooldown" @@ -46,14 +48,19 @@ class AshfangFreezeCooldown { } } + fun iscurrentlyFrozen(): Boolean { + val passedSince = lastHit.passedSince() + val maxDuration = 3.seconds + val duration = maxDuration - passedSince + return duration > 0.seconds + } + @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(2, "ashfang.freezeCooldown", "crimsonIsle.ashfang.freezeCooldown") event.move(2, "ashfang.freezeCooldownPos", "crimsonIsle.ashfang.freezeCooldownPos") } - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyBlock && config.freezeCooldown && - DamageIndicatorManager.isBossSpawned(BossType.NETHER_ASHFANG) - } + private fun isEnabled() = LorenzUtils.inSkyBlock && config.freezeCooldown && + DamageIndicatorManager.isBossSpawned(BossType.NETHER_ASHFANG) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index 67463db18..e8175cb6d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -31,6 +31,7 @@ object TimeUtils { else -> default } + @Deprecated("off sets by one second", ReplaceWith("Duration.format()")) fun formatDuration( millis: Long, biggestUnit: TimeUnit = TimeUnit.YEAR, -- cgit