Problem/Bug How do I get everyone from an ArrayList?

Discussion in 'Bukkit Help' started by ObviousEmeralds, Nov 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    ObviousEmeralds

    Hey, so I'm creating a simple PvP mini-game plugin and I'm getting a bug I can't fix. When a player does "/pvp join" they get added to an ArrayList, Once 2 players are in the arraylist, they get teleported to a random spawn depending on their team and what was set. My problem is, Whenever 1 player does the command, everything goes alright, they get added to the waiting room, etc. If a second person joins, nothing happens. They can both do the command, they'll be teleported to the waiting room, but won't be teleported to the spawnpoints. I believe the error is in the for loop for the ArrayList. I don't even know if an ArrayList is the best way to do this :p Here's my code:
    Code:
            if(args[0].equalsIgnoreCase("join")){
                if(getConfig().getString("Spawnpoint.red") == null || getConfig().getString("Spawnpoint.blue") == null){
                    p.sendMessage("Must set spawnpoints for the game.");
                    return true;
                }
                World w = Bukkit.getServer().getWorld(getConfig().getString("Waiting-Lobby.w"));
                double x = getConfig().getDouble("Waiting-Lobby.x");
                double y = getConfig().getDouble("Waiting-Lobby.y");
                double z = getConfig().getDouble("Waiting-Lobby.z");
                p.teleport(new Location(w,x,y,z));
               
                Bukkit.getServer().broadcastMessage(ChatColor.GOLD+p.getName()+" Joined PvP! You can join too by typing "+ChatColor.YELLOW+"/pvp join"+ChatColor.GOLD+"! See you there!");
                Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
                    public void run(){
                        waiting.add(p);
                        if(waiting.size() == 2){
    
                            for(Player play : waiting){
                               
                                Random r = new Random();
                                int i =  r.nextInt(10+1);
                                String loc = "Spawnpoint.red."+ i;
                                World w = Bukkit.getServer().getWorld(getConfig().getString(loc+".w"));
                                double locx =  getConfig().getDouble(loc+".x");
                                double locy =  getConfig().getDouble(loc+".y");
                                double locz =  getConfig().getDouble(loc+".z");
                               
                                Location l = new Location(w,locx,locy,locz);
                                play.teleport(l);
                                play.sendMessage(ChatColor.GOLD+""+waiting.size()+" players have joined! Game started");
                                waiting.remove(play);
                                waiting.remove(p);
                            }
                            Bukkit.getServer().getScheduler().cancelAllTasks();
                           
                        }
                    }
                }, 0, 40);
                return true;
            }
               
       
           
            return true;
            //END OF PVP
        }
    Here are my ArrayLists:
    Code:
        final ArrayList<Player> waiting = new ArrayList<Player>();
        ArrayList<Player> ingame = new ArrayList<Player>();
        ArrayList<Player> blue = new ArrayList<Player>();
        ArrayList<Player> red = new ArrayList<Player>();
        
    If you need me to show you the full code, I can but it's 311 lines long.
     
  2. Offline

    ObviousEmeralds

  3. Offline

    ObviousEmeralds

Thread Status:
Not open for further replies.

Share This Page