Javadoc and some API changes

This commit is contained in:
2022-08-11 01:32:37 +02:00
parent b6fc3c2b61
commit 99a07a2ba6
13 changed files with 298 additions and 188 deletions

View File

@@ -1,25 +1,22 @@
package fr.pandacube.lib.cli.commands;
import java.util.Arrays;
import java.util.List;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.commands.BrigadierCommand;
import fr.pandacube.lib.commands.SuggestionsSupplier;
import java.util.function.Function;
import java.util.function.Predicate;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.ParsedCommandNode;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.commands.BrigadierCommand;
import fr.pandacube.lib.commands.BrigadierSuggestionsUtil;
import fr.pandacube.lib.commands.SuggestionsSupplier;
import fr.pandacube.lib.util.Log;
/**
* Abstract class that holds the logic of a specific command to be registered in {@link CLIBrigadierDispatcher}.
*/
public abstract class CLIBrigadierCommand extends BrigadierCommand<Object> {
/**
* Instanciate this command instance.
*/
public CLIBrigadierCommand() {
LiteralCommandNode<Object> commandNode = buildCommand().build();
postBuildCommand(commandNode);
@@ -28,7 +25,7 @@ public abstract class CLIBrigadierCommand extends BrigadierCommand<Object> {
aliases = new String[0];
CLIBrigadierDispatcher.instance.register(commandNode);
for (String alias : aliases) {
CLIBrigadierDispatcher.instance.register(literal(alias)
@@ -66,6 +63,11 @@ public abstract class CLIBrigadierCommand extends BrigadierCommand<Object> {
/**
* Wraps the provided {@link SuggestionsSupplier} into a Brigadiers {@link SuggestionProvider}.
* @param suggestions the suggestions to wrap.
* @return a {@link SuggestionProvider} generating the suggestions from the provided {@link SuggestionsSupplier}.
*/
protected SuggestionProvider<Object> wrapSuggestions(SuggestionsSupplier<Object> suggestions) {
return wrapSuggestions(suggestions, Function.identity());
}

View File

@@ -11,14 +11,25 @@ import fr.pandacube.lib.util.Log;
import jline.console.completer.Completer;
import net.kyori.adventure.text.ComponentLike;
/**
* Implementation of {@link BrigadierDispatcher} that integrates the commands into the JLine CLI interface.
*/
public class CLIBrigadierDispatcher extends BrigadierDispatcher<Object> implements Completer {
/**
* The instance of {@link CLIBrigadierDispatcher}.
*/
public static final CLIBrigadierDispatcher instance = new CLIBrigadierDispatcher();
private static final Object sender = new Object();
/**
* Executes the provided command.
* @param commandWithoutSlash the command, without the eventual slash at the begining.
* @return the value returned by the executed command.
*/
public int execute(String commandWithoutSlash) {
return execute(sender, commandWithoutSlash);
}
@@ -37,7 +48,12 @@ public class CLIBrigadierDispatcher extends BrigadierDispatcher<Object> implemen
return completeResult.getRange().getStart();
}
/**
* Gets the suggestions for the currently being typed command.
* @param buffer the command that is being typed.
* @return the suggestions for the currently being typed command.
*/
public Suggestions getSuggestions(String buffer) {
return getSuggestions(sender, buffer);
}