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

Developing a permissions plugin:修订间差异

来自Minecraft插件百科
跳转到导航 跳转到搜索
(创建)
 
 
(未显示4个用户的7个中间版本)
第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.
== 引言  ==


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


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  ==
这篇教程需要你掌握很好的Java知识和一些插件开发知识。这篇教程只会涵盖有关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.
== Permissible类  ==
 
所有拥有权限集的类都必须继承自Permissible类。<br />
目前这些只包含Player和CommandSender类,然而理论上任何事物都应该拥有“权限”。<br />在接下来的教程里我们将更多的提到玩家而不是permissible对象。


== PermissionAttachments  ==
== PermissionAttachments  ==


=== What is a PermissionAttachment?  ===
=== PermissionAttachment是什么?  ===
 
<br/>什么是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.
<br/>“权限附属物”[PermissionAttachment]是插件管理玩家权限的一种手段,更胜一筹的是,它允许多插件管理玩家权限而不需要接口,除非它想要设置同样的权限。
 
=== 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:


=== 怎样创建和移除它们  ===
<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


<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:


<source lang="java">player.removeAttachment(attachment);</source>
<source lang="java">player.removeAttachment(attachment);</source>


== Assigning permissions  ==
== 配置权限 ==


There are two main ways to set a player's permission:
<br/>这有两种主要的方法去配置玩家的权限:


#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.
#通过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,你就可以通过一种简单的方式来设置权限。代码如下:


<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不同)


<source lang="java">attachment.unsetPermission(permissionName);</source>  
<source lang="java">attachment.unsetPermission(permissionName);</source>  
 
<br/>
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 ==
以上就是所有想要写出自己的权限插件的你需要知道东西了。
 
一个真正的权限插件是什么样的完全取决于你。下面提供2个例子:
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:
* 一个根据玩家经验值继续权限的RPG插件
 
* 一个从论坛链接权限组/权限的接口,例如从phpBB到bukkit权限
*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
 
 


[[Category:开发教程]]
[[Category:开发教程]]

2017年8月1日 (二) 10:32的最新版本

点击此处查看原文

引言

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

前提

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

Permissible类

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

PermissionAttachments

PermissionAttachment是什么?


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

怎样创建和移除它们


如何创建和移除一个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);

配置权限


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

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


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

attachment.setPermission(permissionName,permissionValue);


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

attachment.unsetPermission(permissionName);


你希望撤销玩家权限的原因是你希望别的权限插件来设置它。

总结

以上就是所有想要写出自己的权限插件的你需要知道东西了。 一个真正的权限插件是什么样的完全取决于你。下面提供2个例子:

  • 一个根据玩家经验值继续权限的RPG插件
  • 一个从论坛链接权限组/权限的接口,例如从phpBB到bukkit权限