Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.hugog.minecraft</groupId>
<artifactId>dev-command</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean hasValidArgs() {
.toArray().length;

if (args.length < mandatoryArgumentsCount) {
return false;
return false;
}

for (CommandArgument argument : commandData.getArguments()) {
Expand All @@ -79,7 +79,7 @@ public boolean hasValidArgs() {
// We can safely assume that the argument is present because of the check above
String argumentAtPosition = args[argumentPosition];
ICommandArgumentParser<?> expectedCommandArgument = new ArgumentParserFactory(argumentAtPosition)
.generate(argument.validator());
.generate(argument.validator());

if (!expectedCommandArgument.isValid()) {
return false;
Expand Down Expand Up @@ -136,10 +136,14 @@ public boolean performAutoValidation(IAutoValidationConfiguration configuration)
}
if (commandData.getAutoValidationData().validateArguments() && commandData.getArguments() != null) {
if (!hasValidArgs()) {
CommandArgument firstInvalidArgument = Arrays.stream(getInvalidArguments()).findFirst()
.orElseThrow(() -> new InvalidArgumentsException("Unable to find the first invalid argument. This should never happen."));
getCommandSender().sendMessage(MessageFormat.format(configuration.getInvalidArgumentsMessage(this),
firstInvalidArgument.name(), String.valueOf(firstInvalidArgument.position() + 1)));
if (getInvalidArguments().length == 0) { // No invalid arguments but still invalid, this means not enough arguments were provided
getCommandSender().sendMessage(MessageFormat.format(configuration.getInvalidArgumentsMessage(this), "Missing Arguments", "N/A"));
} else { // Invalid arguments found
CommandArgument firstInvalidArgument = Arrays.stream(getInvalidArguments()).findFirst()
.orElseThrow(() -> new InvalidArgumentsException("No invalid arguments found, but hasValidArgs returned false. This should not happen."));
getCommandSender().sendMessage(MessageFormat.format(configuration.getInvalidArgumentsMessage(this),
firstInvalidArgument.name(), String.valueOf(firstInvalidArgument.position() + 1)));
}
return false;
}
}
Expand All @@ -160,7 +164,9 @@ public <T> T getDependency(Class<T> dependencyClass) throws InvalidDependencyExc
@Override
public CommandArgument[] getInvalidArguments() {
return Arrays.stream(commandData.getArguments())
.filter(commandArgument -> !getArgumentParser(commandArgument.position()).isValid())
.filter(commandArgument -> !getOptionalArgumentParser(commandArgument.position())
.map(ICommandArgumentParser::isValid)
.orElse(true))
.toArray(CommandArgument[]::new);
}

Expand Down