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
  • 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

      default boolean shouldValidate(CommandContext context)
      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

      default String getName()
      Gets the name of this validator for debugging and logging purposes.
      Returns:
      the validator name
    • onComplete

      default void onComplete(CommandContext context, boolean commandSucceeded)
      Invoked once, after the mapped command method has returned or thrown, for each validator whose validate(CommandContext) succeeded during the chain run that gated this invocation. Never invoked for a validator that did not run -- skipped via shouldValidate(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. ascending getOrder().

      "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 context
      commandSucceeded - true if the mapped method returned without throwing, false if it threw
      Since:
      6.3.0