Getting players names within ArrayList

Discussion in 'Plugin Development' started by OppositeGamer, Dec 30, 2012.

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

    OppositeGamer

    I want to get all the players within this array list and teleport them. But when I do it this way with this code, it just teleports the guy that first clicked the sign.

    Code:
        if(plugin.match.contains(1))
                        {
                        p.sendMessage("Match has already started!");
                        }
                        if(!plugin.match.contains(1)){
                            p.performCommand("join");
                            if(!plugin.start.contains(1))
                            {
                                plugin.start.add(1);
                                startCount = config.getInt("Countdown");
                                    taskID = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
                                        @Override
                                        public void run() {
                                            if(startCount != -1)
                                            {
                                            if(startCount != 0)
                                            {
                                            plugin.getServer().broadcastMessage("Countdown" + startCount);
                                            startCount--;
                                            } else if(startCount == 0){
                                                plugin.getServer().broadcastMessage("GO!!!");
                                                plugin.match.add(1);
                                                spawnPoint.spawnPoint("spawns.yml", plugin, p, 5, 1);
                                                plugin.getServer().getScheduler().cancelTask(taskID);
                                                    }
                                                }
                                        }
                                    }, 0L, 20L);
                                        }
                                    }
    I have an arraylist that stores each player that joins called ArrayList <String> joined = new ArrayList<String>();

    So then I though well hey! I could just use a for statement like so.

    Code:
    for(int i = 0; i < plugin.joined.size(); i++)
    {
     
    for(Player player : plugin.joined.get(i){
     
      }
    }
    But no luck :(
     
  2. Offline

    RealDope

    Code:JAVA
    1.  
    2. for(String s : joined) {
    3. Player player = plugin.getServer().getPlayer(s);
    4. player.teleport(someLocation);
    5. }
    6.  

    Loops through all strings in the list, gets their player instance, and teleports them.
     
  3. Offline

    OppositeGamer

    let me give it a go!

    wait where is the join variable suppost to be? This is what I've got

    Code:
                            for(String s : joined) {
                                Player player = plugin.getServer().getPlayer(s);
                                player.teleport(someLocation);
                                }
    I was just going to add them each time they can click the sign. But what is joined suppost to be because I cant get each entry in the plugin.joined.* what do I put at the star?

    Code:
    if(plugin.match.contains(1))
                        {
                        p.sendMessage("Match has already started!");
                        }
                        if(!plugin.match.contains(1)){
                            p.performCommand("join");
                           
                            for(String s : joined) {
                                Player player = plugin.getServer().getPlayer(s);
                                player.teleport(someLocation);
                                }
                           
                            if(!plugin.start.contains(1))
                            {
                                plugin.start.add(1);
                                startCount = config.getInt("Countdown");
                                    taskID = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
                                        @Override
                                        public void run() {
                                            if(startCount != -1)
                                            {
                                            if(startCount != 0)
                                            {
                                            plugin.getServer().broadcastMessage("Countdown" + startCount);
                                            startCount--;
                                            } else if(startCount == 0){
                                                plugin.getServer().broadcastMessage("GO!!!");
                                                plugin.match.add(1);
                                                spawnPoint.spawnPoint("spawns.yml", plugin, p, 5, 1);
                                                plugin.getServer().getScheduler().cancelTask(taskID);
                                                    }
                                                }
                                        }
                                    }, 0L, 20L);
                                        }
                                    }
                                }
                            }
                        }
                    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Offline

    fireblast709

    joined is an HashSet<String> or ArrayList<String> containing the names of the players that joined
     
Thread Status:
Not open for further replies.

Share This Page