diff --git a/module/cmd-list/src/main/java/net/md_5/bungee/module/cmd/list/CommandList.java b/module/cmd-list/src/main/java/net/md_5/bungee/module/cmd/list/CommandList.java index c2227110..c4ac9173 100644 --- a/module/cmd-list/src/main/java/net/md_5/bungee/module/cmd/list/CommandList.java +++ b/module/cmd-list/src/main/java/net/md_5/bungee/module/cmd/list/CommandList.java @@ -1,6 +1,7 @@ package net.md_5.bungee.module.cmd.list; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import net.md_5.bungee.Util; @@ -10,11 +11,12 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.api.plugin.TabExecutor; /** * Command to list all players connected to the proxy. */ -public class CommandList extends Command +public class CommandList extends Command implements TabExecutor { public CommandList() @@ -25,6 +27,8 @@ public class CommandList extends Command @Override public void execute(CommandSender sender, String[] args) { + boolean hideEmptyServers = ( args.length == 0 ) || !args[0].equalsIgnoreCase( "all" ); + for ( ServerInfo server : ProxyServer.getInstance().getServers().values() ) { if ( !server.canAccess( sender ) ) @@ -32,16 +36,28 @@ public class CommandList extends Command continue; } + Collection serverPlayers = server.getPlayers(); + if ( hideEmptyServers && serverPlayers.isEmpty() ) + { + continue; + } + List players = new ArrayList<>(); - for ( ProxiedPlayer player : server.getPlayers() ) + for ( ProxiedPlayer player : serverPlayers ) { players.add( player.getDisplayName() ); } Collections.sort( players, String.CASE_INSENSITIVE_ORDER ); - sender.sendMessage( ProxyServer.getInstance().getTranslation( "command_list", server.getName(), server.getPlayers().size(), Util.format( players, ChatColor.RESET + ", " ) ) ); + sender.sendMessage( ProxyServer.getInstance().getTranslation( "command_list", server.getName(), players.size(), Util.format( players, ChatColor.RESET + ", " ) ) ); } sender.sendMessage( ProxyServer.getInstance().getTranslation( "total_players", ProxyServer.getInstance().getOnlineCount() ) ); } + + @Override + public Iterable onTabComplete(CommandSender sender, String[] args) + { + return ( args.length > 1 ) ? Collections.emptyList() : Collections.singletonList( "all" ); + } }