package net.md_5.bungee.command;

import java.util.Collection;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

/**
 * Command to list all players connected to the proxy.
 */
public class CommandList extends Command
{

    public CommandList()
    {
        super( "glist", "bungeecord.command.list" );
    }

    @Override
    public void execute(CommandSender sender, String[] args)
    {
        StringBuilder users = new StringBuilder();
        Collection<ProxiedPlayer> connections = ProxyServer.getInstance().getPlayers();

        if ( connections.isEmpty() )
        {
            sender.sendMessage( ChatColor.BLUE + "Currently no players online." );
            return;
        }

        for ( ProxiedPlayer player : connections )
        {
            users.append( player.getDisplayName() );
            users.append( ", " );
            users.append( ChatColor.RESET );
        }

        users.setLength( users.length() - 2 );
        sender.sendMessage( ChatColor.BLUE + "Currently online across all servers (" + connections.size() + "): " + ChatColor.RESET + users );
    }
}

@@ -44,26 +44,77 @@
 va.util.
-Collection
+ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List
 ;%0Aimport
@@ -223,24 +223,70 @@
 roxyServer;%0A
+import net.md_5.bungee.api.config.ServerInfo;%0A
 import net.m
@@ -661,270 +661,437 @@
     
-StringBuilder users = new StringBuilder();%0A        Collection%3CProxiedPlayer%3E connections = ProxyServer.getInstance().getPlayers();%0A%0A        if ( connections.isEmpty() )%0A        %7B%0A            sender.sendMessage( ChatColor.BLUE + %22Currently no players online.
+for ( ServerInfo server : ProxyServer.getInstance().getServers().values() )%0A        %7B%0A            Collection%3CProxiedPlayer%3E serverPlayers = server.getPlayers();%0A%0A            StringBuilder message = new StringBuilder();%0A            message.append( %22%5B%22 );%0A            message.append( server.getName() );%0A            message.append( %22%5D (%22 );%0A            message.append( serverPlayers.size() );%0A            message.append( %22): 
 %22 );%0A
+%0A
     
@@ -1102,27 +1102,54 @@
     
-return;%0A    
+List%3CString%3E players = new ArrayList%3C%3E();%0A
     
-%7D%0A%0A
     
@@ -1185,22 +1185,28 @@
 r : 
-connections )%0A
+serverPlayers )%0A    
     
@@ -1223,27 +1223,30 @@
         
-us
+    play
 ers.a
-ppen
+d
 d( playe
@@ -1283,94 +1283,261 @@
     
-users.append( %22, %22 );%0A            users.append( ChatColor.RESET );%0A        %7D%0A%0A
+%7D%0A%0A            if ( !players.isEmpty() )%0A            %7B%0A                for ( String player : players )%0A                %7B%0A                    message.append( player ).append( ChatColor.RESET ).append( %22, %22 );%0A                %7D%0A            %7D%0A%0A    
         
 user
@@ -1536,30 +1536,57 @@
     
-u
 se
-rs.setLength( users
+nder.sendMessage( message.substring( 0, message
 .len
@@ -1594,20 +1594,33 @@
 th() - 2
+ )
  );%0A
+        %7D%0A%0A
         
@@ -1643,119 +1643,80 @@
 ge( 
-ChatColor.BLUE + %22Currently online across all servers (%22 + connections.size() + %22): %22 + ChatColor.RESET + users
+%22Total players online: %22 + ProxyServer.getInstance().getPlayers().size()
  );%0A

Rewrite list command for per server breakdown, and alphabetizing.