diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-06-09 11:48:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-09 11:48:56 +0200 |
commit | 7f593e59c872daffd64f91ac70f7f8689a590c27 (patch) | |
tree | 87dc7aaf7c7c5e3277bee932f0da0fd49f1a2a18 /src/main/java/at/hannibal2/skyhanni/features | |
parent | ffcfa1f6ed831817be918d3bbb42d87088f0bf5d (diff) | |
download | skyhanni-7f593e59c872daffd64f91ac70f7f8689a590c27.tar.gz skyhanni-7f593e59c872daffd64f91ac70f7f8689a590c27.tar.bz2 skyhanni-7f593e59c872daffd64f91ac70f7f8689a590c27.zip |
Backend: Storage SimpleTimeMark (#2038)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
9 files changed, 48 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt index 88d9f52a8..fed11dac0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -73,8 +73,8 @@ object CityProjectFeatures { if (LorenzUtils.skyBlockArea == "Community Center") return - if (playerSpecific.nextCityProjectParticipationTime == 0L) return - if (System.currentTimeMillis() <= playerSpecific.nextCityProjectParticipationTime) return + if (playerSpecific.nextCityProjectParticipationTime.isFarPast()) return + if (playerSpecific.nextCityProjectParticipationTime.isInFuture()) return if (lastReminderSend.passedSince() < 30.seconds) return lastReminderSend = SimpleTimeMark.now() @@ -131,7 +131,7 @@ object CityProjectFeatures { if (item.name != "§eContribute this component!") continue nextTime = now } - ProfileStorageData.playerSpecific?.nextCityProjectParticipationTime = nextTime.toMillis() + ProfileStorageData.playerSpecific?.nextCityProjectParticipationTime = nextTime } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index 97e5926ba..a9977f809 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -17,11 +17,13 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow import at.hannibal2.skyhanni.utils.TimeUtils.format import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.Collections import kotlin.time.Duration +import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @SkyHanniModule @@ -84,7 +86,7 @@ object ComposterDisplay { private fun addComposterEmptyTime(emptyTime: Duration?): List<Any> { return if (emptyTime != null) { - GardenAPI.storage?.composterEmptyTime = System.currentTimeMillis() + emptyTime.inWholeMilliseconds + GardenAPI.storage?.composterEmptyTime = emptyTime.fromNow() val format = emptyTime.format() listOf(bucket, "§b$format") } else { @@ -127,22 +129,21 @@ object ComposterDisplay { val storage = storage ?: return - if (ComposterAPI.getOrganicMatter() <= config.notifyLow.organicMatter && System.currentTimeMillis() >= storage.informedAboutLowMatter) { + if (ComposterAPI.getOrganicMatter() <= config.notifyLow.organicMatter && storage.informedAboutLowMatter.isInPast()) { if (config.notifyLow.title) { LorenzUtils.sendTitle("§cYour Organic Matter is low", 4.seconds) } ChatUtils.chat("§cYour Organic Matter is low!") - storage.informedAboutLowMatter = System.currentTimeMillis() + 60_000 * 5 + storage.informedAboutLowMatter = 5.0.minutes.fromNow() } - if (ComposterAPI.getFuel() <= config.notifyLow.fuel && - System.currentTimeMillis() >= storage.informedAboutLowFuel + if (ComposterAPI.getFuel() <= config.notifyLow.fuel && storage.informedAboutLowFuel.isInPast() ) { if (config.notifyLow.title) { LorenzUtils.sendTitle("§cYour Fuel is low", 4.seconds) } ChatUtils.chat("§cYour Fuel is low!") - storage.informedAboutLowFuel = System.currentTimeMillis() + 60_000 * 5 + storage.informedAboutLowFuel = 5.0.minutes.fromNow() } } @@ -159,13 +160,13 @@ object ComposterDisplay { private fun checkWarningsAndOutsideGarden() { val format = GardenAPI.storage?.let { - if (it.composterEmptyTime != 0L) { - val duration = it.composterEmptyTime - System.currentTimeMillis() - if (duration > 0) { - if (duration < 1000 * 60 * 20) { + if (!it.composterEmptyTime.isFarPast()) { + val duration = it.composterEmptyTime.timeUntil() + if (duration > 0.0.seconds) { + if (duration < 20.0.minutes) { warn("Your composter in the garden is almost empty!") } - TimeUtils.formatDuration(duration, maxUnits = 3) + duration.format(maxUnits = 3) } else { warn("Your composter is empty!") "§cComposter is empty!" @@ -187,8 +188,8 @@ object ComposterDisplay { if (ReminderUtils.isBusy()) return - if (System.currentTimeMillis() < storage.lastComposterEmptyWarningTime + 1000 * 60 * 2) return - storage.lastComposterEmptyWarningTime = System.currentTimeMillis() + if (storage.lastComposterEmptyWarningTime.passedSince() >= 2.0.minutes) return + storage.lastComposterEmptyWarningTime = SimpleTimeMark.now() if (IslandType.GARDEN.isInIsland()) { ChatUtils.chat(warningMessage) } else { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index ec3622aa3..3a69f2ece 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -15,7 +15,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData @@ -120,7 +119,7 @@ object GardenVisitorTimer { millis = sixthVisitorArrivalTime.timeUntil() val nextSixthVisitorArrival = SimpleTimeMark.now() + millis + (visitorInterval * (5 - visitorsAmount)) - GardenAPI.storage?.nextSixthVisitorArrival = nextSixthVisitorArrival.toMillis() + GardenAPI.storage?.nextSixthVisitorArrival = nextSixthVisitorArrival if (isSixthVisitorEnabled() && millis.isNegative()) { visitorsAmount++ if (!sixthVisitorReady) { @@ -183,9 +182,8 @@ object GardenVisitorTimer { fun onWorldChange(event: LorenzWorldChangeEvent) { lastVisitors = -1 GardenAPI.storage?.nextSixthVisitorArrival?.let { - val badTime = Duration.INFINITE.inWholeMilliseconds - if (it != badTime && it != -9223370336633802065) { - sixthVisitorArrivalTime = it.asTimeMark() + if (it.isFarFuture() && it.toMillis() != -9223370336633802065) { + sixthVisitorArrivalTime = it } } sixthVisitorReady = false diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/BeaconPower.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/BeaconPower.kt index 60ed3ed66..0eb596afc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/BeaconPower.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/BeaconPower.kt @@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher 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.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -45,9 +44,9 @@ object BeaconPower { ) private var expiryTime: SimpleTimeMark - get() = storage?.beaconPowerExpiryTime?.asTimeMark() ?: SimpleTimeMark.farPast() + get() = storage?.beaconPowerExpiryTime ?: SimpleTimeMark.farPast() set(value) { - storage?.beaconPowerExpiryTime = value.toMillis() + storage?.beaconPowerExpiryTime = value } private var stat: String? @@ -118,6 +117,5 @@ object BeaconPower { } } - private fun isEnabled() = LorenzUtils.inSkyBlock && config.beaconPower } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt index 45fbd65de..00e8870d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateAmount.kt @@ -26,13 +26,13 @@ enum class ChocolateAmount(val chocolate: () -> Long) { fun timeUntilGoal(goal: Long): Duration { val profileStorage = profileStorage ?: return Duration.ZERO - val updatedAgo = SimpleTimeMark(profileStorage.lastDataSave).passedSince().inWholeSeconds + val updatedAgo = profileStorage.lastDataSave.passedSince().inWholeSeconds return ChocolateFactoryAPI.timeUntilNeed(goal - chocolate()) - updatedAgo.seconds } companion object { fun chocolateSinceUpdate(): Long { - val lastUpdate = SimpleTimeMark(profileStorage?.lastDataSave ?: return 0) + val lastUpdate = profileStorage?.lastDataSave ?: return 0 val currentTime = SimpleTimeMark.now() val secondsSinceUpdate = (currentTime - lastUpdate).inWholeSeconds @@ -77,9 +77,9 @@ enum class ChocolateAmount(val chocolate: () -> Long) { private fun updateBestUpgrade() { profileStorage?.let { - if (it.bestUpgradeAvailableAt == 0L || it.bestUpgradeCost == 0L) return + if (it.bestUpgradeAvailableAt.isFarPast() || it.bestUpgradeCost == 0L) return val canAffordAt = SimpleTimeMark.now() + CURRENT.timeUntilGoal(it.bestUpgradeCost) - it.bestUpgradeAvailableAt = canAffordAt.toMillis() + it.bestUpgradeAvailableAt = canAffordAt } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt index ff2b3276a..a0c177abb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt @@ -180,7 +180,7 @@ object ChocolateFactoryDataLoader { profileStorage.rawChocPerSecond = (ChocolateFactoryAPI.chocolatePerSecond / profileStorage.chocolateMultiplier + .01).toInt() - profileStorage.lastDataSave = SimpleTimeMark.now().toMillis() + profileStorage.lastDataSave = SimpleTimeMark.now() ChocolateFactoryStats.updateDisplay() @@ -287,9 +287,9 @@ object ChocolateFactoryDataLoader { val activeDuration = TimeUtils.getDuration(formattedGroup) val activeUntil = SimpleTimeMark.now() + activeDuration - profileStorage.currentTimeTowerEnds = activeUntil.toMillis() + profileStorage.currentTimeTowerEnds = activeUntil } else { - profileStorage.currentTimeTowerEnds = 0 + profileStorage.currentTimeTowerEnds = SimpleTimeMark.farPast() } } timeTowerRechargePattern.matchMatcher(line) { @@ -298,7 +298,7 @@ object ChocolateFactoryDataLoader { val timeUntilTower = TimeUtils.getDuration(formattedGroup) val nextTimeTower = SimpleTimeMark.now() + timeUntilTower - profileStorage.nextTimeTower = nextTimeTower.toMillis() + profileStorage.nextTimeTower = nextTimeTower } } } @@ -435,7 +435,7 @@ object ChocolateFactoryDataLoader { list.filter { !it.isMaxed && it.slotIndex != ChocolateFactoryAPI.timeTowerIndex && it.effectiveCost != null } val bestUpgrade = notMaxed.minByOrNull { it.effectiveCost ?: Double.MAX_VALUE } - profileStorage.bestUpgradeAvailableAt = bestUpgrade?.canAffordAt?.toMillis() ?: 0 + profileStorage.bestUpgradeAvailableAt = bestUpgrade?.canAffordAt ?: SimpleTimeMark.farPast() profileStorage.bestUpgradeCost = bestUpgrade?.price ?: 0 ChocolateFactoryAPI.bestPossibleSlot = bestUpgrade?.getValidUpgradeIndex() ?: -1 diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt index ba410d145..4d4fdf068 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTimeTowerManager.kt @@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.utils.SoundUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration import kotlin.time.Duration.Companion.hours -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -30,8 +29,8 @@ object ChocolateFactoryTimeTowerManager { if (!LorenzUtils.inSkyBlock) return val profileStorage = profileStorage ?: return - if (SimpleTimeMark(profileStorage.currentTimeTowerEnds).isInPast()) { - profileStorage.currentTimeTowerEnds = SimpleTimeMark.farPast().toMillis() + if (profileStorage.currentTimeTowerEnds.isInPast()) { + profileStorage.currentTimeTowerEnds = SimpleTimeMark.farPast() } if (ChocolateFactoryAPI.inChocolateFactory) return @@ -40,13 +39,13 @@ object ChocolateFactoryTimeTowerManager { timeTowerReminder() } - val nextCharge = SimpleTimeMark(profileStorage.nextTimeTower) + val nextCharge = profileStorage.nextTimeTower if (nextCharge.isInPast() && !nextCharge.isFarPast() && currentCharges() < maxCharges()) { profileStorage.currentTimeTowerUses++ - val nextTimeTower = SimpleTimeMark(profileStorage.nextTimeTower) + (profileStorage.timeTowerCooldown).hours - profileStorage.nextTimeTower = nextTimeTower.toMillis() + val nextTimeTower = profileStorage.nextTimeTower + (profileStorage.timeTowerCooldown).hours + profileStorage.nextTimeTower = nextTimeTower if (!config.timeTowerWarning) return ChatUtils.clickableChat( @@ -98,20 +97,20 @@ object ChocolateFactoryTimeTowerManager { fun timeTowerFull() = currentCharges() >= maxCharges() fun timeTowerActive(): Boolean { - val currentTime = profileStorage?.lastDataSave ?: 0 + val currentTime = profileStorage?.lastDataSave ?: SimpleTimeMark.farPast() val endTime = timeTowerEnds() return endTime > currentTime } - private fun timeTowerEnds(): Long { - return profileStorage?.currentTimeTowerEnds ?: 0 + private fun timeTowerEnds(): SimpleTimeMark { + return profileStorage?.currentTimeTowerEnds ?: SimpleTimeMark.farPast() } private fun timeTowerReminder() { if (lastTimeTowerReminder.passedSince() < 20.seconds) return - val timeUntil = SimpleTimeMark(timeTowerEnds()).timeUntil() + val timeUntil = timeTowerEnds().timeUntil() if (timeUntil < 1.minutes && timeUntil.isPositive()) { ChatUtils.clickableChat( "§cYour Time Tower is about to end! " + @@ -128,7 +127,7 @@ object ChocolateFactoryTimeTowerManager { fun timeTowerFullTimeMark(): SimpleTimeMark { val profileStorage = profileStorage ?: return SimpleTimeMark.farPast() if (timeTowerFull()) return SimpleTimeMark.farPast() - val nextChargeDuration = SimpleTimeMark(profileStorage.nextTimeTower) + val nextChargeDuration = profileStorage.nextTimeTower val remainingChargesAfter = profileStorage.maxTimeTowerUses - (profileStorage.currentTimeTowerUses + 1) val endTime = nextChargeDuration + ChocolateFactoryAPI.timeTowerChargeDuration() * remainingChargesAfter @@ -137,11 +136,11 @@ object ChocolateFactoryTimeTowerManager { fun timeTowerActiveDuration(): Duration { if (!timeTowerActive()) return Duration.ZERO - val currentTime = profileStorage?.lastDataSave ?: 0 - val endTime = profileStorage?.currentTimeTowerEnds ?: 0 + val currentTime = profileStorage?.lastDataSave ?: SimpleTimeMark.farPast() + val endTime = profileStorage?.currentTimeTowerEnds ?: SimpleTimeMark.farPast() val duration = endTime - currentTime - return duration.milliseconds + return duration } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt index 04d61966e..e04a882fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt @@ -27,7 +27,7 @@ object ChocolateFactoryUpgradeWarning { if (!LorenzUtils.inSkyBlock) return val profileStorage = profileStorage ?: return - val upgradeAvailableAt = SimpleTimeMark(profileStorage.bestUpgradeAvailableAt) + val upgradeAvailableAt = profileStorage.bestUpgradeAvailableAt if (upgradeAvailableAt.isInPast() && !upgradeAvailableAt.isFarPast()) { checkUpgradeWarning() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt index f71a4b341..8aac00e5b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt @@ -14,7 +14,7 @@ object ChocolatePositionChange { fun update(position: Int?, leaderboard: String) { position ?: return val storage = storage ?: return - val lastTime = storage.lastTime?.let { SimpleTimeMark(it) } + val lastTime = storage.lastTime val lastPosition = storage.lastPosition val lastLeaderboard = storage.lastLeaderboard @@ -34,7 +34,7 @@ object ChocolatePositionChange { } } - storage.lastTime = SimpleTimeMark.now().toMillis() + storage.lastTime = SimpleTimeMark.now() storage.lastLeaderboard = leaderboard storage.lastPosition = position } |