Validation annotations are distributed in theDocumentation 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.
craftcommand-validation-annotations artifact under the package io.github.projectunified.craftcommand.validation.annotation. They work in tandem with craftcommand-validation-processor, which must be placed on the annotation processor path — not the regular compile classpath — for validation code to be generated. Like all CraftCommand annotations, these carry RetentionPolicy.CLASS and are processed entirely at compile time.
Maven setup
Add the annotations artifact as a regular dependency and the processor artifact to<annotationProcessorPaths>:
@Min
Target:PARAMETER
Retention: CLASS
Asserts that a resolved numeric parameter is greater than or equal to the specified minimum. The check runs after the argument is resolved to its target type (e.g. int, long, double, float). If the value is below the minimum, the processor-generated code throws a ValidationException.
The minimum allowed value, inclusive. Applied after type resolution, so the comparison is always numeric.
An error message or translation key sent when validation fails. Supports two
String.format-style placeholders:%1$s— the display name of the parameter (from@Nameif present, otherwise the Java parameter name)%2$s— the minimum value
"", which causes the platform’s built-in error message to be used.@Max
Target:PARAMETER
Retention: CLASS
Asserts that a resolved numeric parameter is less than or equal to the specified maximum. Mirrors @Min in structure and behaviour; the only difference is the direction of the comparison.
The maximum allowed value, inclusive.
An error message or translation key sent when validation fails. Supports the same placeholders as
@Min:%1$s— the display name of the parameter%2$s— the maximum value
"".@ValidateWith
Target:PARAMETER
Retention: CLASS
Validates a parameter by delegating to a custom validation method declared inside the same command class. The generated code invokes the named method after resolving the argument. If the method throws any exception, the exception is caught, and a ValidationException is raised with the configured message (or the caught exception’s own message when message is "").
The validation method must:
- Be a non-static instance method of the command class.
- Accept a single parameter whose type is the same as (or a supertype of) the annotated command parameter.
- Throw any
Exceptionto signal a failure; return normally to signal success.
The name of the validation method inside the command class.
An error message or translation key sent when validation fails. Supports two placeholders:
%1$s— the display name of the parameter%2$s— the message of the exception thrown by the validation method
"", which causes the platform’s built-in error message to be used (typically the exception message itself).Message translation
By default CraftCommand forwards themessage string directly to the sender. To integrate with a custom localisation system — e.g. looking up keys in a messages.yml — override formatMessage() in your CommandManager subclass:
@Max(value = 10, message = "error.range.max") fails, CraftCommand calls formatMessage("error.range.max", paramName, maxValue). Your override can then translate "error.range.max" into a locale-specific string such as "The value of %1$s must not exceed %2$s." before formatting.