-
Notifications
You must be signed in to change notification settings - Fork 3
Command API: Permissions
Uppercore generates a permissions tree based on the commands hierarchy.
For example, saying your plugin's name is Quake and you have created these commands:
/quake <command>
/quake create <arena>
/quake version
/quake join <arena>
/quake show arenas
The generated permissions will be:
quake.quake
quake.quake.*
quake.quake.create
quake.quake.version
quake.quake.join
quake.quake.show.*
quake.quake.show.arenas
By default, every permission won't be available to common players, just to operators.
Every node command automatically appends the "all" permission: the one that ends with *. Having this permission permits to the owner to access all of the sub-commands in any case.
The most common thing you'd probably need is to have commands available to all players. Using the example above, you'd probably want to make /quake join
available. Depending on which approach to the command-api you're using, there are two ways of doing it:
Within the command constructor add the following line:
public JoinArenaCommand() {
super("join");
setDescription("Creates a new arena with the given name.");
setSenderType(SenderType.PLAYER);
addAliases("c", "make");
// Sets the leaf permission for the current command.
setPermissionPortion(new Permission("create", PermissionUser.AVAILABLE.get())); // <---
}
@AsCommand(
description = "Joins an arena.",
sender = SenderType.PLAYER
)
@WithPermission( // <---
user = PermissionUser.AVAILABLE
)
public void join(Player player, String arena) {
// (...)
}
// Still inside of the Command class's constructor.
setPermissionCompleter(PermissionCompleter.NONE);
@WithPermission(
value = "my.absolute.permission",
completer = PermissionCompleter.NONE
)
// Command's function...
After writing your commands is absolutely important that you test if permissions are set the way you want. Within every root command - the command that starts with / and the one registered with CommandRegistry - Uppercore adds a sub-command to print in a markdown file the commands-permissions table.
Back to the /quake command, the sub-command will be:
/quake printmd