@Permission
To restrict access to a command, you can use the @Permission
annotation.
java
@Command(name = "heal")
@Permission("heal.use")
public class HealCommand {
@Execute
void heal(@Context Player player) {
player.setHealth(20);
player.sendMessage("You have been healed!");
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Missing Permissions Message
In the example, the HealCommand
can be executed only by players with the heal.use
permission; otherwise, LiteCommands shows a LiteMessages.NO_PERMISSION
message or uses a custom missing permissions handler.
Multiple Permissions
You can define multiple permissions for a command:
java
@Command(name = "gamemode")
@Permission({"gamemode.use", "gamemode.admin"})
public class GamemodeCommand {
@Execute
void gamemode(@Context Player player, @Arg GameMode mode) {
player.setGameMode(gameMode);
}
@Executor
@Permission("gamemode.other")
void list(@Context CommandSender sender, @Arg GameMode mode, @Arg Player target) {
target.setGameMode(mode);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
INFO
Now /gamemode <mode>
can be executed by players with gamemode.use
and gamemode.admin
permissions, and /gamemode <mode> <player>
can be executed by players with gamemode.other
permission.