diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-02-25 18:28:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-25 18:28:20 +0100 |
commit | ce3ab82ad811dc76781d3113765325461045efbd (patch) | |
tree | 75d270d25b946b8c62ab39364fca59f76efb5b44 /src | |
parent | cff372aeae28f7377a571672964c16ebdcd80a37 (diff) | |
download | skyhanni-ce3ab82ad811dc76781d3113765325461045efbd.tar.gz skyhanni-ce3ab82ad811dc76781d3113765325461045efbd.tar.bz2 skyhanni-ce3ab82ad811dc76781d3113765325461045efbd.zip |
Fixed creating too many skill timers. #1057
Diffstat (limited to 'src')
3 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt index a383b377e..45480aa4e 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt @@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.command.CommandBase import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.LinkedList +import java.util.Timer import java.util.regex.Matcher import kotlin.concurrent.fixedRateTimer import kotlin.time.Duration.Companion.seconds @@ -105,9 +106,9 @@ object SkillAPI { skillXp.lastUpdate = SimpleTimeMark.now() skillXp.sessionTimerActive = true - if (skillXp.shouldStartTimer) { - runTimer(skillName, skillXp) - skillXp.shouldStartTimer = false + + if (skillType.timer == null) { + skillType.timer = runTimer(skillType, skillXp) } SkillProgress.updateDisplay() SkillProgress.hideInActionBar = listOf(component) @@ -243,9 +244,10 @@ object SkillAPI { add("- CustomGoalLevel: ${skillInfo.customGoalLevel}\n") } - private fun runTimer(skillName: String, info: SkillXPInfo) { - fixedRateTimer(name = "skyhanni-skillprogress-timer-$skillName", initialDelay = 1_000L, period = 1_000L) { - if (info.shouldStartTimer) cancel() + // TODO only use one statuc timer for the whole feature. this timer just ticks the currently active skill. + private fun runTimer(skillType: SkillType, info: SkillXPInfo): Timer = + fixedRateTimer(name = "skyhanni-skillprogress-timer-${skillType.displayName}", initialDelay = 1_000L, period = 1_000L) { + if (skillType.timer != this) cancel() val time = when (activeSkill) { SkillType.FARMING -> SkillProgress.etaConfig.farmingPauseTime SkillType.MINING -> SkillProgress.etaConfig.miningPauseTime @@ -261,7 +263,6 @@ object SkillAPI { info.timeActive++ } } - } private fun handleSkillPattern(matcher: Matcher, skillType: SkillType, skillInfo: SkillInfo) { val currentXp = matcher.group("current").formatNumber() @@ -520,6 +521,5 @@ object SkillAPI { var isActive: Boolean = false, var lastUpdate: SimpleTimeMark = SimpleTimeMark.farPast(), var timeActive: Long = 0L, - var shouldStartTimer: Boolean = true, ) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt index 514f40121..0c88e7633 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt @@ -350,7 +350,7 @@ object SkillProgress { add(Renderable.clickAndHover("§7Session: §e$session ${if (xpInfo.sessionTimerActive) "" else "§c(PAUSED)"}", listOf("§eClick to reset!")) { xpInfo.sessionTimerActive = false - xpInfo.shouldStartTimer = true + activeSkill.timer = null xpInfo.timeActive = 0L chat("Timer for §b${activeSkill.displayName} §ehas been reset!") }) diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt index bd44a63f3..8122effc7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt @@ -6,6 +6,7 @@ import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraft.item.ItemStack +import java.util.Timer enum class SkillType(val displayName: String, icon: Item) { COMBAT("Combat", Items.golden_sword), @@ -19,6 +20,8 @@ enum class SkillType(val displayName: String, icon: Item) { TAMING("Taming", Items.spawn_egg), ; + var timer: Timer? = null + constructor(displayName: String, block: Block) : this(displayName, Item.getItemFromBlock(block)) val item: ItemStack by lazy { Utils.createItemStack(icon, displayName) } |