Added PermissionsEx support to WEPIF.

This commit is contained in:
zml2008 2011-08-24 23:56:29 -07:00
parent da6e6da024
commit 84ed4bf4c3
5 changed files with 73 additions and 8 deletions

View File

@ -34,7 +34,7 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>dummypermscompat</artifactId>
<version>1.3</version>
<version>1.4</version>
</dependency>
<!-- Bukkit -->

View File

@ -26,6 +26,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.sk89q.bukkit.migration.PermissionsResolverManager.MissingPluginException;
public class NijiPermissionsResolver implements PermissionsResolver {
private Server server;
@ -126,10 +127,6 @@ public class NijiPermissionsResolver implements PermissionsResolver {
public static class PluginAccessException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
public static boolean checkRealNijiPerms(boolean ignoreBridges) {
if (!ignoreBridges)

View File

@ -0,0 +1,51 @@
package com.sk89q.bukkit.migration;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.PermissionUser;
import com.sk89q.bukkit.migration.PermissionsResolverManager.MissingPluginException;
public class PermissionsExResolver implements PermissionsResolver {
private final PermissionManager manager;
private final Server server;
public PermissionsExResolver(Server server) throws MissingPluginException {
this.server = server;
manager = server.getServicesManager().load(PermissionManager.class);
if (manager == null)
throw new MissingPluginException();
}
public void load() {
}
public boolean hasPermission(String name, String permission) {
Player player = server.getPlayer(name);
return manager.has(name, permission, player == null ? null : player.getWorld().getName());
}
public boolean hasPermission(String worldName, String name, String permission) {
return manager.has(name, permission, worldName);
}
public boolean inGroup(String player, String group) {
PermissionUser user = manager.getUser(player);
if (user == null) {
return false;
}
return user.inGroup(group);
}
public String[] getGroups(String player) {
PermissionUser user = manager.getUser(player);
if (user == null) {
return new String[0];
}
return user.getGroupsNames();
}
}

View File

@ -68,6 +68,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
public void findResolver() {
if (tryPluginPermissionsResolver()) return;
if (tryNijiPermissions()) return;
if (tryPermissionsEx()) return;
if (tryDinnerPerms()) return;
if (tryFlatFilePermissions()) return;
@ -85,6 +86,16 @@ public class PermissionsResolverManager implements PermissionsResolver {
}
}
private boolean tryPermissionsEx() {
try {
perms = new PermissionsExResolver(server);
logger.info(name + ": PermissionsEx detected! Using PermissionsEx for permissions.");
return true;
} catch (Throwable e) {
return false;
}
}
private boolean tryFlatFilePermissions() {
if (FlatFilePermissionsResolver.filesExists()) {
perms = new FlatFilePermissionsResolver();
@ -184,5 +195,9 @@ public class PermissionsResolverManager implements PermissionsResolver {
}
return isUpdated;
}
public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
}

View File

@ -44,8 +44,9 @@ public class PermissionsResolverServerListener extends ServerListener {
String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider) {
manager.setPluginPermissionsResolver(plugin);
} else if (name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) {
} else if ((name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) ||
name.equalsIgnoreCase("PermissionsEx")) {
manager.findResolver();
manager.load();
}
@ -63,7 +64,8 @@ public class PermissionsResolverServerListener extends ServerListener {
if (plugin instanceof PermissionsProvider
|| (name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges))) {
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) ||
name.equalsIgnoreCase("PermissionsEx")) {
manager.findResolver();
manager.load();
}