From 53303c391dc335bc676263f5be75bcc110a74446 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 23 Mar 2023 15:38:34 +0100 Subject: removed toMutableList in render list logic and prevent ConcurrentModificationException --- .../skyhanni/features/misc/NonGodPotEffectDisplay.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 0fc8b26d8..742e91c1d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -24,7 +24,7 @@ class NonGodPotEffectDisplay { private var checkFooter = false private val activeEffects = mutableMapOf() - private val display = mutableListOf() + private var display = listOf() private var lastTick = 0L private var nonGodPotEffects = mapOf( @@ -82,12 +82,17 @@ class NonGodPotEffectDisplay { private fun update() { val now = System.currentTimeMillis() - display.clear() if (activeEffects.values.removeIf { now > it }) { //to fetch the real amount of active pots totalEffectsCount = 0 checkFooter = true } + + display = drawDisplay(now) + } + + private fun drawDisplay(now: Long): MutableList { + val newDisplay = mutableListOf() for (effect in activeEffects.sorted()) { val label = effect.key if (label.contains("Invisibility")) continue @@ -100,14 +105,15 @@ class NonGodPotEffectDisplay { val color = colorForTime(seconds) - display.add("$label $color$format") + newDisplay.add("$label $color$format") } val diff = totalEffectsCount - activeEffects.size if (diff > 0) { - display.add("§eOpen the /effects inventory") - display.add("§eto show the missing $diff effects!") + newDisplay.add("§eOpen the /effects inventory") + newDisplay.add("§eto show the missing $diff effects!") checkFooter = true } + return newDisplay } private fun colorForTime(seconds: Long): String { -- cgit