Add console command completion

This commit is contained in:
md_5 2018-01-07 22:46:52 +11:00
parent dda0638869
commit 3508bf6c85
2 changed files with 27 additions and 0 deletions

View File

@ -71,6 +71,7 @@ import net.md_5.bungee.command.CommandEnd;
import net.md_5.bungee.command.CommandIP;
import net.md_5.bungee.command.CommandPerms;
import net.md_5.bungee.command.CommandReload;
import net.md_5.bungee.command.ConsoleCommandCompleter;
import net.md_5.bungee.command.ConsoleCommandSender;
import net.md_5.bungee.compress.CompressFactory;
import net.md_5.bungee.conf.Configuration;
@ -204,6 +205,7 @@ public class BungeeCord extends ProxyServer
AnsiConsole.systemInstall();
consoleReader = new ConsoleReader();
consoleReader.setExpandEvents( false );
consoleReader.addCompleter( new ConsoleCommandCompleter( this ) );
logger = new BungeeLogger( "BungeeCord", "proxy.log", consoleReader );
System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) );

View File

@ -0,0 +1,25 @@
package net.md_5.bungee.command;
import java.util.ArrayList;
import java.util.List;
import jline.console.completer.Completer;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
@RequiredArgsConstructor
public class ConsoleCommandCompleter implements Completer
{
private final ProxyServer proxy;
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates)
{
List<String> suggestions = new ArrayList<>();
proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions );
candidates.addAll( suggestions );
int lastSpace = buffer.lastIndexOf( ' ' );
return ( lastSpace == -1 ) ? cursor - buffer.length() : cursor - ( buffer.length() - lastSpace - 1 );
}
}