mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Fixed arguments values not being forwarded
This commit is contained in:
parent
c3cfad22fc
commit
907b10604b
@ -23,7 +23,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class Arguments {
|
||||
|
||||
private final Map<String, Object> args = new HashMap<>();
|
||||
private Map<String, Object> args = new HashMap<>();
|
||||
|
||||
public boolean getBoolean(@NotNull String id) {
|
||||
return (boolean) getObject(id);
|
||||
@ -113,6 +113,10 @@ public class Arguments {
|
||||
this.args.put(id, value);
|
||||
}
|
||||
|
||||
protected void copy(Arguments arguments) {
|
||||
this.args = arguments.args;
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
this.args.clear();
|
||||
}
|
||||
|
@ -246,9 +246,13 @@ public class CommandDispatcher {
|
||||
private CommandSyntax findMostCorrectSyntax(List<CommandSyntax> validSyntaxes,
|
||||
Map<CommandSyntax, String[]> syntaxesValues,
|
||||
Arguments executorArgs, CommandResult result) {
|
||||
|
||||
Map<CommandSyntax, Arguments> argumentsValueMap = new HashMap<>();
|
||||
|
||||
CommandSyntax finalSyntax = null;
|
||||
int maxArguments = 0;
|
||||
for (CommandSyntax syntax : validSyntaxes) {
|
||||
Arguments syntaxValues = new Arguments();
|
||||
boolean fullyCorrect = true;
|
||||
|
||||
final Argument[] arguments = syntax.getArguments();
|
||||
@ -260,7 +264,7 @@ public class CommandDispatcher {
|
||||
final Object parsedValue = argument.parse(argValue);
|
||||
final int conditionResult = argument.getConditionResult(parsedValue);
|
||||
if (conditionResult == Argument.SUCCESS) {
|
||||
executorArgs.setArg(argument.getId(), parsedValue);
|
||||
syntaxValues.setArg(argument.getId(), parsedValue);
|
||||
} else {
|
||||
fullyCorrect = false;
|
||||
}
|
||||
@ -270,11 +274,15 @@ public class CommandDispatcher {
|
||||
if (fullyCorrect && argumentLength > maxArguments) {
|
||||
finalSyntax = syntax;
|
||||
maxArguments = argumentLength;
|
||||
} else {
|
||||
executorArgs.clear();
|
||||
argumentsValueMap.put(syntax, syntaxValues);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the arguments values
|
||||
if (finalSyntax != null) {
|
||||
executorArgs.copy(argumentsValueMap.get(finalSyntax));
|
||||
}
|
||||
|
||||
return finalSyntax;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user