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> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
<artifactId>dummypermscompat</artifactId> <artifactId>dummypermscompat</artifactId>
<version>1.3</version> <version>1.4</version>
</dependency> </dependency>
<!-- Bukkit --> <!-- Bukkit -->

View File

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

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() { public void findResolver() {
if (tryPluginPermissionsResolver()) return; if (tryPluginPermissionsResolver()) return;
if (tryNijiPermissions()) return; if (tryNijiPermissions()) return;
if (tryPermissionsEx()) return;
if (tryDinnerPerms()) return; if (tryDinnerPerms()) return;
if (tryFlatFilePermissions()) 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() { private boolean tryFlatFilePermissions() {
if (FlatFilePermissionsResolver.filesExists()) { if (FlatFilePermissionsResolver.filesExists()) {
perms = new FlatFilePermissionsResolver(); perms = new FlatFilePermissionsResolver();
@ -185,4 +196,8 @@ public class PermissionsResolverManager implements PermissionsResolver {
return isUpdated; 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(); String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider) { if (plugin instanceof PermissionsProvider) {
manager.setPluginPermissionsResolver(plugin); manager.setPluginPermissionsResolver(plugin);
} else if (name.equalsIgnoreCase("Permissions") && } else if ((name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) { NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) ||
name.equalsIgnoreCase("PermissionsEx")) {
manager.findResolver(); manager.findResolver();
manager.load(); manager.load();
} }
@ -63,7 +64,8 @@ public class PermissionsResolverServerListener extends ServerListener {
if (plugin instanceof PermissionsProvider if (plugin instanceof PermissionsProvider
|| (name.equalsIgnoreCase("Permissions") && || (name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges))) { NijiPermissionsResolver.checkRealNijiPerms(manager.ignoreNijiPermsBridges)) ||
name.equalsIgnoreCase("PermissionsEx")) {
manager.findResolver(); manager.findResolver();
manager.load(); manager.load();
} }