diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-30 12:50:31 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-30 12:50:31 +0100 |
commit | b49c4b47c2910ab6ae75b62acf9fcc455d1da501 (patch) | |
tree | 4d0289149e02bf43a1d6704d21b8283c9c74820f /src/main/java/at/hannibal2/skyhanni | |
parent | 9e418deb7cb94b048d7bd6d41e85c3d439108698 (diff) | |
download | skyhanni-b49c4b47c2910ab6ae75b62acf9fcc455d1da501.tar.gz skyhanni-b49c4b47c2910ab6ae75b62acf9fcc455d1da501.tar.bz2 skyhanni-b49c4b47c2910ab6ae75b62acf9fcc455d1da501.zip |
fixed ConcurrentModificationException in DelayedRun
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt | 25 |
2 files changed, 18 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt index 56d565299..2ec0ea667 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt @@ -72,11 +72,11 @@ object MinecraftData { Minecraft.getMinecraft().thePlayer ?: return totalTicks++ LorenzTickEvent(totalTicks).postAndCatch() - DelayedRun.checkRuns() } @SubscribeEvent fun onTick(event: LorenzTickEvent) { + DelayedRun.checkRuns() if (!LorenzUtils.inSkyBlock) return val hand = InventoryUtils.getItemInHand() val newItem = hand?.getInternalName() ?: NEUInternalName.NONE diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt index 2af59435d..f90237588 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt @@ -1,25 +1,34 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import kotlin.time.Duration +// TODO find better sync bug fix than creating a new map for each use object DelayedRun { - val map = mutableMapOf<() -> Any, SimpleTimeMark>() + var map = mapOf<() -> Any, SimpleTimeMark>() fun runDelayed(duration: Duration, run: () -> Unit) { - map[run] = SimpleTimeMark.now() + duration + map = map.editCopy { + this[run] = SimpleTimeMark.now() + duration + } } fun runNextTick(run: () -> Unit) { - map[run] = SimpleTimeMark.now() + map = map.editCopy { + this[run] = SimpleTimeMark.now() + } } fun checkRuns() { - map.entries.removeIf { (runnable, time) -> - val inPast = time.isInPast() - if (inPast) { - runnable() + if (map.isEmpty()) return + map = map.editCopy { + entries.removeIf { (runnable, time) -> + val inPast = time.isInPast() + if (inPast) { + runnable() + } + inPast } - inPast } } } |