[SPIGOT-2618] Exception when permissions from plugin.yml are already created in onEnable() / Permissions from plugin.yml are loaded after onEnable() Created: 20/Aug/16 Updated: 25/Aug/16 Resolved: 25/Aug/16 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Dragorn421 | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | Craftbukkit, error, onEnable | ||
Environment: |
Java 8, Windows 10 64 bits |
Description |
When a permission is set in the plugin.yml, it is loaded after the plugin's onEnable(). The problem is that when the permission is loaded, there is no check to see if the permission is already registered or not, which leads into an error if the permission was added in the plugin's onEnable(). (adding a check would not fix the issue though, keep reading) To reproduce, declare a permission in the plugin.yml: permissions: permission.test.foo: default: op Then add it in the onEnable(): String permissionName = "permission.test.foo"; Permission permission = Bukkit.getPluginManager().getPermission(permissionName); if(permission == null) { permission = new Permission(permissionName); Bukkit.getPluginManager().addPermission(permission); } And you will get the following exception: How to fix: (imho) I did not check with Spigot but I don't see a reason that this behavior would be different. |
Comments |
Comment by Dragorn421 [ 21/Aug/16 ] |
My plugin lets you create visits that take you around. When a visit is created a permission object with permission "visit." + visitName is associated with it, and I want this permission to be a child of "visit.*". There is no problems for visits added after the plugin was enabled (eg using commands), as it gets either the permission object created by some visit or the one created using plugin.yml permissions, but the ones that are loaded from the configuration are loaded from onEnable() and therefore do not find the "visit.*" permission. So I have to create it, and then the error happens. I think your question was more about "why register permissions in plugin.yml". I prefer to put all permissions I can in the plugin.yml, that way I don't have to keep track of them somewhere else and I can easily change the default values. And I don't see the point of the permissions configuration in plugin.yml if you can't make use of those x) |
Comment by md_5 [ 20/Aug/16 ] |
I get this, but what I don't get is why your plugin would need to register permissions both in code and in the yaml |