From b26814bc3b7559c999dbbb11d0aec11f6ecb2be3 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:33:50 +0200 Subject: Fixed a rare crash while doing enderman slayer. --- .../features/slayer/enderman/EndermanSlayerFeatures.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt index dcdadf84a..776545a6b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt @@ -30,7 +30,7 @@ class EndermanSlayerFeatures { private val config get() = SkyHanniMod.feature.slayer private val beaconConfig get() = config.endermanBeaconConfig private val endermenWithBeacons = mutableListOf() - private val flyingBeacons = mutableListOf() + private var flyingBeacons = listOf() private val nukekubiSkulls = mutableListOf() private var sittingBeacon = mapOf() private val logger = LorenzLogger("slayer/enderman") @@ -56,7 +56,9 @@ class EndermanSlayerFeatures { if (showBeacon()) { val stack = entity.inventory[4] ?: return if (stack.name == "Beacon" && canSee(LocationUtils.playerEyeLocation(), entity.getLorenzVec())) { - flyingBeacons.add(entity) + flyingBeacons = flyingBeacons.editCopy { + add(entity) + } if (beaconConfig.showWarning) TitleUtils.sendTitle("ยง4Beacon", 2.seconds) logger.log("Added flying beacons at ${entity.getLorenzVec()}") @@ -163,7 +165,11 @@ class EndermanSlayerFeatures { if (!event.repeatSeconds(1)) return nukekubiSkulls.also { skulls -> skulls.removeAll { it.isDead } } - flyingBeacons.also { beacons -> beacons.removeAll { it.isDead } } + if (flyingBeacons.any { it.isDead }) { + flyingBeacons = flyingBeacons.editCopy { + removeAll { it.isDead } + } + } // Removing the beacon if It's still there after 7 sesconds. // This is just a workaround for the cases where the ServerBlockChangeEvent don't detect the beacon despawn info. @@ -184,7 +190,9 @@ class EndermanSlayerFeatures { if (event.new == "beacon") { val armorStand = flyingBeacons.find { location.distance(it.getLorenzVec()) < 3 } if (armorStand != null) { - flyingBeacons.remove(armorStand) + flyingBeacons = flyingBeacons.editCopy { + remove(armorStand) + } sittingBeacon = sittingBeacon.editCopy { this[location] = SimpleTimeMark.now() } logger.log("Replaced flying beacon with sitting beacon at $location") } @@ -199,7 +207,7 @@ class EndermanSlayerFeatures { @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { endermenWithBeacons.clear() - flyingBeacons.clear() + flyingBeacons = emptyList() nukekubiSkulls.clear() sittingBeacon = emptyMap() logger.log("Reset everything (world change)") -- cgit