Add tab completion to /send (Fixes #853)

This commit is contained in:
Thinkofdeath 2014-02-01 11:21:59 +00:00
parent 19b4c09a16
commit edce7f7c3d

View File

@ -1,13 +1,19 @@
package net.md_5.bungee.module.cmd.send; package net.md_5.bungee.module.cmd.send;
import com.google.common.collect.ImmutableSet;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
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.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;
public class CommandSend extends Command import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class CommandSend extends Command implements TabExecutor
{ {
public CommandSend() public CommandSend()
@ -69,4 +75,39 @@ public class CommandSend extends Command
player.sendMessage( ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName() ); player.sendMessage( ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName() );
} }
} }
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args)
{
if ( args.length > 2 || args.length == 0 )
{
return ImmutableSet.of();
}
Set<String> matches = new HashSet<>();
if ( args.length == 1 )
{
String search = args[0].toLowerCase();
for ( ProxiedPlayer player : ProxyServer.getInstance().getPlayers() )
{
if ( player.getName().toLowerCase().startsWith( search ) )
{
matches.add( player.getName() );
}
}
if ( "all".startsWith( search ) ) matches.add( "all" );
if ( "current".startsWith( search ) ) matches.add( "current" );
} else
{
String search = args[1].toLowerCase();
for ( String server : ProxyServer.getInstance().getServers().keySet() )
{
if ( server.toLowerCase().startsWith( search ) )
{
matches.add( server );
}
}
}
return matches;
}
} }