1.8.8 How do I get all player online name in one message?

Discussion in 'Spigot Plugin Development' started by pleumz, Oct 18, 2020 at 4:35 PM.

  1. HI so I'm trying to make this list command that will show all player online like this
    upload_2020-10-18_22-31-11.png
    so I try this

    Code (Text):

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        for(Player p : Bukkit.getOnlinePlayers()) {
            sender.sendMessage(Color("&7(" + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers() + ") &f" + p.getName()));
        }
        return false;
    }
     
    then I run command then it just give me this
    upload_2020-10-18_22-34-16.png
    can anyone help?
     

    Attached Files:

  2. You need to store the player names as a list or something. Then you need to add a comma between each and remove the last comma. Send the message to the sender after you have the final String.
     
  3. Code (Java):
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("(%d/%d) ", Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()));
    Bukkit.getOnlinePlayers().forEach(player -> sb.append(String.format("§c%s§7, ", player.getName())));
    player.sendMessage(sb.toString().substring(0, sb.toString().length() - 2));
    That would be enough. I haven't tested through
     
    #3 DragoFantasma_, Oct 18, 2020 at 4:44 PM
    Last edited: Oct 18, 2020 at 5:01 PM
    • Like Like x 2
  4. ty but I kinda did one on my own bu ty for helping anyways :D