package net.md_5.bungee.module.cmd.send;

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 <player|all|current> <target>" );
            return;
        }
        ServerInfo target = ProxyServer.getInstance().getServerInfo( args[1] );
        if ( target == null )
        {
            sender.sendMessage( ProxyServer.getInstance().getTranslation( "no_server" ) );
            return;
        }

        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" );
                return;
            }
            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" );
                return;
            }
            summon( player, target, sender );
        }
        sender.sendMessage( ChatColor.GREEN + "Successfully summoned player(s)" );
    }

    private void summon(ProxiedPlayer player, ServerInfo target, CommandSender sender)
    {
        if ( player.getServer() != null && !player.getServer().getInfo().equals( target ) )
        {
            player.connect( target );
            player.sendMessage( ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName() );
        }
    }
}

@@ -35,16 +35,63 @@
 .send;%0A%0A
+import com.google.common.collect.ImmutableSet;%0A
 import n
@@ -343,16 +343,137 @@
 Command;
+%0Aimport net.md_5.bungee.api.plugin.TabExecutor;%0A%0Aimport java.util.Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0Apublic
@@ -506,16 +506,39 @@
  Command
+ implements TabExecutor
 %0A%7B%0A%0A    
@@ -2619,11 +2619,1151 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public Iterable%3CString%3E onTabComplete(CommandSender sender, String%5B%5D args)%0A    %7B%0A        if ( args.length %3E 2 %7C%7C args.length == 0 )%0A        %7B%0A            return ImmutableSet.of();%0A        %7D%0A%0A        Set%3CString%3E matches = new HashSet%3C%3E();%0A        if ( args.length == 1 )%0A        %7B%0A            String search = args%5B0%5D.toLowerCase();%0A            for ( ProxiedPlayer player : ProxyServer.getInstance().getPlayers() )%0A            %7B%0A                if ( player.getName().toLowerCase().startsWith( search ) )%0A                %7B%0A                    matches.add( player.getName() );%0A                %7D%0A            %7D%0A            if ( %22all%22.startsWith( search ) ) matches.add( %22all%22 );%0A            if ( %22current%22.startsWith( search ) ) matches.add( %22current%22 );%0A        %7D else%0A        %7B%0A            String search = args%5B1%5D.toLowerCase();%0A            for ( String server : ProxyServer.getInstance().getServers().keySet() )%0A            %7B%0A                if ( server.toLowerCase().startsWith( search ) )%0A                %7B%0A                    matches.add( server );%0A                %7D%0A            %7D%0A        %7D%0A        return matches;%0A    %7D
 %0A%7D%0A

Add tab completion to /send (Fixes #853)