aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillProgress.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillType.kt3
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) }