1.14.4 All player code

Discussion in 'Spigot Plugin Development' started by animegirlskeppy, Apr 14, 2021.

  1. I've recently started coding and I need help. I need a code that executes the command for every player.
    I want to do player.sendmessage but all players should send a message instead of only the person that executes the command.
     
  2. to anwser your question:
    Code (Text):
    for (Player all : Bukkit.getOnlinePlayers()) {
    // do your code
    }
    this would do it
     
  3. Or he can use
    Code (Text):
    Bukkit.getOnlinePlayers().forEach(
    (player) -> {
    //do stuff with player
    }));
     
  4. Alternatively, I just use
    Code (Text):
    Bukkit.broadcastMessage(//Your string here);
    cause I find it more readable. The only downside is that it does send to console, so if you don't want console to see the message, then yeah. Looping through players is your other option.