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

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

来自Minecraft插件百科
跳转至: 导航搜索
(简单修改,去除英语原文)
第11行: 第11行:
 
== Permissible  ==
 
== 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.<br />
 
 
所有拥有权限集的类都必须继承自Permissible类。<br />
 
所有拥有权限集的类都必须继承自Permissible类。<br />
 
目前这些只包含Player和CommandSender类,然而理论上任何事物都应该拥有“权限”。<br />在接下来的教程里我们将更多的提到玩家而不是permissible对象。
 
目前这些只包含Player和CommandSender类,然而理论上任何事物都应该拥有“权限”。<br />在接下来的教程里我们将更多的提到玩家而不是permissible对象。
第19行: 第18行:
 
=== What is a PermissionAttachment?  ===
 
=== What is a PermissionAttachment?  ===
 
<br/>什么是PermissionAttachment?
 
<br/>什么是PermissionAttachment?
<br/>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.<br/>“权限附属物”[PermissionAttachment]是插件管理玩家权限的一种手段,更胜一筹的是,它允许多插件管理玩家权限而不需要接口,除非它想要设置同样的权限。
+
<br/>“权限附属物”[PermissionAttachment]是插件管理玩家权限的一种手段,更胜一筹的是,它允许多插件管理玩家权限而不需要接口,除非它想要设置同样的权限。
  
 
=== How to create and remove them  ===
 
=== How to create and remove them  ===
 
<br/>如何创建和移除一个PermissionAttachment
 
<br/>如何创建和移除一个PermissionAttachment
<br/>Every player must first be "attached" to the plugin so that it can be managed. To create a PermissionAttachment, use the following:
 
 
<br/>每一位玩家必须先被“附着”在插件上,这样才能使用他们。用如下代码来创建一个PermissionAttachment:
 
<br/>每一位玩家必须先被“附着”在插件上,这样才能使用他们。用如下代码来创建一个PermissionAttachment:
 
<source lang="java">PermissionAttachment attachment = player.addAttachment(plugin);</source>  
 
<source lang="java">PermissionAttachment attachment = player.addAttachment(plugin);</source>  
  
You can even create an attachment that will only last for a limited number of ticks:
 
 
<br/>你甚至可以创建一个仅仅只维持很短时间的attachment
 
<br/>你甚至可以创建一个仅仅只维持很短时间的attachment
  
 
<source lang="java">PermissionAttachment attachment = player.addAttachment(plugin,ticks);</source>  
 
<source lang="java">PermissionAttachment attachment = player.addAttachment(plugin,ticks);</source>  
  
This attachment needs to be stored somewhere though. The best solution is to create a <source lang="java">HashMap<UUID,PermissionAttachment></source>&nbsp;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:
 
 
<br/>attachment需要被储存起来。最好的解决方案是用哈希表HashMap<UUID,PermissionAttachment> 来储存。用玩家的UniqueID作为键值。之后你就可以用玩家的UniqueID来管理指定玩家的权限了。 并且在不需要的时候移除它。移除attachment的地方最好是onPlayerQuit event, onPlayerKick event。并且总是在插件的onDisable中移除所有的attachment。使用下面的代码移除attachment:
 
<br/>attachment需要被储存起来。最好的解决方案是用哈希表HashMap<UUID,PermissionAttachment> 来储存。用玩家的UniqueID作为键值。之后你就可以用玩家的UniqueID来管理指定玩家的权限了。 并且在不需要的时候移除它。移除attachment的地方最好是onPlayerQuit event, onPlayerKick event。并且总是在插件的onDisable中移除所有的attachment。使用下面的代码移除attachment:
  
第39行: 第35行:
 
== Assigning permissions  ==
 
== Assigning permissions  ==
  
There are two main ways to set a player's permission:
 
 
<br/>这有两种主要的方法去配置玩家的权限:
 
<br/>这有两种主要的方法去配置玩家的权限:
  
#Via a string. This is probably the easiest method, and the one which I will explain first.
+
#通过字符串。这大概是最简单的方法了,所以我最先解释它。
通过字符串。这大概是最简单的方法了,所以我最先解释它。
+
#通过permission对象。这就有点复杂了,然而他内部的工作方式与第一个完全一样。所以我并不打算重温它。
#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.
 
通过permission对象。这就有点复杂了,然而他内部的工作方式与第一个完全一样。所以我并不打算重温它。
 
  
 
<br>  
 
<br>  
  
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:
+
想要设置玩家的权限你必须先获取之前通过哈希表创建的PermissionAttachment。一旦你取得了PermissionAttachment,你就可以通过一种简单的方式来设置权限。代码如下:
<br/>想要设置玩家的权限你必须先获取之前通过哈希表创建的PermissionAttachment。一旦你取得了PermissionAttachment,你就可以通过一种简单的方式来设置权限。代码如下:
 
  
 
<source lang="java">attachment.setPermission(permissionName,permissionValue);</source>  
 
<source lang="java">attachment.setPermission(permissionName,permissionValue);</source>  
  
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:
 
 
<br/>permissionName是一个字符串,permissionValue则是布尔类型数据。之后你可以通过如下代码撤销一个玩家的权限(与将permissionValue设置成false不同):
 
<br/>permissionName是一个字符串,permissionValue则是布尔类型数据。之后你可以通过如下代码撤销一个玩家的权限(与将permissionValue设置成false不同):
  

2015年10月25日 (日) 10:17的版本

点击此处查看原文

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

引言

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

前提

这篇教程需要你掌握很好的Java知识和一些插件开发知识。这篇教程只会涵盖有关Bukkit Permissions API的各种细节。

Permissible

所有拥有权限集的类都必须继承自Permissible类。
目前这些只包含Player和CommandSender类,然而理论上任何事物都应该拥有“权限”。
在接下来的教程里我们将更多的提到玩家而不是permissible对象。

PermissionAttachments

What is a PermissionAttachment?


什么是PermissionAttachment?
“权限附属物”[PermissionAttachment]是插件管理玩家权限的一种手段,更胜一筹的是,它允许多插件管理玩家权限而不需要接口,除非它想要设置同样的权限。

How to create and remove them


如何创建和移除一个PermissionAttachment
每一位玩家必须先被“附着”在插件上,这样才能使用他们。用如下代码来创建一个PermissionAttachment:

PermissionAttachment attachment = player.addAttachment(plugin);


你甚至可以创建一个仅仅只维持很短时间的attachment

PermissionAttachment attachment = player.addAttachment(plugin,ticks);


attachment需要被储存起来。最好的解决方案是用哈希表HashMap<UUID,PermissionAttachment> 来储存。用玩家的UniqueID作为键值。之后你就可以用玩家的UniqueID来管理指定玩家的权限了。 并且在不需要的时候移除它。移除attachment的地方最好是onPlayerQuit event, onPlayerKick event。并且总是在插件的onDisable中移除所有的attachment。使用下面的代码移除attachment:

player.removeAttachment(attachment);

Assigning permissions


这有两种主要的方法去配置玩家的权限:

  1. 通过字符串。这大概是最简单的方法了,所以我最先解释它。
  2. 通过permission对象。这就有点复杂了,然而他内部的工作方式与第一个完全一样。所以我并不打算重温它。


想要设置玩家的权限你必须先获取之前通过哈希表创建的PermissionAttachment。一旦你取得了PermissionAttachment,你就可以通过一种简单的方式来设置权限。代码如下:

attachment.setPermission(permissionName,permissionValue);


permissionName是一个字符串,permissionValue则是布尔类型数据。之后你可以通过如下代码撤销一个玩家的权限(与将permissionValue设置成false不同):

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. ,br/>撤销玩家权限的原因是你希望别的权限插件来设置它。

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:
一个真正的权限插件是什么样的完全取决于你。下面提供2个例子:

  • 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