Hi
If I use
CommandSpec.builder().permission("...")...
It says no Permissions, when executing the command. This is correct, because I have no Permission Manager installed.
But when I implement CommandCallable and do this:
public boolean testPermission(CommandSource source) {
return false;
}
The command runs without complaining about permissions.
Is this intended, a bug or is it not implemented already?
I tested it with both, SpongeVanilla and SpongeForge.
You have to check yourself. This should work :
@Override
public CommandResult process(CommandSource cs, String args) {
if (!testPermission(cs)) {
cs.sendMessage(Texts.of(TextColors.RED, "You don't have the permission."));
return CommandResult.empty();
}
// TODO execute
return CommandResult.success();
}
If you are using CommandSpec, it’s already done.
1 Like
/**
* Test whether this command can probably be executed by the given source.
*
* <p>If implementations are unsure if the command can be executed by
* the source, {@code true} should be returned. Return values of this method
* may be used to determine whether this command is listed in command
* listings.</p>
*
* @param source The caller of the command
* @return Whether permission is (probably) granted
*/
boolean testPermission(CommandSource source);
So it sounds like to me that testPermissions is only a hint to the system whether the command can be run, for use tab completion / help listings, and not to be confused with actually stopping the CommandCallable from running if returning false. This could probably be made more clear if named differently.