From 4e98f4a176fb8bfe2b9c9afcdb4b941d5b721704 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 13 May 2024 12:40:21 +0200 Subject: Improvement: performance in various ways (#1782) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/data') diff --git a/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt b/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt index f7a730a65..28f1e254b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt @@ -1,10 +1,12 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds object EventCounter { @@ -14,8 +16,15 @@ object EventCounter { private var map = mutableMapOf() private var lastUpdate = SimpleTimeMark.farPast() + private var enabled = false + + @SubscribeEvent + fun onSecondPassed(event: SecondPassedEvent) { + enabled = LorenzUtils.onHypixel && config.eventCounter + } + fun count(eventName: String) { - if (!isEnabled()) return + if (!enabled) return map.addOrPut(eventName, 1) @@ -42,6 +51,4 @@ object EventCounter { println("") println("total: ${total.addSeparators()}") } - - private fun isEnabled() = LorenzUtils.onHypixel && config.eventCounter } -- cgit