mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 12:46:05 +01:00
#3226: Add console command name tab completion
This commit is contained in:
parent
6cbd7404f4
commit
9c95d4ba43
@ -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<CharSequence> candidates)
|
||||
{
|
||||
List<String> 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<String> suggestions = new ArrayList<>();
|
||||
proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, suggestions );
|
||||
candidates.addAll( suggestions );
|
||||
}
|
||||
|
||||
return ( lastSpace == -1 ) ? cursor - buffer.length() : cursor - ( buffer.length() - lastSpace - 1 );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user