From 84ed4bf4c3429ac695fb01adcd593b56706d677a Mon Sep 17 00:00:00 2001 From: zml2008 Date: Wed, 24 Aug 2011 23:56:29 -0700 Subject: [PATCH] Added PermissionsEx support to WEPIF. --- pom.xml | 2 +- .../migration/NijiPermissionsResolver.java | 5 +- .../migration/PermissionsExResolver.java | 51 +++++++++++++++++++ .../migration/PermissionsResolverManager.java | 15 ++++++ .../PermissionsResolverServerListener.java | 8 +-- 5 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java diff --git a/pom.xml b/pom.xml index 0701375e0..f7bf52fb0 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.sk89q dummypermscompat - 1.3 + 1.4 diff --git a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java index 086862ccf..03d096808 100644 --- a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java @@ -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) diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java new file mode 100644 index 000000000..2cc8c1e5e --- /dev/null +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsExResolver.java @@ -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(); + } + +} diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java index 3dc8dd336..14690dd6b 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java @@ -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; + } } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java index f64e8c486..3fccc3b5b 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java @@ -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(); }