From a7db8e95d22864c340add384f98150f31cdf35fa Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 5 May 2023 09:45:48 +0200 Subject: using editThreadSave to edit the particle burrows list instead of Collections.synchronizedMap --- .../skyhanni/features/event/diana/GriffinBurrowHelper.kt | 12 ++++++------ src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 55b893938..3458bd2a3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeSyncMap +import at.hannibal2.skyhanni.utils.LorenzUtils.editThreadSave import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine import at.hannibal2.skyhanni.utils.RenderUtils.drawColor @@ -23,7 +23,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class GriffinBurrowHelper { private var guessLocation: LorenzVec? = null - private val particleBurrows = makeSyncMap(mutableMapOf()) + private var particleBurrows = mapOf() private var animationLocation: LorenzVec? = null private var lastDug: LorenzVec? = null private var teleportedLocation: LorenzVec? = null @@ -51,7 +51,7 @@ class GriffinBurrowHelper { @SubscribeEvent fun onBurrowDetect(event: BurrowDetectEvent) { EntityMovementData.addToTrack(Minecraft.getMinecraft().thePlayer) - particleBurrows[event.burrowLocation] = event.type + particleBurrows = particleBurrows.editThreadSave { this[event.burrowLocation] = event.type } if (SkyHanniMod.feature.diana.burrowsNearbyDetection) { checkRemoveGuess(true) @@ -73,7 +73,7 @@ class GriffinBurrowHelper { @SubscribeEvent fun onBurrowDug(event: BurrowDugEvent) { val location = event.burrowLocation - particleBurrows.remove(location) + particleBurrows = particleBurrows.editThreadSave { remove(location) } if (particleBurrows.isNotEmpty()) { animationLocation = location } @@ -92,7 +92,7 @@ class GriffinBurrowHelper { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (event.message.startsWith("§c ☠ §r§7You were killed by §r")) { - particleBurrows.keys.removeIf { particleBurrows[it] == BurrowType.MOB } + particleBurrows = particleBurrows.editThreadSave { keys.removeIf { this[it] == BurrowType.MOB } } } } @@ -101,7 +101,7 @@ class GriffinBurrowHelper { guessLocation = null animationLocation = null lastDug = null - particleBurrows.clear() + particleBurrows = particleBurrows.editThreadSave { clear() } } private fun findBlock(point: LorenzVec): LorenzVec { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index fbb0272f6..043cfe45f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -263,5 +263,6 @@ object LorenzUtils { whenChanged { _, _ -> observer.run() } } - fun makeSyncMap(originalMap: MutableMap) = Collections.synchronizedMap(originalMap) + fun Map.editThreadSave(function: MutableMap.() -> Unit) = + toMutableMap().also { function(it) }.toMap() } \ No newline at end of file -- cgit