CommandCallable -> testPermissions(): Is it not implemented or is it a bug?

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

A ok thank you!

/**
 * 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.

On the flip side, CommandSpec seems to check the permission if specified and actually bail out of executing.

https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/command/spec/CommandSpec.java#L270

Yep, CommandCallable is the most LOW LEVEL interface.

If you want an example:

https://github.com/FoxDenStudio/FoxGuard/blob/master/src/main/java/net/foxdenstudio/foxguard/plugin/command/handlers/CommandPriority.java#L49