Hello once again stackoverflow! I am having the hardest time with this plugin for some reason. Here are the issues. So it have a game class with a method tick i will post it, but it dose not seem to work right it will not send the debug message to the player at all! And then i noticed that there was a ConcurrentModificationException on the list that holds the class game. I'm honestly not sure what is causing the ConcurrentModificationException because i glanced over my code and i do not appear to be modifying the list from within an iteration. I didnt really want to show all my code but i feel like i will need to show a bit of it. If you could look over these segments and try to shed some light on it i would be very grateful! If some one could point out what is causing the ConcurrentModificationException that would be awesome and if some one could explain to me why p.sendMessage("test!"); dosent seem to occur at all.
the ConcurrentModificationException is fixed!
Segment From Class Main:
public class Main extends JavaPlugin implements Runnable {
//Holds all active games
public static ArrayList<Game> games = new ArrayList<Game>();
private CommandHandler cmdHandler = new CommandHandler(this);
private Thread thread = new Thread(this);
private boolean serverActive = true;
public void onEnable(){
//Command stuff here
thread.start();
}
public void onDisable(){
serverActive = false;
}
@Override
public void run() {
//Loop through games.
while(serverActive == true){
for (Game game: games){
game.Tick();
}
}
}
}
Segment from command Handler: The ConcurrentModificationException Error happens on the newgame command
@Override
public boolean onCommand(CommandSender sender, Command arg, String cmd, String[] args){
if (cmd.equalsIgnoreCase("newgame")){
if (args.length == 0){
sender.sendMessage(ChatColor.RED + "Please enter a game name.");
return true;
}else{
Player player = sender.getServer().getPlayer(sender.getName());
//Loop and Check
Game game;
for (int i = 0; i < Main.games.size(); i++){
game = Main.games.get(i);
if (game.getName().equalsIgnoreCase(args[0])){
//Tells that a game already exists with that name.
player.sendMessage(ChatColor.RED + "Can not create game with the name of " + args[0]);
return true;
}
}
// We have reached the end of the loop so we now know that none of the
// games in the list match. Now we can return.
Main.games.add(new Game(args[0],sender.getServer().getPlayer(sender.getName())));
player.sendMessage(ChatColor.GREEN + "Game Created. To join Type " + ChatColor.ITALIC + "/join " + args[0]);
return true;
}
Segment from Game class:
//Teams
public ArrayList<Player> terrorists = new ArrayList<Player>();
private ArrayList<Player> traitors = new ArrayList<Player>();
public Game(String gameName, Player gameOwner){
this.gameName = gameName;
this.gameOwner = gameOwner;
state = State.Idle;
}
public void Tick(){
if (state == State.Active){
//Perform while Active Game.
}else if (state == State.Idle){
//Perform while Idle Game.
for (Player p: terrorists){
p.sendMessage("test!");
}
}else{
//Clean up
terrorists.clear();
traitors.clear();
}
}