From f67af16eacb6cdf3598183d473f072d123ef8a25 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sun, 26 May 2024 23:02:48 +1000 Subject: Backend: Convert stuff to SimpleTimeMark (#1777) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt | 12 ++++++------ src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt | 13 ++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/data') 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: (?.*)" ) - 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>(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 = 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)) { -- cgit