The validation module is an optional add-on for CraftCommand that generates bounds-checking and custom-validation code directly into the command wrapper at compile time. No runtime reflection is involved — the generatedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ProjectUnified/CraftCommand/llms.txt
Use this file to discover all available pages before exploring further.
if-statements and try/catch blocks are plain Java, sitting right alongside the rest of the resolved parameter code.
Maven setup
Add the annotations artifact to your<dependencies> (compile scope) and the processor artifact to the <annotationProcessorPaths> of the Maven Compiler Plugin alongside your platform processor. The validation processor registers its handlers through Java SPI, so the platform processor discovers and invokes them automatically during code generation.
@Min
@Min validates that a numeric parameter value is at least the specified minimum (inclusive). If the value is below the threshold the generated code throws a CommandException.
| Attribute | Type | Required | Description |
|---|---|---|---|
value | double | ✅ | The minimum allowed value (inclusive). |
message | String | ❌ | Error message or translation key. Defaults to the built-in key validation.min. |
message:
%1$s— the parameter name%2$s— the minimum value
@Max
@Max validates that a numeric parameter value is at most the specified maximum (inclusive). If the value exceeds the threshold the generated code throws a CommandException.
| Attribute | Type | Required | Description |
|---|---|---|---|
value | double | ✅ | The maximum allowed value (inclusive). |
message | String | ❌ | Error message or translation key. Defaults to the built-in key validation.max. |
message:
%1$s— the parameter name%2$s— the maximum value
@ValidateWith
@ValidateWith delegates validation to a method you define inside the command class. If the method throws any exception, the exception message is captured and wrapped in a CommandException.
| Attribute | Type | Required | Description |
|---|---|---|---|
value | String | ✅ | Name of the validation method in the command class. |
message | String | ❌ | Error message or translation key. Defaults to validation.custom. When empty, %2$s (the exception message) is used verbatim. |
message:
%1$s— the parameter name%2$s— the exception message thrown by the validation method
| Signature | When to use |
|---|---|
void method() | No access to the value or sender needed |
void method(T value) | Access to the parameter value |
void method(S sender, T value) | Access to both sender and value |
Combining validators
Multiple validation annotations can be stacked on the same parameter. They are applied in order after the parameter is resolved:@Min is checked before @Max, and both are checked before @ValidateWith.
Custom error messages
There are two distinct modes for themessage attribute:
- Literal message
- Translation key
When
message is set to a plain string that does not match any key in the message dictionary, it is used verbatim as the error text.The default templates when
message is not set are "%s cannot be less than %s" for @Min and "%s cannot be greater than %s" for @Max. The built-in keys are validation.min, validation.max, and validation.custom.