diff options
3 files changed, 27 insertions, 29 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt index 4c25b4c3e..2e7af1836 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt @@ -36,7 +36,6 @@ 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 @@ -81,6 +80,33 @@ object SkillAPI { var showDisplay = false var lastUpdate = SimpleTimeMark.farPast() + init { + fixedRateTimer(name = "skyhanni-skillprogress-timer", initialDelay = 1_000L, period = 1_000L) { + tickSkill() + } + } + + private fun tickSkill() { + val activeSkill = activeSkill ?: return + val info = skillXPInfoMap[activeSkill] ?: return + if (!info.sessionTimerActive) return + + val time = when (activeSkill) { + SkillType.FARMING -> SkillProgress.etaConfig.farmingPauseTime + SkillType.MINING -> SkillProgress.etaConfig.miningPauseTime + SkillType.COMBAT -> SkillProgress.etaConfig.combatPauseTime + SkillType.FORAGING -> SkillProgress.etaConfig.foragingPauseTime + SkillType.FISHING -> SkillProgress.etaConfig.fishingPauseTime + else -> 0 + } + if (info.lastUpdate.passedSince() > time.seconds) { + info.sessionTimerActive = false + } + if (info.sessionTimerActive) { + info.timeActive++ + } + } + @SubscribeEvent fun onActionBar(event: ActionBarUpdateEvent) { val actionBar = event.actionBar.removeColor() @@ -106,10 +132,6 @@ object SkillAPI { skillXp.lastUpdate = SimpleTimeMark.now() skillXp.sessionTimerActive = true - - if (skillType.timer == null) { - skillType.timer = runTimer(skillType, skillXp) - } SkillProgress.updateDisplay() SkillProgress.hideInActionBar = listOf(component) return @@ -244,26 +266,6 @@ object SkillAPI { add("- CustomGoalLevel: ${skillInfo.customGoalLevel}\n") } - // 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 - SkillType.COMBAT -> SkillProgress.etaConfig.combatPauseTime - SkillType.FORAGING -> SkillProgress.etaConfig.foragingPauseTime - SkillType.FISHING -> SkillProgress.etaConfig.fishingPauseTime - else -> 0 - } - if (info.lastUpdate.passedSince() > time.seconds) { - info.sessionTimerActive = false - } - if (info.sessionTimerActive) { - info.timeActive++ - } - } - private fun handleSkillPattern(matcher: Matcher, skillType: SkillType, skillInfo: SkillInfo) { val currentXp = matcher.group("current").formatNumber() val maxXp = matcher.group("needed").formatNumber() 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 684d65c82..d2821fc63 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt @@ -359,7 +359,6 @@ object SkillProgress { add(Renderable.clickAndHover("§7Session: §e$session ${if (xpInfo.sessionTimerActive) "" else "§c(PAUSED)"}", listOf("§eClick to reset!")) { xpInfo.sessionTimerActive = false - 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 8122effc7..bd44a63f3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt @@ -6,7 +6,6 @@ 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), @@ -20,8 +19,6 @@ 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) } |