diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 43c8862f..2b6c6995 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -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 ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java b/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java new file mode 100644 index 00000000..bd52d880 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java @@ -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 candidates) + { + List 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 ); + } +}