aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-02 06:07:46 +1100
committerGitHub <noreply@github.com>2024-04-01 21:07:46 +0200
commit8b28b68d6956ae406c0b13abece629a197670edf (patch)
tree49ad7909383eecca20cad544535d935177e6feaf /src/main
parent60c5f9c351a7f59622a09cc10a5047c5dca279fa (diff)
downloadskyhanni-8b28b68d6956ae406c0b13abece629a197670edf.tar.gz
skyhanni-8b28b68d6956ae406c0b13abece629a197670edf.tar.bz2
skyhanni-8b28b68d6956ae406c0b13abece629a197670edf.zip
Backend: Less fixed rate timer (#1264)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/FixedRateTimerManager.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/SecondPassedEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt26
11 files changed, 72 insertions, 82 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 118818ca3..590a94ccf 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -19,6 +19,7 @@ import at.hannibal2.skyhanni.data.CropAccessoryData
import at.hannibal2.skyhanni.data.EntityData
import at.hannibal2.skyhanni.data.EntityMovementData
import at.hannibal2.skyhanni.data.FameRanks
+import at.hannibal2.skyhanni.data.FixedRateTimerManager
import at.hannibal2.skyhanni.data.FriendAPI
import at.hannibal2.skyhanni.data.GardenComposterUpgradesData
import at.hannibal2.skyhanni.data.GardenCropMilestones
@@ -487,6 +488,7 @@ class SkyHanniMod {
loadModule(BossbarData)
loadModule(EntityUtils)
loadModule(ChatUtils)
+ loadModule(FixedRateTimerManager())
loadModule(ChromaManager)
// APIs
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index 20679d3e9..bc8522dd6 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.SkillOverflowLevelupEvent
import at.hannibal2.skyhanni.features.skillprogress.SkillProgress
import at.hannibal2.skyhanni.features.skillprogress.SkillType
@@ -38,7 +39,6 @@ import net.minecraft.command.CommandBase
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.LinkedList
import java.util.regex.Matcher
-import kotlin.concurrent.fixedRateTimer
import kotlin.time.Duration.Companion.seconds
object SkillAPI {
@@ -81,13 +81,8 @@ object SkillAPI {
var showDisplay = false
var lastUpdate = SimpleTimeMark.farPast()
- init {
- fixedRateTimer(name = "skyhanni-skillprogress-timer", initialDelay = 1_000L, period = 1_000L) {
- tickSkill()
- }
- }
-
- private fun tickSkill() {
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
val activeSkill = activeSkill ?: return
val info = skillXPInfoMap[activeSkill] ?: return
if (!info.sessionTimerActive) return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/FixedRateTimerManager.kt b/src/main/java/at/hannibal2/skyhanni/data/FixedRateTimerManager.kt
new file mode 100644
index 000000000..a0125d35e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/FixedRateTimerManager.kt
@@ -0,0 +1,20 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.SecondPassedEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import net.minecraft.client.Minecraft
+import kotlin.concurrent.fixedRateTimer
+
+class FixedRateTimerManager {
+ private var totalSeconds = 0
+
+ init {
+ fixedRateTimer(name = "skyhanni-fixed-rate-timer-manager", period = 1000L) {
+ Minecraft.getMinecraft().addScheduledTask {
+ if (!LorenzUtils.onHypixel) return@addScheduledTask
+ SecondPassedEvent(totalSeconds).postAndCatch()
+ totalSeconds++
+ }
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/SecondPassedEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SecondPassedEvent.kt
new file mode 100644
index 000000000..d8290703d
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/SecondPassedEvent.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.events
+
+class SecondPassedEvent(private val totalSeconds: Int) : LorenzEvent() {
+ fun repeatSeconds(i: Int) = i % totalSeconds
+}
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 3547a4827..dfaf5b02f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonMilestonesDisplay.kt
@@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.DungeonStartEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.StringUtils.matches
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.concurrent.fixedRateTimer
class DungeonMilestonesDisplay {
@@ -33,22 +33,16 @@ class DungeonMilestonesDisplay {
fun isMilestoneMessage(message: String): Boolean = milestonePatternList.any { it.matches(message) }
}
- init {
- fixedRateTimer(name = "skyhanni-dungeon-milestone-display", period = 200) {
- if (isEnabled()) {
- checkVisibility()
- }
- }
- }
-
- private fun checkVisibility() {
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!event.isMod(5)) return
if (currentMilestone >= 3 && System.currentTimeMillis() > timeReached + 3_000 && display != "") {
display = display.substring(1)
}
}
@SubscribeEvent(receiveCanceled = true)
- fun onChatPacket(event: LorenzChatEvent) {
+ fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
if (isMilestoneMessage(event.message)) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
index f335b882c..fbd9e246b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
@@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.ConfigUtils
@@ -23,7 +24,6 @@ import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
import com.google.gson.annotations.Expose
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.concurrent.fixedRateTimer
object FrozenTreasureTracker {
@@ -44,11 +44,6 @@ object FrozenTreasureTracker {
init {
FrozenTreasure.entries.forEach { it.chatPattern }
-
- fixedRateTimer(name = "skyhanni-frozen-treasure-tracker", period = 1000) {
- if (!onJerryWorkshop()) return@fixedRateTimer
- calculateIcePerHour()
- }
}
class Data : TrackerData() {
@@ -77,13 +72,15 @@ object FrozenTreasureTracker {
tracker.update()
}
- private fun calculateIcePerHour() {
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ if (!onJerryWorkshop()) return
+
val difference = estimatedIce - lastEstimatedIce
lastEstimatedIce = estimatedIce
if (difference == estimatedIce) return
-
if (difference == 0L) {
if (icePerSecond.isEmpty()) return
stoppedChecks += 1
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt
index 19c3f578e..0abf9d245 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
-import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
@@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.concurrent.fixedRateTimer
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
@@ -28,16 +27,6 @@ class JyrreTimer {
private var display = emptyList<Any>()
private var duration = 0.seconds
- init {
- fixedRateTimer(name = "skyhanni-update-jyrre-display", period = 1000L) {
- try {
- updateJyrreDisplay()
- } catch (error: Throwable) {
- ErrorManager.logErrorWithData(error, "Error Updating Jyrre Timer")
- }
- }
- }
-
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
resetDisplay()
@@ -60,7 +49,8 @@ class JyrreTimer {
config.pos.renderSingleLineWithItems(display, posLabel = "Refined Jyrre Timer")
}
- private fun updateJyrreDisplay() {
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
if (display.isNotEmpty() && !config.showInactive && duration <= 0.seconds) {
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 806f86175..6639f42da 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
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.garden.visitor.VisitorAcceptEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.test.command.ErrorManager
@@ -223,6 +224,12 @@ object GardenVisitorDropStatistics {
return "$amount"
}
+ //todo this should just save when changed not once a second
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ saveAndUpdate()
+ }
+
fun saveAndUpdate() {
if (!GardenAPI.inGarden()) return
val storage = GardenAPI.storage?.visitorDrops ?: return
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 21db46b4b..c35cb9266 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
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.CropClickEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.garden.visitor.VisitorArrivalEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.test.command.ErrorManager
@@ -20,7 +21,6 @@ import at.hannibal2.skyhanni.utils.TimeUtils
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.concurrent.fixedRateTimer
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
@@ -65,20 +65,6 @@ class GardenVisitorTimer {
visitorJustArrived = true
}
- init {
- fixedRateTimer(name = "skyhanni-update-visitor-display", period = 1000L) {
- try {
- updateVisitorDisplay()
- } catch (error: Throwable) {
- ErrorManager.logErrorWithData(error, "Encountered an error when updating visitor display")
- }
- try {
- GardenVisitorDropStatistics.saveAndUpdate()
- } catch (_: Throwable) {
- } // no config yet
- }
- }
-
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
display = ""
@@ -88,7 +74,8 @@ class GardenVisitorTimer {
sixthVisitorReady = false
}
- private fun updateVisitorDisplay() {
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
var visitorsAmount = VisitorAPI.visitorsInTabList(TabListData.getTabList()).size
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 83e428b16..01672ac98 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
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange
import at.hannibal2.skyhanni.utils.ConfigUtils
@@ -25,7 +26,6 @@ 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.concurrent.fixedRateTimer
object PowderTracker {
@@ -73,15 +73,16 @@ object PowderTracker {
init {
PowderChestReward.entries.forEach { it.chatPattern }
+ }
- fixedRateTimer(name = "skyhanni-powder-tracker", period = 1000) {
- if (!isEnabled()) return@fixedRateTimer
- calculateResourceHour(gemstoneInfo)
- calculateResourceHour(mithrilInfo)
- calculateResourceHour(diamondEssenceInfo)
- calculateResourceHour(goldEssenceInfo)
- calculateResourceHour(chestInfo)
- }
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ if (!isEnabled()) return
+ calculateResourceHour(gemstoneInfo)
+ calculateResourceHour(mithrilInfo)
+ calculateResourceHour(diamondEssenceInfo)
+ calculateResourceHour(goldEssenceInfo)
+ calculateResourceHour(chestInfo)
}
private val tracker = SkyHanniTracker("Powder Tracker", { Data() }, { it.powderTracker })
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
index 7fe10ae5d..5b1f4e2ae 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt
@@ -11,10 +11,10 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
-import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha
import at.hannibal2.skyhanni.utils.ConfigUtils
@@ -42,7 +42,6 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.concurrent.fixedRateTimer
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
@@ -101,21 +100,14 @@ object TrevorFeatures {
private val config get() = SkyHanniMod.feature.misc.trevorTheTrapper
- init {
- fixedRateTimer(name = "skyhanni-update-trapper", period = 1000L) {
- if (onFarmingIsland() && config.trapperSolver) {
- Minecraft.getMinecraft().addScheduledTask {
- try {
- updateTrapper()
- TrevorTracker.update()
- TrevorTracker.calculatePeltsPerHour()
- if (questActive) TrevorSolver.findMob()
- } catch (error: Throwable) {
- ErrorManager.logErrorWithData(error, "Encountered an error when updating the trapper solver")
- }
- }
- }
- }
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ if (!onFarmingIsland()) return
+ if (!config.trapperSolver) return
+ updateTrapper()
+ TrevorTracker.update()
+ TrevorTracker.calculatePeltsPerHour()
+ if (questActive) TrevorSolver.findMob()
}
@SubscribeEvent