#3425: Make ip command output clickable to copy ip

This commit is contained in:
Outfluencer 2023-01-28 11:19:45 +11:00 committed by md_5
parent 7651d4a249
commit 71ac9b34fa
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -1,7 +1,10 @@
package net.md_5.bungee.command; package net.md_5.bungee.command;
import java.util.Collections;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class CommandIP extends PlayerCommand public class CommandIP extends PlayerCommand
@ -26,7 +29,17 @@ public class CommandIP extends PlayerCommand
sender.sendMessage( ProxyServer.getInstance().getTranslation( "user_not_online" ) ); sender.sendMessage( ProxyServer.getInstance().getTranslation( "user_not_online" ) );
} else } else
{ {
sender.sendMessage( ProxyServer.getInstance().getTranslation( "command_ip", args[0], user.getSocketAddress() ) ); sender.sendMessage( new ComponentBuilder()
.appendLegacy( ProxyServer.getInstance().getTranslation( "command_ip", user.getName(), user.getSocketAddress() ) )
.event( new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, user.getSocketAddress().toString() ) )
.create()
);
} }
} }
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args)
{
return ( args.length == 1 ) ? super.onTabComplete( sender, args ) : Collections.emptyList();
}
} }