Check Permissions

Sometimes when writing a plugin, you might want to restrict the commands you’ve created—maybe only ops should run them, or maybe you have different kinds of players or teams, and each should only be able to run certain commands.

For instance, suppose you want to restrict the firebow commands to a select set of players. We’ll invent a new name; let’s call it commands.firebow.enable.

You can then use the permissions field in the @Command annotation to check if the player issuing the command is one of the chosen few:

 
@Command(aliases = { ​"nofirebow"​ },
 
description = ​"Disable firebow behavior"​,
 
permissions = { ​"commands.firebow.enable"​ },
 
toolTip = ​"/nofirebow"​)

Now only players who have the permission for ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.