Send a message to players on ArrayList?

Discussion in 'Plugin Development' started by iLalox, Apr 17, 2015.

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

    iLalox

    Hi! em..
    How can i send a message to a players on a ArrayList? :s
     
  2. Offline

    ShadowLAX

    @iLalox Depends on how you store the player's information. If you store their instance (which you shouldn't, as it is bad practice and causes memory leaks), then just simply get the player from the array and send them a message. If you store their names or UUID, get it from the array and use Bukkit.getPlayer() and then send them the message.
     
  3. Offline

    teej107

    Storing players in collections isn't bad practice. Forgetting to remove them is.
     
    nverdier likes this.
  4. Offline

    Vextricity

    You could loop through all the players on the server, and then test if the array list contains the player.
    Code:
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (arraylist.contains(p) {
          p.sendMessage(message)
        }
    }
     
  5. Offline

    teej107

    @Vextricity That completely gets rid of the point of the list. Just loop through the list.
     
  6. Offline

    nverdier

    Well at least he didn't spoonfeed code that would solve the OP's problem. The OP should take that and make it work for him, now that it's out there.
     
Thread Status:
Not open for further replies.

Share This Page