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);
}
}
Aggregations