Fix auto-leave-on-end: true error.

The ConcurrentModificationException happens because the player leave
procedure alters the `specPlayers` set, and this is the set we iterate
during the automatic spectator kicking procedure. By making a copy of
the set and iterating the copy, we circumvent this problem. Java 101,
really, but when the code is stateful and complex, it's "fair enough"
that it slipped through the cracks. It's also impossible to reproduce
without at least two players, so go figure...

Fixes #802
This commit is contained in:
Andreas Troelsen
2024-10-06 15:47:50 +02:00
parent b4db44985b
commit bafc17e1df
2 changed files with 3 additions and 1 deletions
+1
View File
@@ -24,6 +24,7 @@ These changes will (most likely) be included in the next version.
### Fixed ### Fixed
- MobArena no longer throws errors when handling block explosions on Minecraft 1.21. - MobArena no longer throws errors when handling block explosions on Minecraft 1.21.
- MobArena no longer throws errors during the automatic removal of spectators when using `auto-leave-on-end: true`.
- The `shuffle-positions` ability now correctly shuffles the position of the boss as well if `monster-teleport` is set to `false`. - The `shuffle-positions` ability now correctly shuffles the position of the boss as well if `monster-teleport` is set to `false`.
- The `obsidian-bomb` ability no longer breaks boss waves. - The `obsidian-bomb` ability no longer breaks boss waves.
- Text on Arena Signs is no longer explicitly truncated. This fixes an issue where color codes would count towards the character limit, causing the text that would otherwise fit on the sign to be cut off. - Text on Arena Signs is no longer explicitly truncated. This fixes an issue where color codes would count towards the character limit, causing the text that would otherwise fit on the sign to be cut off.
@@ -665,7 +665,8 @@ public class ArenaImpl implements Arena
// Auto-leave // Auto-leave
if (settings.getBoolean("auto-leave-on-end", false)) { if (settings.getBoolean("auto-leave-on-end", false)) {
specPlayers.forEach(this::playerLeave); List<Player> spectators = new ArrayList<>(specPlayers);
spectators.forEach(this::playerLeave);
} }
return true; return true;