Bukkit/Bukkit — pull request #920 by afistofirony (2013-09-02 00:04:09+00:00)
Title: Allow external permission checking. Adds BUKKIT-4740

This pull request allows the permission-checking process to be modified externally by working *with* the built-in permissions system instead of against it.

## Justification
Ever since Bukkit introduced permissions, working in permission checks has been a tricky task for permission plugin developers. Most of the time, it involves some nasty reflection or other direct modification.

The intent of this addition is to make handling the permission check externally easier by introducing the PermissionManager interface. This interface has one method, checkPermission(Permissible, Permission) which returns a boolean value. The PluginManager must also store a PermissionManagerwhich can be accessed with the getPermissionManager() method or changed with the setPermissionManager(PermissionManager) method. When instantiated, the SimplePluginManager class will use the new SuperPermissions class which implements PermissionManager.

PermissibleBase handles the check (the 'weird' line break does not exist in the actual code):
```java
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);

if (perm != null) {
return Bukkit.getServer().getPluginManager()
.getPermissionManager().checkPermission(this, perm);
} else {
return Permission.DEFAULT_PERMISSION.getValue(isOp());
}
```

CraftBukkit is not affected in any way.

This should hopefully make life a lot easier for permission plugin developers and other people wanting to take over the permission-checking process.

## Example
If a permissions plugin wants to control permissions checks, they can implement PermissionManager to do it. For example:

```java
public class MyPermissionPlugin extends JavaPlugin implements PermissionManager {

public void onEnable () {
this.getServer().getPluginManager().setPermissionManager(this);
}

public boolean checkPermission (Permissible user, Permission permission) {
// Code for checking permissions goes here.
}

}
```

Much simpler than reflection, right?

See the JIRA ticket here: https://bukkit.atlassian.net/browse/BUKKIT-4740