mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Cleanup
This commit is contained in:
parent
60dc164cdc
commit
f3335d25f6
@ -29,7 +29,7 @@ public abstract class Argument<T> {
|
||||
|
||||
private T defaultValue;
|
||||
|
||||
public SuggestionCallback suggestionCallback;
|
||||
private SuggestionCallback suggestionCallback;
|
||||
|
||||
/**
|
||||
* Creates a new argument.
|
||||
|
@ -62,7 +62,8 @@ public class CommandParser {
|
||||
boolean useRemaining = false;
|
||||
// Check the validity of the arguments...
|
||||
for (int argIndex = 0; argIndex < commandArguments.length; argIndex++) {
|
||||
ArgumentResult argumentResult = validate(commandArguments, argIndex, inputArguments, inputIndex);
|
||||
final Argument<?> argument = commandArguments[argIndex];
|
||||
ArgumentResult argumentResult = validate(argument, commandArguments, argIndex, inputArguments, inputIndex);
|
||||
if (argumentResult == null) {
|
||||
break;
|
||||
}
|
||||
@ -170,10 +171,11 @@ public class CommandParser {
|
||||
ArgumentQueryResult maxArg = null;
|
||||
int maxArgIndex = 0;
|
||||
for (int argIndex = 0; argIndex < commandArguments.length; argIndex++) {
|
||||
ArgumentResult argumentResult = validate(commandArguments, argIndex, args, inputIndex);
|
||||
Argument<?> argument = commandArguments[argIndex];
|
||||
ArgumentResult argumentResult = validate(argument, commandArguments, argIndex, args, inputIndex);
|
||||
if (argumentResult == null) {
|
||||
argumentResult = new ArgumentResult();
|
||||
argumentResult.argument = commandArguments[argIndex];
|
||||
argumentResult.argument = argument;
|
||||
argumentResult.correct = false;
|
||||
argumentResult.inputIndex = inputIndex;
|
||||
argumentResult.rawArg = "";
|
||||
@ -182,7 +184,6 @@ public class CommandParser {
|
||||
// Update local var
|
||||
inputIndex = argumentResult.inputIndex;
|
||||
|
||||
final Argument<?> argument = argumentResult.argument;
|
||||
if (argumentResult.correct) {
|
||||
// Fill context
|
||||
context.setArg(argument.getId(), argumentResult.parsedValue, argumentResult.rawArg);
|
||||
@ -218,10 +219,9 @@ public class CommandParser {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ArgumentResult validate(@NotNull Argument<?>[] arguments, int argIndex,
|
||||
private static ArgumentResult validate(@NotNull Argument<?> argument,
|
||||
@NotNull Argument<?>[] arguments, int argIndex,
|
||||
@NotNull String[] inputArguments, int inputIndex) {
|
||||
final Argument<?> argument = arguments[argIndex];
|
||||
|
||||
final boolean end = inputIndex == inputArguments.length;
|
||||
if (end) // Stop if there is no input to analyze left
|
||||
return null;
|
||||
|
@ -49,7 +49,7 @@ public class TabCompleteListener {
|
||||
|
||||
final Argument<?> argument = queryResult.argument;
|
||||
|
||||
final SuggestionCallback suggestionCallback = argument.suggestionCallback;
|
||||
final SuggestionCallback suggestionCallback = argument.getSuggestionCallback();
|
||||
if (suggestionCallback != null) {
|
||||
final String input = queryResult.input;
|
||||
final int inputLength = input.length();
|
||||
|
@ -1,13 +1,10 @@
|
||||
package demo.commands;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandContext;
|
||||
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
|
||||
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.Integer;
|
||||
import static net.minestom.server.command.builder.arguments.ArgumentType.*;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
@ -16,15 +13,13 @@ public class TestCommand extends Command {
|
||||
super("testcmd");
|
||||
setDefaultExecutor(this::usage);
|
||||
|
||||
addSubcommand(new Sub());
|
||||
|
||||
var test1 = String("msg").setSuggestionCallback((sender, context, suggestion) -> {
|
||||
var test1 = Word("msg").setSuggestionCallback((sender, context, suggestion) -> {
|
||||
suggestion.addEntry(new SuggestionEntry("test"));
|
||||
});
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
System.out.println("input: " + context.get("msg"));
|
||||
}, test1);
|
||||
System.out.println("executed");
|
||||
}, Group("test", test1));
|
||||
|
||||
}
|
||||
|
||||
@ -32,28 +27,4 @@ public class TestCommand extends Command {
|
||||
sender.sendMessage("Incorrect usage");
|
||||
}
|
||||
|
||||
private static class Sub extends Command {
|
||||
|
||||
public Sub() {
|
||||
super("sub");
|
||||
|
||||
setDefaultExecutor((sender, context) -> sender.sendMessage("default sub"));
|
||||
|
||||
var test1 = Word("msg").setSuggestionCallback((sender, context, suggestion) -> {
|
||||
final String input = suggestion.getInput();
|
||||
if (!input.isEmpty()) {
|
||||
int num = Integer.valueOf(input) * 2;
|
||||
suggestion.addEntry(new SuggestionEntry(String.valueOf(num), ColoredText.of(ChatColor.RED, "Hover")));
|
||||
System.out.println("test: " + context.get("msg3"));
|
||||
}
|
||||
});
|
||||
|
||||
var test3 = Integer("msg3");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
System.out.println("input: " + context.getInput());
|
||||
}, test3, test1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user