aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-05 09:45:48 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-05 09:45:48 +0200
commita7db8e95d22864c340add384f98150f31cdf35fa (patch)
treef3e445dde6b2cf42a6a4478bd87f4deaecd3caf8 /src/main/java/at/hannibal2
parent722c5ceac257b29126537063cab7909f89a8c376 (diff)
downloadskyhanni-a7db8e95d22864c340add384f98150f31cdf35fa.tar.gz
skyhanni-a7db8e95d22864c340add384f98150f31cdf35fa.tar.bz2
skyhanni-a7db8e95d22864c340add384f98150f31cdf35fa.zip
using editThreadSave to edit the particle burrows list instead of Collections.synchronizedMap
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt3
2 files changed, 8 insertions, 7 deletions
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<LorenzVec, BurrowType>())
+ private var particleBurrows = mapOf<LorenzVec, BurrowType>()
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 <K, V> makeSyncMap(originalMap: MutableMap<K, V>) = Collections.synchronizedMap(originalMap)
+ fun <K, V> Map<K, V>.editThreadSave(function: MutableMap<K, V>.() -> Unit) =
+ toMutableMap().also { function(it) }.toMap()
} \ No newline at end of file