java - Serious problems with Bukkit plugin [unexpected behavior] -


hello once again stackoverflow! having hardest time plugin reason. here issues. have game class method tick post it, dose not seem work right not send debug message player @ all! , noticed there concurrentmodificationexception on list holds class game. i'm not sure causing concurrentmodificationexception because glanced on code , not appear modifying list within iteration. didnt want show code feel need show bit of it. if on these segments , try shed light on grateful! if 1 point out causing concurrentmodificationexception awesome , if 1 explain me why p.sendmessage("test!"); dosent seem occur @ all.

the concurrentmodificationexception fixed!

segment class main:

public class main extends javaplugin implements runnable { //holds 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){         (game game: games){             game.tick();         }     } } 

}

segment command handler: concurrentmodificationexception error happens on 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 game name.");             return true;         }else{         player player = sender.getserver().getplayer(sender.getname());                 //loop , check                 game game;                 (int = 0; < main.games.size(); i++){                     game = main.games.get(i);                     if (game.getname().equalsignorecase(args[0])){                         //tells game exists name.                         player.sendmessage(chatcolor.red + "can not create game name of " + args[0]);                         return true;                     }                 }                    // have reached end of loop know none of                  // games in list match. can return.                 main.games.add(new game(args[0],sender.getserver().getplayer(sender.getname())));                 player.sendmessage(chatcolor.green + "game created. join type " + chatcolor.italic + "/join " + args[0]);                 return true;             } 

segment 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.             (player p: terrorists){                 p.sendmessage("test!");             }         }else{             //clean             terrorists.clear();             traitors.clear();         } } 

do still have problem concurrentmodificationexception fixed?

in code segments you've provided, can't see anywhere you're adding players game's terrorists list. if game ticking, there's no-one send message to.

further, perhaps debugging sending hard-coded message player or game's creator help. show if game registering players correctly.

myworld.getplayer(*yournickname*).sendmessage("game tick!");  (player p: terrorists) {     p.sendmessage("test! terrorist!"); } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -