• 欢迎来到Minecraft插件百科!
  • 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
  • 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289

“Developing a permissions plugin”的版本间的差异

来自Minecraft插件百科
跳转至: 导航搜索
(创建)
 
(汉化引言部分)
第1行: 第1行:
 
[[Developing a permissions plugin/en|点击此处查看原文]]
 
[[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.
+
这篇教程将会带领你了解有关怎么基于新的BukkitPermissionsAPI给你插件创建权限。
  
=== 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.
+
这篇教程需要你掌握很好的Java知识和一些插件开发知识。这篇教程只会涵盖有关Bukkit Permissions API的各种细节。
  
 
== Permissible  ==
 
== Permissible  ==

2015年9月3日 (四) 20:33的版本

点击此处查看原文

Icon-info.png
本页面已存在其他语言的内容,请协助翻译为本地化的中文。
  • 点击此处开始翻译。
  • 如本模板出现在原文存档页面,请注意更新主页面后,仍需要去除此处该模板。
  • 如当前页面已经没有需要翻译的内容,请删去待翻译模板。
  • 有标题的大篇幅文章,如果短时间内无法全部翻译,请先把所有的标题翻译出来,以便之后的贡献者选择与翻译章节内容。

引言

这篇教程将会带领你了解有关怎么基于新的BukkitPermissionsAPI给你插件创建权限。

前提

这篇教程需要你掌握很好的Java知识和一些插件开发知识。这篇教程只会涵盖有关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:

  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

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