From dd06937a3b6b4bdd8832e0d8e65389f57594a9ca Mon Sep 17 00:00:00 2001 From: zaiyers Date: Sat, 28 Sep 2013 16:50:04 +0200 Subject: [PATCH] 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 --- .../net/md_5/bungee/api/plugin/PluginManager.java | 13 ++++++++++++- .../protocol/packet/PacketCBTabComplete.java | 13 ++++--------- .../net/md_5/bungee/command/PlayerCommand.java | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 13 deletions(-) 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 e5ec1ce8e..bdcf2d254 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 @@ -137,7 +137,18 @@ public class PluginManager return true; } - String[] args = Arrays.copyOfRange( split, 1, split.length ); + String[] args; + + // add empty argument for tab completion + if ( commandLine.endsWith( " " ) ) + { + args = Arrays.copyOfRange( split, 1, split.length + 1 ); + args[ split.length - 1] = ""; + } else + { + args = Arrays.copyOfRange( split, 1, split.length ); + } + try { if ( tabResults == null ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java index 0e2dcaa8a..01df2ff42 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java @@ -34,18 +34,13 @@ public class PacketCBTabComplete extends DefinedPacket @Override public void write(ByteBuf buf) { - String tab = ""; + StringBuilder tab = new StringBuilder(); for ( String alternative : commands ) { - if ( tab.isEmpty() ) - { - tab = alternative + " "; - } else - { - tab += "\0" + alternative + " "; - } + tab.append( alternative ); + tab.append( "\00" ); } - writeString( tab, buf ); + writeString( tab.substring( 0, tab.length() - 1 ), buf ); } @Override 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 index 1b0087b00..a0c9164e8 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java +++ b/proxy/src/main/java/net/md_5/bungee/command/PlayerCommand.java @@ -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 onTabComplete(CommandSender sender, String[] args) { - return Iterables.transform( ProxyServer.getInstance().getPlayers(), new Function() + final String lastArg = ( args.length > 0 ) ? args[args.length - 1] : ""; + return Iterables.transform( Iterables.filter( ProxyServer.getInstance().getPlayers(), new Predicate() { @Override - public String apply(ProxiedPlayer input) + public boolean apply(ProxiedPlayer player) { - return input.getDisplayName(); + return player.getName().startsWith( lastArg ); + } + } ), new Function() + { + @Override + public String apply(ProxiedPlayer player) + { + return player.getName(); } } ); }