diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt | 21 |
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) { |