From 43b8c2cd9b7188214b944c794df809b984804418 Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 31 Aug 2013 23:00:49 -0700 Subject: [PATCH] Update PEX WEPIF resolver to use superperms where possible --- .../com/sk89q/wepif/DinnerPermsResolver.java | 9 +-- .../sk89q/wepif/PermissionsExResolver.java | 56 ++++++++----------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java b/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java index ec1ec504d..866da3a4b 100644 --- a/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java +++ b/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java @@ -32,8 +32,8 @@ import java.util.List; public class DinnerPermsResolver implements PermissionsResolver { - private static final String GROUP_PREFIX = "group."; - private final Server server; + public static final String GROUP_PREFIX = "group."; + protected final Server server; public DinnerPermsResolver(Server server) { this.server = server; @@ -115,7 +115,7 @@ public class DinnerPermsResolver implements PermissionsResolver { } return groupNames.toArray(new String[groupNames.size()]); } - + public Permissible getPermissible(OfflinePlayer offline) { if (offline == null) return null; Permissible perm = null; @@ -130,7 +130,8 @@ public class DinnerPermsResolver implements PermissionsResolver { /** * Checks the permission from dinnerperms - * @param perms Permissible to check for + * + * @param perms Permissible to check for * @param permission The permission to check * @return -1 if the permission is explicitly denied, 1 if the permission is allowed, * 0 if the permission is denied by a default. diff --git a/src/main/java/com/sk89q/wepif/PermissionsExResolver.java b/src/main/java/com/sk89q/wepif/PermissionsExResolver.java index 106a5085d..19a65323c 100644 --- a/src/main/java/com/sk89q/wepif/PermissionsExResolver.java +++ b/src/main/java/com/sk89q/wepif/PermissionsExResolver.java @@ -23,13 +23,12 @@ import com.sk89q.util.yaml.YAMLProcessor; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.entity.Player; - +import org.bukkit.permissions.Permissible; import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.PermissionUser; -public class PermissionsExResolver implements PermissionsResolver { +public class PermissionsExResolver extends DinnerPermsResolver { private final PermissionManager manager; - private final Server server; public static PermissionsResolver factory(Server server, YAMLProcessor config) { try { @@ -46,42 +45,21 @@ public class PermissionsExResolver implements PermissionsResolver { } public PermissionsExResolver(Server server, PermissionManager manager) { - this.server = server; + super(server); this.manager = manager; } - public void load() { - - } - - public boolean hasPermission(String name, String permission) { - Player player = server.getPlayerExact(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(); - } - public boolean hasPermission(OfflinePlayer player, String permission) { - Player onlinePlayer = player.getPlayer(); - return manager.has(player.getName(), permission, onlinePlayer == null ? null : onlinePlayer.getWorld().getName()); + Permissible permissible = getPermissible(player); + if (permissible == null) { + return manager.has(player.getName(), permission, null); + } else { + return permissible.hasPermission(permission); + } } public boolean hasPermission(String worldName, OfflinePlayer player, String permission) { @@ -89,11 +67,23 @@ public class PermissionsExResolver implements PermissionsResolver { } public boolean inGroup(OfflinePlayer player, String group) { - return inGroup(player.getName(), group); + if (getPermissible(player) == null) { + return manager.getUser(player.getName()).inGroup(group); + } else { + return hasPermission(player, GROUP_PREFIX + group); + } } public String[] getGroups(OfflinePlayer player) { - return getGroups(player.getName()); + if (getPermissible(player) == null) { + PermissionUser user = manager.getUser(player.getName()); + if (user == null) { + return new String[0]; + } + return user.getGroupsNames(); + } else { + return super.getGroups(player); + } } public String getDetectionMessage() {