From 9c95d4ba43ba84d10e8bb7d7c92d7e6c5f161ed2 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Sun, 2 Jan 2022 10:13:48 +1100 Subject: [PATCH] #3226: Add console command name tab completion --- .../command/ConsoleCommandCompleter.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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 index bd52d880..3e5ca394 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java +++ b/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java @@ -2,6 +2,9 @@ package net.md_5.bungee.command; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; import jline.console.completer.Completer; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ProxyServer; @@ -15,11 +18,21 @@ public class ConsoleCommandCompleter implements Completer @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( ' ' ); + if ( lastSpace == -1 ) + { + String lowerCase = buffer.toLowerCase( Locale.ROOT ); + candidates.addAll( proxy.getPluginManager().getCommands().stream() + .map( Map.Entry::getKey ) + .filter( (name) -> name.toLowerCase( Locale.ROOT ).startsWith( lowerCase ) ) + .collect( Collectors.toList() ) ); + } else + { + List suggestions = new ArrayList<>(); + proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions ); + candidates.addAll( suggestions ); + } + return ( lastSpace == -1 ) ? cursor - buffer.length() : cursor - ( buffer.length() - lastSpace - 1 ); } }