Interface CommandValidator
- All Known Implementing Classes:
CooldownValidator,PermissionValidator,SenderTypeValidator,UsageLockValidator
- 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 voidonRefused(CommandContext context) Invoked once, instead ofonComplete(CommandContext, boolean), for each validator whosevalidate(CommandContext)succeeded when the dispatch is then refused before the mapped method runs: by a validator later in the chain, by an exception from a later validator'sshouldValidate(CommandContext)orvalidate(CommandContext), by the argument-count check, or because a parameter could not be parsed.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.An exception thrown here refuses the dispatch like one thrown from
validate(CommandContext): the validators that already passed receiveonRefused(CommandContext), and the exception propagates unchanged (as of 6.3.0).- 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
-
onRefused
Invoked once, instead ofonComplete(CommandContext, boolean), for each validator whosevalidate(CommandContext)succeeded when the dispatch is then refused before the mapped method runs: by a validator later in the chain, by an exception from a later validator'sshouldValidate(CommandContext)orvalidate(CommandContext), by the argument-count check, or because a parameter could not be parsed. Validators are invoked in chain order. Never invoked for a validator that did not run or that refused.A validator that acquires something in
validate--UsageLockValidatortakes its lock there -- releases it here; the mapped method never ran, so effects that belong to an invocation (a cooldown) are not applied. Before 6.3.0 these refusals released nothing, and a@UsageLimitlock stayed held until the player quit (#568).The default implementation is a no-op, like
onComplete's.- Parameters:
context- the command context- Since:
- 6.3.0
-