diff --git a/pom.xml b/pom.xml
index 08ef802..7dd5dbe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.hugog.minecraft
dev-command
- 0.0.7
+ 0.0.8
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 8726eef..784b699 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
@@ -1,21 +1,22 @@
package dev.hugog.minecraft.dev_command.commands;
+import dev.hugog.minecraft.dev_command.DevCommand;
import dev.hugog.minecraft.dev_command.arguments.CommandArgument;
+import dev.hugog.minecraft.dev_command.arguments.parsers.ICommandArgumentParser;
import dev.hugog.minecraft.dev_command.commands.data.BukkitCommandData;
+import dev.hugog.minecraft.dev_command.dependencies.DependencyHandler;
+import dev.hugog.minecraft.dev_command.exceptions.ArgumentsConfigException;
import dev.hugog.minecraft.dev_command.exceptions.InvalidArgumentsException;
import dev.hugog.minecraft.dev_command.exceptions.InvalidDependencyException;
+import dev.hugog.minecraft.dev_command.exceptions.PermissionConfigException;
+import dev.hugog.minecraft.dev_command.factories.ArgumentParserFactory;
import dev.hugog.minecraft.dev_command.validation.IAutoValidationConfiguration;
import lombok.Generated;
import lombok.Getter;
-import dev.hugog.minecraft.dev_command.DevCommand;
-import dev.hugog.minecraft.dev_command.dependencies.DependencyHandler;
-import dev.hugog.minecraft.dev_command.exceptions.ArgumentsConfigException;
-import dev.hugog.minecraft.dev_command.exceptions.PermissionConfigException;
-import dev.hugog.minecraft.dev_command.factories.ArgumentParserFactory;
-import dev.hugog.minecraft.dev_command.arguments.parsers.ICommandArgumentParser;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Optional;
@@ -135,7 +136,10 @@ public boolean performAutoValidation(IAutoValidationConfiguration configuration)
}
if (commandData.getAutoValidationData().validateArguments() && commandData.getArguments() != null) {
if (!hasValidArgs()) {
- getCommandSender().sendMessage(configuration.getInvalidArgumentsMessage(this));
+ 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)));
return false;
}
}
@@ -153,4 +157,11 @@ public T getDependency(Class dependencyClass) throws InvalidDependencyExc
return (T) dependencyHandler.getDependencyInstance(commandData.getIntegration(), dependencyClass);
}
+ @Override
+ public CommandArgument[] getInvalidArguments() {
+ return Arrays.stream(commandData.getArguments())
+ .filter(commandArgument -> !getArgumentParser(commandArgument.position()).isValid())
+ .toArray(CommandArgument[]::new);
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/dev/hugog/minecraft/dev_command/commands/IDevCommand.java b/src/main/java/dev/hugog/minecraft/dev_command/commands/IDevCommand.java
index fa2bc3e..ffcba21 100644
--- a/src/main/java/dev/hugog/minecraft/dev_command/commands/IDevCommand.java
+++ b/src/main/java/dev/hugog/minecraft/dev_command/commands/IDevCommand.java
@@ -1,5 +1,6 @@
package dev.hugog.minecraft.dev_command.commands;
+import dev.hugog.minecraft.dev_command.arguments.CommandArgument;
import dev.hugog.minecraft.dev_command.arguments.parsers.ICommandArgumentParser;
import dev.hugog.minecraft.dev_command.validation.IAutoValidationConfiguration;
@@ -29,14 +30,49 @@ public interface IDevCommand {
*/
Optional> getOptionalArgumentParser(int argumentPosition);
+ /**
+ * Check if the player has permission to execute the command.
+ *
+ * @return true if the player has permission, false otherwise
+ */
boolean hasPermissionToExecuteCommand();
+ /**
+ * Check if all arguments provided are valid.
+ *
+ * @return true if all arguments are valid, false otherwise
+ */
boolean hasValidArgs();
+ /**
+ * Check if the command sender can execute the command.
+ *
+ * @return true if the command sender can execute the command, false otherwise
+ */
boolean canSenderExecuteCommand();
+ /**
+ * Perform auto-validation of the command.
+ *
+ * @param configuration the configuration for auto-validation
+ * @return true if the command is valid, false otherwise
+ */
boolean performAutoValidation(IAutoValidationConfiguration configuration);
+ /**
+ * Get a dependency injected into the command.
+ *
+ * @param dependencyClass the class of the dependency to get
+ * @param the type of the dependency
+ * @return the dependency instance
+ */
T getDependency(Class dependencyClass);
+ /**
+ * Get all invalid arguments for the command.
+ *
+ * @return an array of invalid arguments, or an empty array if all arguments are valid
+ */
+ CommandArgument[] getInvalidArguments();
+
}
diff --git a/src/main/java/dev/hugog/minecraft/dev_command/validation/DefaultAutoValidationConfiguration.java b/src/main/java/dev/hugog/minecraft/dev_command/validation/DefaultAutoValidationConfiguration.java
index 23b96a4..096dc4b 100644
--- a/src/main/java/dev/hugog/minecraft/dev_command/validation/DefaultAutoValidationConfiguration.java
+++ b/src/main/java/dev/hugog/minecraft/dev_command/validation/DefaultAutoValidationConfiguration.java
@@ -10,7 +10,7 @@ public String getNoPermissionMessage(BukkitDevCommand command) {
@Override
public String getInvalidArgumentsMessage(BukkitDevCommand command) {
- return "You have provided invalid arguments. Please try again.";
+ return "You have provided invalid arguments. The argument {0} on position {1} is invalid.";
}
@Override