- 欢迎来到Minecraft插件百科!
- 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
- 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289
Developing a permissions plugin/en
Introduction
This tutorial will guide you through how to create your own permissions plugin that sets permissions using the new Bukkit permissions API.
Prerequisite
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
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
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);
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, onPlayerKick event, and remove them all in the plugin's onDisable event. Removing the attachment is as follows:
player.removeAttachment(attachment);
Assigning permissions
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:
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
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