Getting players in Arraylist

Discussion in 'Spigot Plugin Development' started by Bear53, May 5, 2015.

  1. so I'm making a minigame and when a player joins the game I want it to send a message to the player that joins what method can I use? To send the message I was trying to do something like this:
    p.sendMessage(ChatColor.GREEN + Main.ingame.(method to get number of players here) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + "24"));
    Thanks!
     
  2. [arraylistname].size() ?
     
  3. Use .size() on an arraylist to get the amount.
     
  4. create a method in the class that has the array list to return the size and to send a message to all the joining players ->

    Code (Text):

    /**
    * get the player count in the arraylist
    */
    public int getPlayerCount () {
        return arrayListName.size();
    }

    /**
    * send a broadcast message to all players in the array list
    * this is assuming that your array list contains a list of UUIDs
    * @param message the message to send
    */
    public void broadcast(String message) {

        for(UUID uuid: getArrayList()) {
            Player player = Bukkit.getPlayer(uuid);
            if(player != null) {
                player.sendMessage(message);
            }
        }
    }
     
    If you do not understand this I suggest you go so something more simpler than a minigame. :p
     
    • Agree Agree x 1
  5. Thanks for all the help! Will msg again if I get a error