Welcome to the BukkitWiki!

This Wiki is home to Bukkit's documentation and regulations surrounding the Bukkit Project and it's services. Want to help out? We would love to have you! Signup to get started!

Developing a permissions plugin

From BukkitWiki
Jump to: navigation, search

Introduction[edit | edit source]

This tutorial will guide you through how to create your own permissions plugin that sets permissions using the new Bukkit permissions API.

Prerequisite[edit | edit source]

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.

Permissible[edit | edit source]

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.

PermissionAttachments[edit | edit source]

What is a PermissionAttachment?[edit | edit source]

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[edit | edit source]

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);
This attachment needs to be stored somewhere though. The best solution is to create a
HashMap<UUID,PermissionAttachment>
 and store it in there with the player's Unique ID. That will later allow you to manage a particular player's permissions via their Unique ID, and remove the attachment when it's no longer needed. The best places to remove the attachment are in the onPlayerQuit event and remove them all in the plugin's onDisable event. Removing the attachment is as follows:
player.removeAttachment(attachment);

Assigning permissions[edit | edit source]

There are two main ways to set a player's permission:

  1. Via a string. This is probably the easiest method, and the one which I will explain first.
  2. 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:

attachment.setPermission(permissionName,permissionValue);

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:

attachment.unsetPermission(permissionName);

The reason you may want to unset a player's permission is if you want to allow a different permissions plugin to set it.

Conclusion[edit | edit source]

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беларускаяDeutschespañolsuomifrançaisitaliano한국어Nederlandsnorsk bokmålpolskiportuguêsрусскийlietuviųčeština