diff --git a/pom.xml b/pom.xml index 074c337..c7b70bc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.hugog.minecraft dev-command - 0.0.9 + 0.0.10 11 diff --git a/src/main/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommand.java b/src/main/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommand.java index 784b699..7f9aa0f 100644 --- a/src/main/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommand.java +++ b/src/main/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommand.java @@ -64,7 +64,7 @@ public boolean hasValidArgs() { .toArray().length; if (args.length < mandatoryArgumentsCount) { - return false; + return false; } for (CommandArgument argument : commandData.getArguments()) { @@ -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; @@ -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; } } @@ -160,7 +164,9 @@ public T getDependency(Class 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); }