aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-05-26 23:02:48 +1000
committerGitHub <noreply@github.com>2024-05-26 15:02:48 +0200
commitf67af16eacb6cdf3598183d473f072d123ef8a25 (patch)
tree62d11d0f5191d48eee31a630a0b054baeb89a509
parent29657e24412baa7be9a1681593593368f92de26f (diff)
downloadskyhanni-f67af16eacb6cdf3598183d473f072d123ef8a25.tar.gz
skyhanni-f67af16eacb6cdf3598183d473f072d123ef8a25.tar.bz2
skyhanni-f67af16eacb6cdf3598183d473f072d123ef8a25.zip
Backend: Convert stuff to SimpleTimeMark (#1777)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt45
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/SoopyGuessBurrow.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftAgaricusCap.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftWiltedBerberisHelper.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt2
24 files changed, 161 insertions, 144 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 824726e35..16b0fcfa3 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -305,7 +305,7 @@ class ConfigManager {
logger.log("Loaded $fileName from file")
} catch (e: Exception) {
e.printStackTrace()
- val backupFile = file.resolveSibling("$fileName-${System.currentTimeMillis()}-backup.json")
+ val backupFile = file.resolveSibling("$fileName-${SimpleTimeMark.now().toMillis()}-backup.json")
logger.log("Exception while reading $file. Will load blank $fileName and save backup to $backupFile")
logger.log("Exception was $e")
try {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt
index 4c0d47614..e09eb11d7 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt
@@ -7,9 +7,11 @@ import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import at.hannibal2.skyhanni.utils.NumberUtil.million
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
object PurseAPI {
private val patternGroup = RepoPattern.group("data.purse")
@@ -22,13 +24,13 @@ object PurseAPI {
"Piggy: (?<coins>.*)"
)
- private var inventoryCloseTime = 0L
+ private var inventoryCloseTime = SimpleTimeMark.farPast()
var currentPurse = 0.0
private set
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
- inventoryCloseTime = System.currentTimeMillis()
+ inventoryCloseTime = SimpleTimeMark.now()
}
@SubscribeEvent
@@ -55,15 +57,13 @@ object PurseAPI {
}
if (Minecraft.getMinecraft().currentScreen == null) {
- val timeDiff = System.currentTimeMillis() - inventoryCloseTime
- if (timeDiff > 2_000) {
+ if (inventoryCloseTime.passedSince() > 2.seconds) {
return PurseChangeCause.GAIN_MOB_KILL
}
}
return PurseChangeCause.GAIN_UNKNOWN
} else {
- val timeDiff = System.currentTimeMillis() - SlayerAPI.questStartTime
- if (timeDiff < 1500) {
+ if (SlayerAPI.questStartTime.passedSince() < 1.5.seconds) {
return PurseChangeCause.LOSE_SLAYER_QUEST_STARTED
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
index f4235cb73..3d3be9c3a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
@@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RecalculatingValue
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TimeLimitedCache
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.minutes
@@ -24,20 +25,15 @@ object SlayerAPI {
private var nameCache = TimeLimitedCache<Pair<NEUInternalName, Int>, Pair<String, Double>>(1.minutes)
- var questStartTime = 0L
+ var questStartTime = SimpleTimeMark.farPast()
var isInCorrectArea = false
var isInAnyArea = false
var latestSlayerCategory = ""
- private var latestProgressChangeTime = 0L
- var latestWrongAreaWarning = 0L
+ var latestWrongAreaWarning = SimpleTimeMark.farPast()
var latestSlayerProgress = ""
fun hasActiveSlayerQuest() = latestSlayerCategory != ""
- fun getLatestProgressChangeTime() = if (latestSlayerProgress == "§eSlay the boss!") {
- System.currentTimeMillis()
- } else latestProgressChangeTime
-
fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> =
nameCache.getOrPut(internalName to amount) {
val amountFormat = if (amount != 1) "§7${amount}x §r" else ""
@@ -76,7 +72,7 @@ object SlayerAPI {
if (!LorenzUtils.inSkyBlock) return
if (event.message.contains("§r§5§lSLAYER QUEST STARTED!")) {
- questStartTime = System.currentTimeMillis()
+ questStartTime = SimpleTimeMark.now()
}
if (event.message == " §r§a§lSLAYER QUEST COMPLETE!") {
@@ -118,7 +114,6 @@ object SlayerAPI {
if (latestSlayerProgress != slayerProgress) {
SlayerProgressChangeEvent(latestSlayerProgress, slayerProgress).postAndCatch()
latestSlayerProgress = slayerProgress
- latestProgressChangeTime = System.currentTimeMillis()
}
if (event.isMod(5)) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
index 3d77e214a..ac2496f18 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
@@ -20,6 +20,7 @@ import net.minecraft.network.play.server.S2APacketParticles
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
class SpawnTimers {
@@ -40,13 +41,13 @@ class SpawnTimers {
private var arachneSpawnTime = SimpleTimeMark.farPast()
private var saveNextTickParticles = false
private var particleCounter = 0
- private var tickTime: Long = 0
- private var searchTime: Long = 0
+ private var lastTickTime = SimpleTimeMark.farPast()
+ private var searchTime = SimpleTimeMark.farPast()
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- searchTime = 0
- tickTime = 0
+ searchTime = SimpleTimeMark.farPast()
+ lastTickTime = SimpleTimeMark.farPast()
particleCounter = 0
saveNextTickParticles = false
arachneSpawnTime = SimpleTimeMark.farPast()
@@ -70,9 +71,9 @@ class SpawnTimers {
if (arachneFragmentPattern.matches(message) || arachneCrystalPattern.matches(message)) {
if (arachneCrystalPattern.matches(message)) {
saveNextTickParticles = true
- searchTime = System.currentTimeMillis()
+ searchTime = SimpleTimeMark.now()
particleCounter = 0
- tickTime = 0L
+ lastTickTime = SimpleTimeMark.farPast()
} else arachneSpawnTime = SimpleTimeMark.now() + 19.seconds
}
}
@@ -81,11 +82,11 @@ class SpawnTimers {
@SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
fun onPacketReceive(event: PacketEvent.ReceiveEvent) {
if (!saveNextTickParticles) return
- if (System.currentTimeMillis() <= searchTime + 3000) return
+ if (searchTime.passedSince() < 3.seconds) return
- if (particleCounter == 0 && tickTime == 0L) tickTime = System.currentTimeMillis()
+ if (particleCounter == 0 && lastTickTime.isFarPast()) lastTickTime = SimpleTimeMark.now()
- if (System.currentTimeMillis() > tickTime + 60) {
+ if (lastTickTime.passedSince() > 60.milliseconds) {
arachneSpawnTime = if (particleCounter <= 20) {
SimpleTimeMark.now() + 21.seconds
} else {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt
index 2e6832eb1..960a8053e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt
@@ -8,27 +8,29 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
object DungeonMilestonesDisplay {
private val config get() = SkyHanniMod.feature.dungeon
- val milestonePattern by RepoPattern.pattern(
+ private val milestonePattern by RepoPattern.pattern(
"dungeon.milestone",
"§e§l.*Milestone §r§e.§r§7: You have (?:tanked and )?(?:dealt|healed) §r§.*§r§7.*so far! §r§a.*"
)
private var display = ""
private var currentMilestone = 0
- private var timeReached = 0L
+ private var timeReached = SimpleTimeMark.farPast()
var colour = ""
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!event.isMod(5)) return
- if (currentMilestone >= 3 && System.currentTimeMillis() > timeReached + 3_000 && display.isNotEmpty()) {
+ if (currentMilestone >= 3 && timeReached.passedSince() > 3.seconds && display.isNotEmpty()) {
display = display.substring(1)
}
}
@@ -47,7 +49,7 @@ object DungeonMilestonesDisplay {
private fun update() {
if (currentMilestone > 3) return
if (currentMilestone == 3) {
- timeReached = System.currentTimeMillis()
+ timeReached = SimpleTimeMark.now()
}
colour = when (currentMilestone) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
index c8f7fc240..c884bd818 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt
@@ -29,6 +29,7 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
object InquisitorWaypointShare {
@@ -58,13 +59,14 @@ object InquisitorWaypointShare {
"(?<party>§9Party §8> )?(?<playerName>.*)§f: §rInquisitor dead!"
)
- private var time = 0L
- private var testTime = 0L
+ private var inquisitorTime = SimpleTimeMark.farPast()
+ private var testTime = SimpleTimeMark.farPast()
private var lastInquisitorMessage = ""
private var inquisitor = -1
private var lastInquisitor = -1
- private var lastShareTime = 0L
+ private var lastShareTime = SimpleTimeMark.farPast()
private var inquisitorsNearby = emptyList<EntityOtherPlayerMP>()
+ private val soonRange = (-500).milliseconds..1.5.seconds
private val logger = LorenzLogger("diana/waypoints")
@@ -105,26 +107,25 @@ object InquisitorWaypointShare {
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
val message = event.message
+ // TODO repo pattern
if (message.contains("§eYou dug out")) {
- testTime = System.currentTimeMillis()
+ testTime = SimpleTimeMark.now()
lastInquisitorMessage = message
- val diff = System.currentTimeMillis() - time
+ val passedSince = inquisitorTime.passedSince()
- if (diff < 10_000) {
+ if (passedSince < 10.seconds) {
logger.log(" ")
logger.log("reverse!")
- logger.log("diff: $diff")
- }
- if (diff > 1500 || diff < -500) {
- return
+ logger.log("diff: $passedSince")
}
+ if (passedSince in soonRange) return
foundInquisitor(lastInquisitor)
}
// TODO: Change the check to only one line once we have a confirmed inquis message line
if (message.contains("§r§eYou dug out ") && message.contains("Inquis")) {
- time = System.currentTimeMillis()
+ inquisitorTime = SimpleTimeMark.now()
logger.log("found Inquisitor")
}
}
@@ -145,15 +146,15 @@ object InquisitorWaypointShare {
inquisitorsNearby = inquisitorsNearby.editCopy { add(entity) }
GriffinBurrowHelper.update()
- val diff = System.currentTimeMillis() - time
- time = System.currentTimeMillis()
+ val passedSince = inquisitorTime.passedSince()
+ inquisitorTime = SimpleTimeMark.now()
lastInquisitor = entity.entityId
- logger.log("diff: $diff")
- if (diff > 1500 || diff < -500) {
- val testDiff = System.currentTimeMillis() - testTime
- if (testDiff > 1500 || testDiff < -500) {
- logger.log("testDiff: $diff")
+ logger.log("diff: $passedSince")
+ if (passedSince in soonRange) {
+ val testDiff = testTime.passedSince()
+ if (testDiff in soonRange) {
+ logger.log("testDiff: $passedSince")
return
} else {
logger.log("wrong Inquisitor message!")
@@ -204,8 +205,8 @@ object InquisitorWaypointShare {
private fun sendDeath() {
if (!isEnabled()) return
- if (lastShareTime + 5000 > System.currentTimeMillis()) return
- lastShareTime = System.currentTimeMillis()
+ if (lastShareTime.passedSince() > 5.seconds) return
+ lastShareTime = SimpleTimeMark.now()
if (inquisitor == -1) {
logger.log("Inquisitor is already null!")
@@ -217,8 +218,8 @@ object InquisitorWaypointShare {
fun sendInquisitor() {
if (!isEnabled()) return
- if (lastShareTime + 5000 > System.currentTimeMillis()) return
- lastShareTime = System.currentTimeMillis()
+ if (lastShareTime.passedSince() > 5.seconds) return
+ lastShareTime = SimpleTimeMark.now()
if (inquisitor == -1) {
ChatUtils.error("No Inquisitor Found!")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/SoopyGuessBurrow.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/SoopyGuessBurrow.kt
index 535e8d4a0..37c9d50f1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/SoopyGuessBurrow.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/SoopyGuessBurrow.kt
@@ -24,7 +24,7 @@ import kotlin.math.sin
class SoopyGuessBurrow {
private var dingIndex = 0
- private var lastDing = 0L
+ private var hasDinged = false
private var lastDingPitch = 0f
private var firstPitch = 0f
private var lastParticlePoint: LorenzVec? = null
@@ -43,7 +43,7 @@ class SoopyGuessBurrow {
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- lastDing = 0L
+ hasDinged = false
lastDingPitch = 0f
firstPitch = 0f
lastParticlePoint = null
@@ -63,11 +63,11 @@ class SoopyGuessBurrow {
if (event.soundName != "note.harp") return
val pitch = event.pitch
- if (lastDing == 0L) {
+ if (!hasDinged) {
firstPitch = pitch
}
- lastDing = System.currentTimeMillis()
+ hasDinged = true
if (pitch < lastDingPitch) {
firstPitch = pitch
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
index 130daa29c..f917db711 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt
@@ -12,13 +12,15 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.TimeUnit
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
class FishingTimer {
@@ -28,7 +30,7 @@ class FishingTimer {
private var rightLocation = false
private var currentCount = 0
- private var startTime = 0L
+ private var startTime = SimpleTimeMark.farPast()
private var inHollows = false
@SubscribeEvent
@@ -45,16 +47,16 @@ class FishingTimer {
if (event.isMod(5)) checkMobs()
if (event.isMod(7)) tryPlaySound()
if (config.manualResetTimer.isKeyHeld() && Minecraft.getMinecraft().currentScreen == null) {
- startTime = System.currentTimeMillis()
+ startTime = SimpleTimeMark.now()
}
}
private fun tryPlaySound() {
if (currentCount == 0) return
- val duration = System.currentTimeMillis() - startTime
- val barnTimerAlertTime = config.alertTime * 1_000
- if (duration > barnTimerAlertTime && duration < barnTimerAlertTime + 3_000) {
+ val passedSince = startTime.passedSince()
+ val barnTimerAlertTime = (config.alertTime * 1_000).milliseconds
+ if (passedSince in barnTimerAlertTime..(barnTimerAlertTime + 3.seconds)) {
SoundUtils.playBeepSound()
}
}
@@ -63,12 +65,12 @@ class FishingTimer {
val newCount = countMobs()
if (currentCount == 0 && newCount > 0) {
- startTime = System.currentTimeMillis()
+ startTime = SimpleTimeMark.now()
}
currentCount = newCount
if (newCount == 0) {
- startTime = 0
+ startTime = SimpleTimeMark.farPast()
}
if (inHollows && newCount >= 60 && config.wormLimitAlert) {
@@ -109,10 +111,10 @@ class FishingTimer {
if (currentCount == 0) return
if (!FishingAPI.isFishing()) return
- val duration = System.currentTimeMillis() - startTime
- val barnTimerAlertTime = config.alertTime * 1_000
- val color = if (duration > barnTimerAlertTime) "§c" else "§e"
- val timeFormat = TimeUtils.formatDuration(duration, biggestUnit = TimeUnit.MINUTE)
+ val passedSince = startTime.passedSince()
+ val barnTimerAlertTime = (config.alertTime * 1_000).milliseconds
+ val color = if (passedSince > barnTimerAlertTime) "§c" else "§e"
+ val timeFormat = passedSince.format(TimeUnit.MINUTE)
val name = StringUtils.pluralize(currentCount, "sea creature")
val text = "$color$timeFormat §8(§e$currentCount §b$name§8)"
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt
index e47100cb4..1027234f7 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt
@@ -14,15 +14,17 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.ceil
+import kotlin.time.Duration.Companion.milliseconds
class JacobContestFFNeededDisplay {
private val config get() = GardenAPI.config
private var display = emptyList<List<Any>>()
- private var lastToolTipTime = 0L
+ private var lastToolTipTime = SimpleTimeMark.farPast()
private val cache = mutableMapOf<ItemStack, List<List<Any>>>()
@SubscribeEvent
@@ -35,7 +37,7 @@ class JacobContestFFNeededDisplay {
val oldData = cache[stack]
if (oldData != null) {
display = oldData
- lastToolTipTime = System.currentTimeMillis()
+ lastToolTipTime = SimpleTimeMark.now()
return
}
@@ -45,7 +47,7 @@ class JacobContestFFNeededDisplay {
val newDisplay = drawDisplay(contest)
display = newDisplay
cache[stack] = newDisplay
- lastToolTipTime = System.currentTimeMillis()
+ lastToolTipTime = SimpleTimeMark.now()
}
@SubscribeEvent
@@ -116,7 +118,7 @@ class JacobContestFFNeededDisplay {
fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!isEnabled()) return
if (!FarmingContestAPI.inInventory) return
- if (System.currentTimeMillis() > lastToolTipTime + 200) return
+ if (lastToolTipTime.passedSince() < 200.milliseconds) return
config.farmingFortuneForContestPos.renderStringsAndItems(display, posLabel = "Jacob Contest Crop Data")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
index 72021eea6..5b50a29ff 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
@@ -29,12 +29,14 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.TimeUnit
import at.hannibal2.skyhanni.utils.TimeUtils
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
object GardenCropMilestoneDisplay {
@@ -47,7 +49,7 @@ object GardenCropMilestoneDisplay {
private val storage get() = ProfileStorageData.profileSpecific?.garden?.customGoalMilestone
private val bestCropTime = GardenBestCropTime()
- private var lastPlaySoundTime = 0L
+ private var lastPlaySoundTime = SimpleTimeMark.farPast()
private var needsInventory = false
private var lastWarnedLevel = -1
@@ -262,11 +264,11 @@ object GardenCropMilestoneDisplay {
private fun tryWarn(millis: Long, title: String) {
if (!config.warnClose) return
- if (GardenCropSpeed.lastBrokenTime + 500 <= System.currentTimeMillis()) return
+ if (GardenCropSpeed.lastBrokenTime.passedSince() > 500.milliseconds) return
if (millis > 5_900) return
- if (System.currentTimeMillis() > lastPlaySoundTime + 1_000) {
- lastPlaySoundTime = System.currentTimeMillis()
+ if (lastPlaySoundTime.passedSince() > 1.seconds) {
+ lastPlaySoundTime = SimpleTimeMark.now()
SoundUtils.playBeepSound()
}
if (!needsInventory) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
index 691c3777c..72e73ee2d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
@@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
@@ -26,7 +27,7 @@ object GardenCropSpeed {
private val latestBlocksPerSecond: MutableMap<CropType, Double>? get() = GardenAPI.storage?.latestBlocksPerSecond
var lastBrokenCrop: CropType? = null
- var lastBrokenTime = 0L
+ var lastBrokenTime = SimpleTimeMark.now()
var averageBlocksPerSecond = 0.0
@@ -76,7 +77,7 @@ object GardenCropSpeed {
if (event.clickType != ClickType.LEFT_CLICK) return
lastBrokenCrop = event.crop
- lastBrokenTime = System.currentTimeMillis()
+ lastBrokenTime = SimpleTimeMark.now()
blocksBroken++
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
index f4a401cd5..aa59a604d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
@@ -14,6 +14,7 @@ import org.lwjgl.input.Keyboard
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import java.util.IdentityHashMap
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
object GardenCustomKeybinds {
@@ -22,7 +23,7 @@ object GardenCustomKeybinds {
private val mcSettings get() = Minecraft.getMinecraft().gameSettings
private val map: MutableMap<KeyBinding, () -> Int> = IdentityHashMap()
- private var lastWindowOpenTime = 0L
+ private var lastWindowOpenTime = SimpleTimeMark.farPast()
private var lastDuplicateKeybindsWarnTime = SimpleTimeMark.farPast()
init {
@@ -44,13 +45,13 @@ object GardenCustomKeybinds {
if (Minecraft.getMinecraft().currentScreen != null) {
if (Minecraft.getMinecraft().currentScreen is GuiEditSign) {
- lastWindowOpenTime = System.currentTimeMillis()
+ lastWindowOpenTime = SimpleTimeMark.now()
}
return false
}
// TODO remove workaround
- if (System.currentTimeMillis() < lastWindowOpenTime + 300) return false
+ if (lastWindowOpenTime.passedSince() < 300.milliseconds) return false
val areDuplicates = map.values
.map { it() }
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
index 7fb3439f7..75c9f5e27 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
@@ -9,32 +9,31 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
class WildStrawberryDyeNotification {
- private var lastCloseTime = 0L
+ private var lastCloseTime = SimpleTimeMark.farPast()
val item by lazy { "DYE_WILD_STRAWBERRY".asInternalName() }
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
- lastCloseTime = System.currentTimeMillis()
+ lastCloseTime = SimpleTimeMark.now()
}
@SubscribeEvent
fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) {
if (!GardenAPI.inGarden()) return
if (!GardenAPI.config.wildStrawberryDyeNotification) return
+ // Prevent false positives when buying the item in ah or moving it from a storage
+ if (lastCloseTime.passedSince() < 1.seconds) return
val itemStack = event.itemStack
- // Prevent false positives when buying the item in ah or moving it from a storage
- val diff = System.currentTimeMillis() - lastCloseTime
- if (diff < 1_000) return
-
val internalName = itemStack.getInternalName()
if (internalName == item) {
val name = itemStack.name
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt
index 4cdd6c117..caa8940db 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt
@@ -23,9 +23,11 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
object GardenVisitorDropStatistics {
@@ -37,7 +39,7 @@ object GardenVisitorDropStatistics {
private var totalVisitors = 0
var coinsSpent = 0L
- var lastAccept = 0L
+ var lastAccept = SimpleTimeMark.farPast()
private val patternGroup = RepoPattern.group("garden.visitor.droptracker")
private val acceptPattern by patternGroup.pattern(
@@ -101,7 +103,7 @@ object GardenVisitorDropStatistics {
fun onChat(event: LorenzChatEvent) {
if (!GardenAPI.onBarnPlot) return
if (!ProfileStorageData.loaded) return
- if (lastAccept - System.currentTimeMillis() > 0 || lastAccept - System.currentTimeMillis() <= -1000) return
+ if (lastAccept.passedSince() > 1.seconds || lastAccept.isInPast()) return
val message = event.message.removeColor().trim()
val storage = GardenAPI.storage?.visitorDrops ?: return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 3badedef7..aeb049417 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -51,6 +51,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.getLorenzVec
@@ -284,7 +285,7 @@ object GardenVisitorFeatures {
VisitorAcceptEvent(event.visitor).postAndCatch()
update()
GardenVisitorDropStatistics.coinsSpent += round(lastFullPrice).toLong()
- GardenVisitorDropStatistics.lastAccept = System.currentTimeMillis()
+ GardenVisitorDropStatistics.lastAccept = SimpleTimeMark.now()
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
index ab6ba87a9..f87dee33a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt
@@ -34,6 +34,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.drawBorder
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isMuseumDonated
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRiftExportable
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRiftTransferable
@@ -46,6 +47,7 @@ import net.minecraft.item.ItemStack
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
class HideNotClickableItems {
@@ -54,8 +56,7 @@ class HideNotClickableItems {
private var hideReason = ""
private var showGreenLine = false
- private var lastClickTime = 0L
- private var bypassUntil = 0L
+ private var lastClickTime = SimpleTimeMark.farPast()
private val hideNpcSellFilter = MultiFilter()
private val hideInStorageFilter = MultiFilter()
@@ -95,8 +96,8 @@ class HideNotClickableItems {
@SubscribeEvent
fun onForegroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
- if (isDisabled()) return
- if (bypasssActive()) return
+ if (!isEnabled()) return
+ if (bypassActive()) return
if (event.gui !is GuiChest) return
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
@@ -113,9 +114,9 @@ class HideNotClickableItems {
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onTooltip(event: ItemTooltipEvent) {
- if (isDisabled()) return
+ if (!isEnabled()) return
if (event.toolTip == null) return
- if (bypasssActive()) return
+ if (bypassActive()) return
val guiChest = Minecraft.getMinecraft().currentScreen
if (guiChest !is GuiChest) return
@@ -144,9 +145,9 @@ class HideNotClickableItems {
@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
- if (isDisabled()) return
+ if (!isEnabled()) return
if (!config.itemsBlockClicks) return
- if (bypasssActive()) return
+ if (bypassActive()) return
if (event.gui !is GuiChest) return
val chestName = InventoryUtils.openInventoryName()
@@ -160,20 +161,14 @@ class HideNotClickableItems {
if (hide(chestName, stack)) {
event.isCanceled = true
- if (System.currentTimeMillis() > lastClickTime + 5_000) {
- lastClickTime = System.currentTimeMillis()
+ if (lastClickTime.passedSince() > 5.seconds) {
+ lastClickTime = SimpleTimeMark.now()
}
return
}
}
- private fun bypasssActive() = config.itemsBypass && KeyboardManager.isModifierKeyDown()
-
- private fun isDisabled(): Boolean {
- if (bypassUntil > System.currentTimeMillis()) return true
-
- return !config.items
- }
+ private fun bypassActive() = config.itemsBypass && KeyboardManager.isModifierKeyDown()
private fun hide(chestName: String, stack: ItemStack): Boolean {
hideReason = ""
@@ -603,6 +598,8 @@ class HideNotClickableItems {
return result
}
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.items
+
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(3, "inventory.hideNotClickableItems", "inventory.hideNotClickable.items")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt
index cdd5163b5..ea33bc7ec 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt
@@ -12,7 +12,9 @@ import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.minutes
class TiaRelayHelper {
@@ -20,7 +22,7 @@ class TiaRelayHelper {
private var inInventory = false
private var lastClickSlot = 0
- private var lastClickTime = 0L
+ private var lastClickTime = SimpleTimeMark.farPast()
private var sounds = mutableMapOf<Int, Sound>()
private var resultDisplay = mutableMapOf<Int, Int>()
@@ -41,8 +43,7 @@ class TiaRelayHelper {
if (distance >= 2) return
if (lastClickSlot == 0) return
- val duration = System.currentTimeMillis() - lastClickTime
- if (duration > 1_000) return
+ if (lastClickTime.passedSince() > 1.minutes) return
if (sounds.contains(lastClickSlot)) return
sounds[lastClickSlot] = Sound(soundName, event.pitch)
@@ -136,7 +137,7 @@ class TiaRelayHelper {
if (event.clickedButton != 1) return
lastClickSlot = event.slotId
- lastClickTime = System.currentTimeMillis()
+ lastClickTime = SimpleTimeMark.now()
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt
index 6df86dda0..9e0857285 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt
@@ -19,6 +19,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
@@ -26,6 +27,7 @@ import com.google.gson.JsonArray
import com.google.gson.JsonNull
import com.google.gson.annotations.Expose
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.minutes
object PowderTracker {
@@ -53,7 +55,7 @@ object PowderTracker {
"§e§lPASSIVE EVENT §b§l2X POWDER §e§lRUNNING FOR §a§l(?<time>.*)§r"
)
- private var lastChestPicked = 0L
+ private var lastChestPicked = SimpleTimeMark.farPast()
private var isGrinding = false
private val gemstoneInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf())
private val mithrilInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf())
@@ -122,7 +124,7 @@ object PowderTracker {
it.totalChestPicked += 1
}
isGrinding = true
- lastChestPicked = System.currentTimeMillis()
+ lastChestPicked = SimpleTimeMark.now()
}
}
@@ -131,7 +133,7 @@ object PowderTracker {
it.totalChestPicked += 1
}
isGrinding = true
- lastChestPicked = System.currentTimeMillis()
+ lastChestPicked = SimpleTimeMark.now()
}
powderStartedPattern.matchMatcher(msg) { doublePowder = true }
@@ -163,7 +165,7 @@ object PowderTracker {
tracker.update()
}
}
- if (System.currentTimeMillis() - lastChestPicked > 60_000) {
+ if (lastChestPicked.passedSince() > 1.minutes) {
isGrinding = false
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftAgaricusCap.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftAgaricusCap.kt
index 70b595d1a..c01d20157 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftAgaricusCap.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftAgaricusCap.kt
@@ -11,13 +11,14 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class RiftAgaricusCap {
private val config get() = RiftAPI.config.area.dreadfarm
- private var startTime = 0L
+ private var startTime = SimpleTimeMark.farPast()
private var location: LorenzVec? = null
@SubscribeEvent
@@ -36,11 +37,11 @@ class RiftAgaricusCap {
when (currentLocation.getBlockStateAt().toString()) {
"minecraft:brown_mushroom" -> {
return if (location != currentLocation) {
- startTime = System.currentTimeMillis()
+ startTime = SimpleTimeMark.now()
currentLocation
} else {
- if (startTime == -1L) {
- startTime = System.currentTimeMillis()
+ if (startTime.isFarFuture()) {
+ startTime = SimpleTimeMark.now()
}
location
}
@@ -48,7 +49,7 @@ class RiftAgaricusCap {
"minecraft:red_mushroom" -> {
if (location == currentLocation) {
- startTime = -1L
+ startTime = SimpleTimeMark.farFuture()
return location
}
}
@@ -62,13 +63,12 @@ class RiftAgaricusCap {
val location = location?.add(y = 0.6) ?: return
- if (startTime == -1L) {
+ if (startTime.isFarFuture()) {
event.drawDynamicText(location, "§cClick!", 1.5)
return
}
- val countDown = System.currentTimeMillis() - startTime
- val format = TimeUtils.formatDuration(countDown - 1000, showMilliSeconds = true)
+ val format = startTime.passedSince().format(showMilliSeconds = true)
event.drawDynamicText(location, "§b$format", 1.5)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftWiltedBerberisHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftWiltedBerberisHelper.kt
index 319b04142..9515330d1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftWiltedBerberisHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/RiftWiltedBerberisHelper.kt
@@ -15,11 +15,13 @@ import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBox_nea
import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraft.client.Minecraft
import net.minecraft.init.Blocks
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
+import kotlin.time.Duration.Companion.milliseconds
class RiftWiltedBerberisHelper {
@@ -28,12 +30,12 @@ class RiftWiltedBerberisHelper {
private var hasFarmingToolInHand = false
private var list = listOf<WiltedBerberis>()
- class WiltedBerberis(var currentParticles: LorenzVec) {
+ data class WiltedBerberis(var currentParticles: LorenzVec) {
var previous: LorenzVec? = null
var moving = true
var y = 0.0
- var lastTime = System.currentTimeMillis()
+ var lastTime = SimpleTimeMark.now()
}
@SubscribeEvent
@@ -41,7 +43,7 @@ class RiftWiltedBerberisHelper {
if (!isEnabled()) return
if (!event.isMod(5)) return
- list = list.editCopy { removeIf { System.currentTimeMillis() > it.lastTime + 500 } }
+ list = list.editCopy { removeIf { it.lastTime.passedSince() > 500.milliseconds } }
hasFarmingToolInHand = InventoryUtils.getItemInHand()?.getInternalName() == RiftAPI.farmingTool
@@ -98,7 +100,7 @@ class RiftWiltedBerberisHelper {
moving = isMoving
currentParticles = location
- lastTime = System.currentTimeMillis()
+ lastTime = SimpleTimeMark.now()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
index 95ba80060..ad90e89b6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
@@ -80,7 +80,7 @@ class SlayerQuestWarning {
}
private var needSlayerQuest = false
- private var lastWarning = 0L
+ private var lastWarning = SimpleTimeMark.farPast()
private var currentReason = ""
private fun needNewQuest(reason: String) {
@@ -95,13 +95,13 @@ class SlayerQuestWarning {
private fun warn(titleMessage: String, chatMessage: String) {
if (!config.questWarning) return
- if (lastWarning + 10_000 > System.currentTimeMillis()) return
+ if (lastWarning.passedSince() < 10.seconds) return
if (DianaAPI.isDoingDiana()) return
// prevent warnings when mobs are hit by other players
if (lastWeaponUse.passedSince() > 500.milliseconds) return
-
- lastWarning = System.currentTimeMillis()
+
+ lastWarning = SimpleTimeMark.now()
ChatUtils.chat(chatMessage)
if (config.questWarningTitle) {
@@ -128,7 +128,7 @@ class SlayerQuestWarning {
if (slayerType != activeSlayer) {
val activeSlayerName = activeSlayer.displayName
val slayerName = slayerType.displayName
- SlayerAPI.latestWrongAreaWarning = System.currentTimeMillis()
+ SlayerAPI.latestWrongAreaWarning = SimpleTimeMark.now()
warn(
"Wrong Slayer!",
"Wrong slayer selected! You have $activeSlayerName selected and you are in an $slayerName area!"
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
index aeb7d4590..07bc097a8 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
@@ -22,9 +22,10 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
-import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeWordsAtEnd
import at.hannibal2.skyhanni.utils.renderables.Renderable
@@ -63,7 +64,7 @@ class SlayerRngMeterDisplay {
)
private var display = emptyList<Renderable>()
- private var lastItemDroppedTime = 0L
+ private var lastItemDroppedTime = SimpleTimeMark.farPast()
var rngScore = mapOf<String, Map<NEUInternalName, Long>>()
@@ -71,8 +72,8 @@ class SlayerRngMeterDisplay {
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
- if (lastItemDroppedTime != 0L && System.currentTimeMillis() > lastItemDroppedTime + 4_000) {
- lastItemDroppedTime = 0L
+ if (!lastItemDroppedTime.isFarPast() && lastItemDroppedTime.passedSince() > 4.seconds) {
+ lastItemDroppedTime = SimpleTimeMark.farPast()
update()
}
}
@@ -121,7 +122,7 @@ class SlayerRngMeterDisplay {
if (rawPercentage > 1) rawPercentage = 1.0
val percentage = LorenzUtils.formatPercentage(rawPercentage)
ChatUtils.chat("§dRNG Meter §7dropped at §e$percentage §7XP ($from/${to}§7)")
- lastItemDroppedTime = System.currentTimeMillis()
+ lastItemDroppedTime = SimpleTimeMark.now()
}
if (blockChat) {
event.blockedReason = "slayer_rng_meter"
@@ -220,7 +221,7 @@ class SlayerRngMeterDisplay {
with(storage) {
if (itemGoal == "?") return "§cOpen RNG Meter Inventory!"
if (itemGoal == "") {
- return if (lastItemDroppedTime != 0L) {
+ return if (!lastItemDroppedTime.isFarPast()) {
"§a§lRNG Item dropped!"
} else {
"§eNo RNG Item selected!"
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt
index 7d900c2e6..4f94838e9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt
@@ -17,11 +17,14 @@ import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
+import kotlin.time.Duration.Companion.seconds
class BlazeSlayerDaggerHelper {
@@ -36,8 +39,8 @@ class BlazeSlayerDaggerHelper {
private var textTop = ""
private var textBottom = ""
- private var lastDaggerCheck = 0L
- private var lastNearestCheck = 0L
+ private var lastDaggerCheck = SimpleTimeMark.farPast()
+ private var lastNearestCheck = SimpleTimeMark.farPast()
private var lastNearest: HellionShield? = null
@SubscribeEvent
@@ -80,8 +83,8 @@ class BlazeSlayerDaggerHelper {
private fun findNearest(): HellionShield? {
if (!config.markRightHellionShield) return null
- if (lastNearestCheck + 100 > System.currentTimeMillis()) return lastNearest
- lastNearestCheck = System.currentTimeMillis()
+ if (lastNearestCheck.passedSince() < 100.milliseconds) return lastNearest
+ lastNearestCheck = SimpleTimeMark.now()
val playerLocation = LocationUtils.playerLocation()
return HellionShieldHelper.hellionShieldMobs
@@ -124,8 +127,8 @@ class BlazeSlayerDaggerHelper {
}
private fun checkActiveDagger() {
- if (lastDaggerCheck + 1_000 > System.currentTimeMillis()) return
- lastDaggerCheck = System.currentTimeMillis()
+ if (lastDaggerCheck.passedSince() < 1.seconds) return
+ lastDaggerCheck = SimpleTimeMark.now()
for (dagger in Dagger.entries) {
if (dagger.updated) continue
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
index 66286a489..2184322e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
@@ -29,6 +29,8 @@ value class SimpleTimeMark(private val millis: Long) : Comparable<SimpleTimeMark
fun isFarPast() = millis == 0L
+ fun isFarFuture() = millis == Long.MAX_VALUE
+
override fun compareTo(other: SimpleTimeMark): Int = millis.compareTo(other.millis)
override fun toString(): String {