#3423: Remove empty servers from glist by default
This commit is contained in:
parent
f8e0bccdf0
commit
7651d4a249
@ -1,6 +1,7 @@
|
|||||||
package net.md_5.bungee.module.cmd.list;
|
package net.md_5.bungee.module.cmd.list;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.md_5.bungee.Util;
|
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.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
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.
|
* Command to list all players connected to the proxy.
|
||||||
*/
|
*/
|
||||||
public class CommandList extends Command
|
public class CommandList extends Command implements TabExecutor
|
||||||
{
|
{
|
||||||
|
|
||||||
public CommandList()
|
public CommandList()
|
||||||
@ -25,6 +27,8 @@ public class CommandList extends Command
|
|||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
|
boolean hideEmptyServers = ( args.length == 0 ) || !args[0].equalsIgnoreCase( "all" );
|
||||||
|
|
||||||
for ( ServerInfo server : ProxyServer.getInstance().getServers().values() )
|
for ( ServerInfo server : ProxyServer.getInstance().getServers().values() )
|
||||||
{
|
{
|
||||||
if ( !server.canAccess( sender ) )
|
if ( !server.canAccess( sender ) )
|
||||||
@ -32,16 +36,28 @@ public class CommandList extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collection<ProxiedPlayer> serverPlayers = server.getPlayers();
|
||||||
|
if ( hideEmptyServers && serverPlayers.isEmpty() )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> players = new ArrayList<>();
|
List<String> players = new ArrayList<>();
|
||||||
for ( ProxiedPlayer player : server.getPlayers() )
|
for ( ProxiedPlayer player : serverPlayers )
|
||||||
{
|
{
|
||||||
players.add( player.getDisplayName() );
|
players.add( player.getDisplayName() );
|
||||||
}
|
}
|
||||||
Collections.sort( players, String.CASE_INSENSITIVE_ORDER );
|
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() ) );
|
sender.sendMessage( ProxyServer.getInstance().getTranslation( "total_players", ProxyServer.getInstance().getOnlineCount() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
return ( args.length > 1 ) ? Collections.emptyList() : Collections.singletonList( "all" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user