changes to tab completion

* PacketCBTabComplete: options for completion should be seperated by
NUL
 * PluginManager: append an empty argument to arguments if command ends
with a whitespace (this will match all suggestions)
 * PlayerCommand: suggest only matching players instead of all players
This commit is contained in:
zaiyers
2013-09-28 16:50:04 +02:00
committed by md_5
parent 891dc87b16
commit dd06937a3b
3 changed files with 28 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
package net.md_5.bungee.command;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
@@ -24,12 +25,20 @@ public abstract class PlayerCommand extends Command implements TabExecutor
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args)
{
return Iterables.transform( ProxyServer.getInstance().getPlayers(), new Function<ProxiedPlayer, String>()
final String lastArg = ( args.length > 0 ) ? args[args.length - 1] : "";
return Iterables.transform( Iterables.filter( ProxyServer.getInstance().getPlayers(), new Predicate<ProxiedPlayer>()
{
@Override
public String apply(ProxiedPlayer input)
public boolean apply(ProxiedPlayer player)
{
return input.getDisplayName();
return player.getName().startsWith( lastArg );
}
} ), new Function<ProxiedPlayer, String>()
{
@Override
public String apply(ProxiedPlayer player)
{
return player.getName();
}
} );
}