Hello Everyone i am creating a game mode for Bukkit and am encountering a problem that at the moment seems to baffling me. Perhaps i am simply over looking something so i would very much appreciate it if i could have another pair of eyes look at this segment of code. Here is my situation i have a command that creates a Game. This is a class Type. Every time the /newgame command is used it adds it to a ArrayList. Now it is supposed to check to see if a game with its name already exists. It only works for the first game name. so if i make a game called "game1" and then try to make "game1" again it returns "Can not create game with the name of game1" but when i make another one for example if i add the game"game2" and then i make "game2" again it allows it to be created. It only appears to working on the first game made. If someone could help it would be of much help so thanks in advance.
Note: The Main.games.size() always goes up so the games are being created but only the first game can not be created more then once any game after that can have the same name for some reason.
Here is the code Snippet in my CommandExecuter
if (cmd.equalsIgnoreCase("newgame")){
Player player = sender.getServer().getPlayer(sender.getName());
if (Main.games.size() == 0){
Main.games.add(new Game(args[0]));
player.sendMessage(ChatColor.GREEN + "Game Created. To join Type " + ChatColor.ITALIC + "/join " + args[0]);
return true;
}else{
//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]) == false){
Main.games.add(new Game(args[0]));
player.sendMessage(ChatColor.GREEN + "Game Created. To join Type " + ChatColor.ITALIC + "/join " + args[0]);
//debug
player.sendMessage(Main.games.size() + ""); // + "" id
return true;
}else{
//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;
}
}
}