mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 12:46:05 +01:00
#3614: Make glist command output hover and clickable
This commit is contained in:
parent
86e6fdf8a2
commit
0851e39197
@ -7,6 +7,11 @@ import java.util.List;
|
||||
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.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
@ -27,6 +32,7 @@ public class CommandList extends Command implements TabExecutor
|
||||
public void execute(CommandSender sender, String[] args)
|
||||
{
|
||||
boolean hideEmptyServers = ( args.length == 0 ) || !args[0].equalsIgnoreCase( "all" );
|
||||
boolean moduleLoaded = ProxyServer.getInstance().getPluginManager().getPlugin( "cmd_server" ) != null;
|
||||
|
||||
for ( ServerInfo server : ProxyServer.getInstance().getServers().values() )
|
||||
{
|
||||
@ -48,7 +54,18 @@ public class CommandList extends Command implements TabExecutor
|
||||
}
|
||||
Collections.sort( players, String.CASE_INSENSITIVE_ORDER );
|
||||
|
||||
sender.sendMessage( ProxyServer.getInstance().getTranslation( "command_list", server.getName(), players.size(), String.join( ChatColor.RESET + ", ", players ) ) );
|
||||
BaseComponent baseComponent = new ComponentBuilder().appendLegacy( ProxyServer.getInstance().getTranslation( "command_list", server.getName(), players.size(), String.join( ChatColor.RESET + ", ", players ) ) ).build();
|
||||
|
||||
if ( moduleLoaded )
|
||||
{
|
||||
baseComponent.setHoverEvent( new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
new Text( new ComponentBuilder().appendLegacy( ProxyServer.getInstance().getTranslation( "click_to_connect" ) ).create() ) )
|
||||
);
|
||||
baseComponent.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/server " + server.getName() ) );
|
||||
}
|
||||
|
||||
sender.sendMessage( baseComponent );
|
||||
}
|
||||
|
||||
sender.sendMessage( ProxyServer.getInstance().getTranslation( "total_players", ProxyServer.getInstance().getOnlineCount() ) );
|
||||
|
Loading…
Reference in New Issue
Block a user