Add console command completion
This commit is contained in:
parent
dda0638869
commit
3508bf6c85
@ -71,6 +71,7 @@ import net.md_5.bungee.command.CommandEnd;
|
|||||||
import net.md_5.bungee.command.CommandIP;
|
import net.md_5.bungee.command.CommandIP;
|
||||||
import net.md_5.bungee.command.CommandPerms;
|
import net.md_5.bungee.command.CommandPerms;
|
||||||
import net.md_5.bungee.command.CommandReload;
|
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.command.ConsoleCommandSender;
|
||||||
import net.md_5.bungee.compress.CompressFactory;
|
import net.md_5.bungee.compress.CompressFactory;
|
||||||
import net.md_5.bungee.conf.Configuration;
|
import net.md_5.bungee.conf.Configuration;
|
||||||
@ -204,6 +205,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
AnsiConsole.systemInstall();
|
AnsiConsole.systemInstall();
|
||||||
consoleReader = new ConsoleReader();
|
consoleReader = new ConsoleReader();
|
||||||
consoleReader.setExpandEvents( false );
|
consoleReader.setExpandEvents( false );
|
||||||
|
consoleReader.addCompleter( new ConsoleCommandCompleter( this ) );
|
||||||
|
|
||||||
logger = new BungeeLogger( "BungeeCord", "proxy.log", consoleReader );
|
logger = new BungeeLogger( "BungeeCord", "proxy.log", consoleReader );
|
||||||
System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) );
|
System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) );
|
||||||
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user