Class PermissionValidator
- All Implemented Interfaces:
CommandValidator
Which senders actually reach the class-level check (#383, corrected #413).
CommandManager.registerCommandDirect calls command.setPermission(permission) with the
value from @CmdExecutor, so Paper filters the command out of the command tree of any
player who lacks it and answers with a parse error before onCommand is invoked
at all. Measured across 22 permission-gated commands on a real 1.21.4 server: a deop'd player
received Unknown or incomplete command every time and never this validator's message,
while an op'd player received real output for the same commands -- the control proving they
were registered and working.
The class-level branch is therefore reached by:
- the console, which always satisfies the Bukkit-level check, and
- a player who already holds the class-level permission -- the Bukkit-level filter
above only rejects a player who lacks the permission before
onCommandever runs; a player who holds it is not filtered, reachesonCommandnormally, and is still evaluated by this branch, where it trivially passes.
Method-level permissions declared on @CmdMapping are not registered with Bukkit,
so those branches run for every sender, players included, normally.
The Bukkit-level filter itself is deliberate and is not a defect to be fixed by deleting this
branch or by dropping the Bukkit registration. Hiding a command a player cannot use is standard
Minecraft behaviour and avoids disclosing that the command exists; the branch still governs the
console, and still governs any player who does hold the permission. What was wrong before 6.3.0
was only that nothing said a permitted player was among the senders reached here. Removing
setPermission so an unpermitted player could see the class-level branch's message too
would make every permission-gated command visible in every player's tab completion -- a product
decision, not a bug fix, and one for the maintainer rather than this class.
- Since:
- 6.2.0
- Version:
- 2.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.abstracts.command.validation.CommandValidator
CommandValidator.ValidationResult -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate static final intprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates a permission validator with no base permission requirement.PermissionValidator(String permission, boolean requireOp) Creates a permission validator with the specified permission. -
Method Summary
Modifier and TypeMethodDescriptionstatic PermissionValidatorfromAnnotation(CmdExecutor annotation) Creates a validator from a CmdExecutor annotation.getName()Gets the name of this validator for debugging and logging purposes.intgetOrder()Gets the order of this validator.validate(CommandContext context) Validates the command context.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.ultikits.ultitools.abstracts.command.validation.CommandValidator
onComplete, shouldValidate
-
Field Details
-
ORDER
private static final int ORDER- See Also:
-
basePermission
-
requireOp
private final boolean requireOp
-
-
Constructor Details
-
PermissionValidator
public PermissionValidator()Creates a permission validator with no base permission requirement. -
PermissionValidator
Creates a permission validator with the specified permission.- Parameters:
permission- the required permissionrequireOp- whether OP is required
-
-
Method Details
-
validate
Description copied from interface:CommandValidatorValidates the command context.- Specified by:
validatein interfaceCommandValidator- Parameters:
context- the command context to validate- Returns:
- the validation result
-
getOrder
public int getOrder()Description copied from interface:CommandValidatorGets the order of this validator. Lower values are executed first.- Specified by:
getOrderin interfaceCommandValidator- Returns:
- the order value
-
getName
Description copied from interface:CommandValidatorGets the name of this validator for debugging and logging purposes.- Specified by:
getNamein interfaceCommandValidator- Returns:
- the validator name
-
fromAnnotation
Creates a validator from a CmdExecutor annotation.- Parameters:
annotation- the annotation- Returns:
- a new validator
-