mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Added PermissionsEx support to WEPIF.
This commit is contained in:
parent
da6e6da024
commit
84ed4bf4c3
2
pom.xml
2
pom.xml
@ -34,7 +34,7 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>dummypermscompat</artifactId>
|
||||
<version>1.3</version>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Bukkit -->
|
||||
|
@ -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;
|
||||
@ -127,10 +128,6 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
||||
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)
|
||||
return true;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
@ -185,4 +196,8 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
||||
return isUpdated;
|
||||
}
|
||||
|
||||
public static class MissingPluginException extends Exception {
|
||||
private static final long serialVersionUID = 7044832912491608706L;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user