Interface CommandValidator
- All Known Implementing Classes:
CooldownValidator,PermissionValidator,SenderTypeValidator,UsageLockValidator
public interface CommandValidator
Interface for command validation following the Chain of Responsibility pattern.
Validators are executed in order and can stop the chain by returning a failed result.
- Since:
- 6.2.0
- Version:
- 2.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classResult of a validation operation. -
Method Summary
Modifier and TypeMethodDescriptiondefault StringgetName()Gets the name of this validator for debugging and logging purposes.default intgetOrder()Gets the order of this validator.default voidonComplete(CommandContext context, boolean commandSucceeded) Invoked once, after the mapped command method has returned or thrown, for each validator whosevalidate(CommandContext)succeeded during the chain run that gated this invocation.default booleanshouldValidate(CommandContext context) Checks if this validator should be applied to the given context.validate(CommandContext context) Validates the command context.
-
Method Details
-
validate
Validates the command context.- Parameters:
context- the command context to validate- Returns:
- the validation result
-
getOrder
default int getOrder()Gets the order of this validator. Lower values are executed first.- Returns:
- the order value
-
shouldValidate
Checks if this validator should be applied to the given context.- Parameters:
context- the command context- Returns:
- true if this validator should be applied
-
getName
Gets the name of this validator for debugging and logging purposes.- Returns:
- the validator name
-
onComplete
Invoked once, after the mapped command method has returned or thrown, for each validator whosevalidate(CommandContext)succeeded during the chain run that gated this invocation. Never invoked for a validator that did not run -- skipped viashouldValidate(CommandContext), or never reached because an earlier validator in the chain failed. Validators are invoked in the same order the chain validated them, i.e. ascendinggetOrder()."In the chain that ran" and "receives this call" are the same fact by construction: the caller drives this hook from
ValidatorChain.ChainValidationResult#getPassedValidators(), never from a hard-coded reference to a specific validator instance.The default implementation is a no-op, so existing validators that only gate -- and have no side effect to apply afterward -- require no change.
- Parameters:
context- the command contextcommandSucceeded-trueif the mapped method returned without throwing,falseif it threw- Since:
- 6.3.0
-