From e998faeec1d00cd214617f035b025c1b3dadfeee Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 15 Sep 2013 07:37:20 +1000 Subject: [PATCH] Add tab completion for find command. Also change api a bit. --- .../md_5/bungee/api/plugin/PluginManager.java | 5 ++- .../md_5/bungee/api/plugin/TabExecutor.java | 3 +- .../net/md_5/bungee/command/CommandFind.java | 3 +- .../md_5/bungee/command/PlayerCommand.java | 36 +++++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 93f5c41d..e5ec1ce8 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -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 ) { diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/TabExecutor.java b/api/src/main/java/net/md_5/bungee/api/plugin/TabExecutor.java index 2510573e..cdf5174b 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/TabExecutor.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/TabExecutor.java @@ -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 onTabComplete(CommandSender sender, String[] args); + public Iterable onTabComplete(CommandSender sender, String[] args); } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandFind.java b/proxy/src/main/java/net/md_5/bungee/command/CommandFind.java index 023dae18..7da6c13c 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandFind.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandFind.java @@ -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() diff --git a/proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java b/proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java new file mode 100644 index 00000000..1b0087b0 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java @@ -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 onTabComplete(CommandSender sender, String[] args) + { + return Iterables.transform( ProxyServer.getInstance().getPlayers(), new Function() + { + @Override + public String apply(ProxiedPlayer input) + { + return input.getDisplayName(); + } + } ); + } +}