Search in sources :

Example 1 with Suggestion

use of com.mojang.brigadier.suggestion.Suggestion in project MinecraftForge by MinecraftForge.

the class ConsoleCommandCompleter method complete.

@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
    String buffer = line.line();
    boolean prefix;
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        buffer = '/' + buffer;
        prefix = false;
    } else {
        prefix = true;
    }
    final String input = buffer;
    // See NetHandlerPlayServer#processTabComplete
    StringReader stringReader = new StringReader(input);
    if (stringReader.canRead() && stringReader.peek() == '/')
        stringReader.skip();
    try {
        ParseResults<CommandSourceStack> results = this.server.getCommands().getDispatcher().parse(stringReader, this.server.createCommandSourceStack());
        Suggestions tabComplete = this.server.getCommands().getDispatcher().getCompletionSuggestions(results).get();
        for (Suggestion suggestion : tabComplete.getList()) {
            String completion = suggestion.getText();
            if (!completion.isEmpty()) {
                boolean hasPrefix = prefix || completion.charAt(0) != '/';
                Candidate candidate = new Candidate(hasPrefix ? completion : completion.substring(1));
                candidates.add(candidate);
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        logger.error("Failed to tab complete", e);
    }
}
Also used : Suggestions(com.mojang.brigadier.suggestion.Suggestions) Candidate(org.jline.reader.Candidate) Suggestion(com.mojang.brigadier.suggestion.Suggestion) StringReader(com.mojang.brigadier.StringReader) ExecutionException(java.util.concurrent.ExecutionException) CommandSourceStack(net.minecraft.commands.CommandSourceStack)

Aggregations

StringReader (com.mojang.brigadier.StringReader)1 Suggestion (com.mojang.brigadier.suggestion.Suggestion)1 Suggestions (com.mojang.brigadier.suggestion.Suggestions)1 ExecutionException (java.util.concurrent.ExecutionException)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 Candidate (org.jline.reader.Candidate)1