Skip to content

Permissions

Marten edited this page Nov 11, 2021 · 4 revisions

One of the features that makes SimpleCommands is easy to use is the fact that the permission handling is taken care of by the SimpleCommand class. The only thing you need to do is define them and the library will take control of the rest!

Root commands

Commands that have sub-commands can specify their own permission node. This node is usually not being tested for. It's present such that sub-commands can stack their own permission on top if they would like to do that. Giving your root command a permission node is highly recommended.

An example root command:

public class DebugCommand extends RootCommand {

    public DebugCommand() {
        super("debug", "example.commands.debug", false);

        addCommand(new SimpleKillPlayer());
        addCommand(new SimpleTeleport());
    }
}

Sub commands

After having defined a root command we can attach new SimpleCommands to it as you might have seen it already. For simplicity we will only show their constructor here:

Standart permission node

public class SimpleTeleport extends SimpleCommand {
    public SimpleTeleport() {
      super("tp", "a.custom.permission", true);
   }
}

Define your own permission node. Simple.

Stacking permission node

public class KillPlayerCommand extends SimpleCommand {
    public SimpleKillPlayer() {
       super("kill", "+kill", false);
    }
}

The SimpleKillPlayer command has the permission: +kill. The + operator attaches the permission to that of the parent. The parents' permission, in this case, is: example.commands.debug. The final permission for this command will be example.commands.debug.kill. Permissions can be stacked like this as much as you want. As an example, consider the following nesting of commands with their permission: example.commands.nest, +fire, 'notch. The final command /nest fire notch will have the permission example.commands.nest.fire.notch.

Sub-command without permission

In cases where your sub-command has not specified a permission, the parents' permission node will be used.

Clone this wiki locally