From 6aa403dffea030f473acdedf30de11c7672bb35d Mon Sep 17 00:00:00 2001 From: ican Date: Sun, 3 Mar 2024 07:34:04 +0800 Subject: [PATCH] Fix ConcurrentModificationsException caused by removing the healing pool --- .../bedwars/arena/upgrades/HealPoolTask.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/upgrades/HealPoolTask.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/upgrades/HealPoolTask.java index 1cac082cb..dfa0148a0 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/upgrades/HealPoolTask.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/upgrades/HealPoolTask.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Iterator; import java.util.Random; import static com.andrei1058.bedwars.BedWars.config; @@ -85,35 +86,41 @@ public static boolean exists(IArena arena, ITeam bwt){ } return false; } - public static void removeForArena(IArena a){ - if (healPoolTasks.isEmpty() || a == null) return; - for (HealPoolTask hpt: healPoolTasks) { + public static void removeForArena(IArena arena) { + if (healPoolTasks.isEmpty() || arena == null) return; + Iterator healPoolTasksIterator = healPoolTasks.iterator(); + while (healPoolTasksIterator.hasNext()) { + HealPoolTask hpt = healPoolTasksIterator.next(); if (hpt == null) continue; - if (hpt.getArena().equals(a)){ + if (hpt.getArena().equals(arena)){ hpt.cancel(); - healPoolTasks.remove(hpt); + healPoolTasksIterator.remove(); } } } - public static void removeForArena(String a){ - if (healPoolTasks == null || healPoolTasks.isEmpty() || (a == null)) return; - for (HealPoolTask hpt: healPoolTasks) { + public static void removeForArena(String arena) { + if (healPoolTasks == null || healPoolTasks.isEmpty() || (arena == null)) return; + Iterator healPoolTasksIterator = healPoolTasks.iterator(); + while (healPoolTasksIterator.hasNext()) { + HealPoolTask hpt = healPoolTasksIterator.next(); if (hpt == null) continue; - if (hpt.getArena().getWorldName().equals(a)){ + if (hpt.getArena().getWorldName().equals(arena)){ hpt.cancel(); - healPoolTasks.remove(hpt); + healPoolTasksIterator.remove(); } } } public static void removeForTeam(ITeam team){ if (healPoolTasks == null || healPoolTasks.isEmpty() || (team == null)) return; - for (HealPoolTask hpt:healPoolTasks) { + Iterator healPoolTasksIterator = healPoolTasks.iterator(); + while (healPoolTasksIterator.hasNext()) { + HealPoolTask hpt = healPoolTasksIterator.next(); if (hpt == null) continue; if (hpt.getBwt().equals(team)){ hpt.cancel(); - healPoolTasks.remove(hpt); + healPoolTasksIterator.remove(); } } }