Add tab completion for find command. Also change api a bit.

This commit is contained in:
md_5 2013-09-15 07:37:20 +10:00
parent d67acd7bc9
commit e998faeec1
4 changed files with 42 additions and 5 deletions

View File

@ -145,7 +145,10 @@ public class PluginManager
command.execute( sender, args );
} else if ( command instanceof TabExecutor )
{
tabResults.addAll( ( (TabExecutor) command ).onTabComplete( sender, args ) );
for ( String s : ( (TabExecutor) command ).onTabComplete( sender, args ) )
{
tabResults.add( s );
}
}
} catch ( Exception ex )
{

View File

@ -2,10 +2,9 @@ package net.md_5.bungee.api.plugin;
import net.md_5.bungee.api.CommandSender;
import java.util.List;
public interface TabExecutor
{
public List<String> onTabComplete(CommandSender sender, String[] args);
public Iterable<String> onTabComplete(CommandSender sender, String[] args);
}

View File

@ -4,9 +4,8 @@ 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.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
public class CommandFind extends Command
public class CommandFind extends PlayerCommand
{
public CommandFind()

View File

@ -0,0 +1,36 @@
package net.md_5.bungee.command;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
public abstract class PlayerCommand extends Command implements TabExecutor
{
public PlayerCommand(String name)
{
super( name );
}
public PlayerCommand(String name, String permission, String... aliases)
{
super( name, permission, aliases );
}
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args)
{
return Iterables.transform( ProxyServer.getInstance().getPlayers(), new Function<ProxiedPlayer, String>()
{
@Override
public String apply(ProxiedPlayer input)
{
return input.getDisplayName();
}
} );
}
}