Fix ConcurrentModification error

This commit is contained in:
ceze88 2024-07-10 19:09:25 +02:00
parent 2cdbef2ee3
commit cbfe903745

View File

@ -6,6 +6,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import java.util.ArrayList;
import java.util.List;
public class WorldListeners implements Listener {
private final EpicSpawners plugin;
@ -16,10 +19,12 @@ public class WorldListeners implements Listener {
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
// Unload previous spawners belonging to this world.
List<PlacedSpawner> remove = new ArrayList<>();
for (PlacedSpawner ps : this.plugin.getSpawnerManager().getSpawners()) {
if (e.getWorld().getName().equals(ps.getWorld().getName())) {
this.plugin.getSpawnerManager().removeSpawnerFromWorld(ps);
if (ps.getWorld() == null || e.getWorld().getName().equals(ps.getWorld().getName())) {
remove.add(ps);
}
}
this.plugin.getSpawnerManager().removeSpawnersFromWorld(remove);
}
}