mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-24 01:27:38 +01:00
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:
parent
891dc87b16
commit
dd06937a3b
@ -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 )
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user