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> --- .../at/hannibal2/skyhanni/config/ConfigManager.kt | 2 +- .../java/at/hannibal2/skyhanni/data/PurseAPI.kt | 12 +++--- .../java/at/hannibal2/skyhanni/data/SlayerAPI.kt | 13 ++----- .../skyhanni/features/combat/mobs/SpawnTimers.kt | 19 ++++----- .../features/dungeon/DungeonMilestonesDisplay.kt | 10 +++-- .../event/diana/InquisitorWaypointShare.kt | 45 +++++++++++----------- .../features/event/diana/SoopyGuessBurrow.kt | 8 ++-- .../skyhanni/features/fishing/FishingTimer.kt | 26 +++++++------ .../garden/contest/JacobContestFFNeededDisplay.kt | 10 +++-- .../garden/farming/GardenCropMilestoneDisplay.kt | 10 +++-- .../features/garden/farming/GardenCropSpeed.kt | 5 ++- .../garden/farming/GardenCustomKeybinds.kt | 7 ++-- .../farming/WildStrawberryDyeNotification.kt | 11 +++--- .../garden/visitor/GardenVisitorDropStatistics.kt | 6 ++- .../garden/visitor/GardenVisitorFeatures.kt | 3 +- .../features/inventory/HideNotClickableItems.kt | 31 +++++++-------- .../features/inventory/tiarelay/TiaRelayHelper.kt | 9 +++-- .../features/mining/powdertracker/PowderTracker.kt | 10 +++-- .../rift/area/dreadfarm/RiftAgaricusCap.kt | 18 ++++----- .../area/dreadfarm/RiftWiltedBerberisHelper.kt | 10 +++-- .../skyhanni/features/slayer/SlayerQuestWarning.kt | 10 ++--- .../features/slayer/SlayerRngMeterDisplay.kt | 13 ++++--- .../slayer/blaze/BlazeSlayerDaggerHelper.kt | 15 +++++--- .../at/hannibal2/skyhanni/utils/SimpleTimeMark.kt | 2 + 24 files changed, 161 insertions(+), 144 deletions(-) (limited to 'src/main/java/at/hannibal2') 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: (?.*)" ) - 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)) { 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 { "(?§9Party §8> )?(?.*)§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() + 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>() - private var lastToolTipTime = 0L + private var lastToolTipTime = SimpleTimeMark.farPast() private val cache = mutableMapOf>>() @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? 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 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() private var resultDisplay = mutableMapOf() @@ -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(?