I'm working on a plugin for a game server api known as Bukkit; this plugin allows players to play a minigame - a game within their game.
The problem I'm facing is stopping the game. When the game stops, it loops through all players within that game and then removes them. The problem is that when the player is removed, they are removed from the arena list. This arena list is what is being looped over; causing the ConcurrentModificationException.
Here is my code:
ArrayList<String> players = new ArrayList<String>(arena.getPlayers());
for(String player : players){
removePlayer(Bukkit.getPlayer(player));
}
Within the removePlayer function, the player is being remove from arena.getPlayers().
Any help would be appreciated.
EDIT: Here's the github repo https://github.com/MCMedia/GunGames/blob/master/src/com/ViralAftermath/GunGame/Arena/ArenaManager.java