Developing a permissions plugin
This tutorial will guide you through how to create your own permissions plugin that sets permissions using the new Bukkit permissions API.
This tutorial assumes you have a good understanding of the Java language, and general plugin development. This tutorial will only cover the specifics of the Bukkit permissions API.
Everything that can have permissions set must inherit the Permissible class. Currently these only include the Player and CommandSender classes, however in theory anything could have permissions. For the future of this tutorial we will mention the player rather than a permissible object.
What is a PermissionAttachment?
A permission attachment is a way for a plugin to manage a player's permissions, and even better, allows multiple plugins to manage the player's permissions without interference, unless of course they want to set the same permission.
How to create and remove them
Every player must first be "attached" to the plugin so that it can be managed. To create a PermissionAttachment, use the following:
PermissionAttachment attachment = player.addAttachment(plugin);
You can even create an attachment that will only last for a limited number of ticks:
PermissionAttachment attachment = player.addAttachment(plugin,ticks);
There are two main ways to set a player's permission:
- Via a string. This is probably the easiest method, and the one which I will explain first.
- Via a permission Object. This is slightly more complicated, however it works in exactly the same way as the first internally, so I won't bother going over this.
To set a player's permission you firstly have to get the PermissionAttachment you created earlier from the HashMap. Once you have this then setting a player's permissions is easy via the following:
The permissionName is a String, and permissionValue is a boolean. You can later unset a player's permission (different to setting it to false) through the following:
The reason you may want to unset a player's permission is if you want to allow a different permissions plugin to set it.
That's about all there is to know about writing your own permissions plugin. The actual implementation of the plugin however is up to you. I can however provide a few examples:
- An RPG plugin that gives player's permissions based on their XP
- A forum bridge that links groups/permissions from a forum such as phpBB to bukkit's permissions
|Language||English • беларуская • Deutsch • español • suomi • français • italiano • 한국어 • Nederlands • norsk bokmål • polski • português • русский • lietuvių • čeština|