Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoPermissionException fires with wrong permissions #365

Open
SirSalad opened this issue May 29, 2022 · 1 comment
Open

NoPermissionException fires with wrong permissions #365

SirSalad opened this issue May 29, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@SirSalad
Copy link

When the command sender has no permissions relevant to the command manager, and attempts to use a command, NoPermissionException will have all permissions rather than the appropriate one.

Versions: cloud-paper 1.6.2 and 1.7.0-SNAPSHOT (bcc9d30)

Code:

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        try {
            var commandManager = PaperCommandManager.createNative(this, CommandExecutionCoordinator.simpleCoordinator());

            commandManager.registerExceptionHandler(NoPermissionException.class, (ignored, exception) ->
                    getLogger().info(exception::getMessage)
            );

            commandManager.command(commandManager.commandBuilder("command1")
                    .permission("permission1")
                    .handler(context -> context.getSender().sendMessage("Handling command1"))
            );

            commandManager.command(commandManager.commandBuilder("command2")
                    .permission("permission2")
                    .handler(context -> context.getSender().sendMessage("Handling command2"))
            );
        } catch (Exception ignored) {}
    }
}

Output:

[11:09:44 INFO]: SirSalad issued server command: /command1
[11:09:44 INFO]: [MyPlugin] Missing permission '(permission2)|(permission1)' <-- should only have permission1
[11:09:47 INFO]: SirSalad issued server command: /command2
[11:09:47 INFO]: [MyPlugin] Missing permission '(permission2)|(permission1)' <-- should only have permission2

[11:09:58 INFO]: SirSalad issued server command: /lp user SirSalad permission set permission1 true
[11:10:03 INFO]: SirSalad issued server command: /command1
[11:10:05 INFO]: SirSalad issued server command: /command2
[11:10:05 INFO]: [MyPlugin] Missing permission 'permission2' <-- this is correct
@Citymonstret
Copy link
Member

It's not really wrong per se. When building the command tree, the root note will end up with an OR-permission that is built up by the command permissions. It's failing on this OR-permission because the sender lacks permission to use any of the commands.

Because of the way parsing works, we never even attempts to traverse the tree further if we fail that early, thus we don't really have information about which command that was actually going to be executed, had the permission checks passed. Therefore I am not really sure if there's a good way to "solve" this.

@Citymonstret Citymonstret added the enhancement New feature or request label May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants