aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-31 14:14:58 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-31 14:14:58 +0200
commit9eff744e37e5053f2bf5496305651345afba26a4 (patch)
treef58f498572e9f755340628cf735d73e77208a818 /src/main/java/at
parent5cdd92022f80dc5c1fa21bafca6725e435555c91 (diff)
downloadskyhanni-9eff744e37e5053f2bf5496305651345afba26a4.tar.gz
skyhanni-9eff744e37e5053f2bf5496305651345afba26a4.tar.bz2
skyhanni-9eff744e37e5053f2bf5496305651345afba26a4.zip
Fixed ConcurrentModificationException at DamageIndicatorManager
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt
index 6e0f0080d..e7be3e90f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt
@@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.EntityUtils.hasNameTagWith
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
import at.hannibal2.skyhanni.utils.LorenzUtils.between
+import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
@@ -41,12 +42,10 @@ class DamageIndicatorManager {
private val config get() = SkyHanniMod.feature.damageIndicator
companion object {
- private var data = mutableMapOf<UUID, EntityData>()
+ private var data = mapOf<UUID, EntityData>()
private val damagePattern = "[✧✯]?(\\d+[⚔+✧❤♞☄✷ﬗ✯]*)".toPattern()
- fun isBoss(entity: EntityLivingBase): Boolean {
- return data.values.any { it.entity == entity }
- }
+ fun isBoss(entity: EntityLivingBase) = data.values.any { it.entity == entity }
fun isDamageSplash(entity: EntityLivingBase): Boolean {
if (entity.ticksExisted > 300 || entity !is EntityArmorStand) return false
@@ -57,13 +56,9 @@ class DamageIndicatorManager {
return damagePattern.matcher(name).matches()
}
- fun isBossSpawned(type: BossType): Boolean {
- return data.entries.find { it.value.bossType == type } != null
- }
+ fun isBossSpawned(type: BossType) = data.entries.find { it.value.bossType == type } != null
- fun isBossSpawned(vararg types: BossType): Boolean {
- return types.any { isBossSpawned(it) }
- }
+ fun isBossSpawned(vararg types: BossType) = types.any { isBossSpawned(it) }
fun getDistanceTo(vararg types: BossType): Double {
val playerLocation = LocationUtils.playerLocation()
@@ -84,7 +79,7 @@ class DamageIndicatorManager {
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
mobFinder = MobFinder()
- data.clear()
+ data = emptyMap()
}
@SubscribeEvent(receiveCanceled = true)
@@ -106,7 +101,7 @@ class DamageIndicatorManager {
val waitForRemoval = if (it.value.dead && !noDeathDisplay(it.value.bossType)) 4_000 else 100
(System.currentTimeMillis() > it.value.timeLastTick + waitForRemoval) || (it.value.dead && noDeathDisplay(it.value.bossType))
}.map { it.key }) {
- data.remove(uuid)
+ data.editCopy { remove(uuid) }
}
val sizeHealth: Double
@@ -350,7 +345,7 @@ class DamageIndicatorManager {
entityData.healthText = color.getChatColor() + NumberUtil.format(health)
}
entityData.timeLastTick = System.currentTimeMillis()
- data[entity.uniqueID] = entityData
+ data.editCopy { this[entity.uniqueID] = entityData }
} catch (e: Throwable) {