From c05934580219de1d77d325750bb046469723afd7 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 16 Mar 2013 12:14:15 +1100 Subject: [PATCH] Add send command, closes issue #197 --- .../main/java/net/md_5/bungee/BungeeCord.java | 3 +- .../net/md_5/bungee/command/CommandSend.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/command/CommandSend.java diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index f97d9f3d..7ec09572 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -92,7 +92,7 @@ public class BungeeCord extends ProxyServer * Plugin manager. */ @Getter - public final PluginManager pluginManager = new PluginManager(this); + public final PluginManager pluginManager = new PluginManager( this ); @Getter @Setter private ReconnectHandler reconnectHandler; @@ -113,6 +113,7 @@ public class BungeeCord extends ProxyServer getPluginManager().registerCommand( new CommandAlert() ); getPluginManager().registerCommand( new CommandBungee() ); getPluginManager().registerCommand( new CommandPerms() ); + getPluginManager().registerCommand( new CommandSend() ); registerChannel( "BungeeCord" ); } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandSend.java b/proxy/src/main/java/net/md_5/bungee/command/CommandSend.java new file mode 100644 index 00000000..d772f686 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandSend.java @@ -0,0 +1,69 @@ +package net.md_5.bungee.command; + +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.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; + +public class CommandSend extends Command +{ + + public CommandSend() + { + super( "send", "bungeecord.command.send" ); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + if ( args.length != 2 ) + { + sender.sendMessage( ChatColor.RED + "Not enough arguments, usage: /send " ); + return; + } + ServerInfo target = ProxyServer.getInstance().getServerInfo( args[1] ); + if ( target == null ) + { + sender.sendMessage( ChatColor.RED + "Target server does not exist" ); + } + + if ( args[0].equalsIgnoreCase( "all" ) ) + { + for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) + { + summon( p, target, sender ); + } + } else if ( args[0].equalsIgnoreCase( "current" ) ) + { + if ( !( sender instanceof ProxiedPlayer ) ) + { + sender.sendMessage( ChatColor.RED + "Only in game players can use this command" ); + } + ProxiedPlayer player = (ProxiedPlayer) sender; + for ( ProxiedPlayer p : player.getServer().getInfo().getPlayers() ) + { + summon( p, target, sender ); + } + } else + { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer( args[0] ); + if ( player == null ) + { + sender.sendMessage( ChatColor.RED + "That player is not online" ); + } + summon( player, target, sender ); + } + sender.sendMessage( ChatColor.GREEN + "Successfully summoned player(s)" ); + } + + private void summon(ProxiedPlayer player, ServerInfo target, CommandSender sender) + { + if ( player.getServer().getInfo() != target ) + { + player.connect( target ); + player.sendMessage( ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName() ); + } + } +}