Fixed default permissions with the built-in permission resolvers.

This commit is contained in:
sk89q 2011-01-21 17:53:27 -08:00
parent 01fa16aa54
commit ecb2942f1d
2 changed files with 16 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.bukkit.util.config.Configuration;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private Configuration config;
private Map<String,Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String,Set<String>> userGroups;
public ConfigurationPermissionsResolver(Configuration config) {
@ -38,6 +39,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
public void load() {
userGroups = new HashMap<String,Set<String>>();
userPermissionsCache = new HashMap<String,Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String,Set<String>> userGroupPermissions = new HashMap<String,Set<String>>();
@ -51,6 +53,10 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
if (permissions.size() > 0) {
Set<String> groupPerms = new HashSet<String>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
defaultPermissionsCache.addAll(permissions);
}
}
}
}
@ -90,7 +96,8 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
public boolean hasPermission(String player, String permission) {
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return false;
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);

View File

@ -31,6 +31,7 @@ import java.util.HashMap;
public class FlatFilePermissionsResolver implements PermissionsResolver {
private Map<String,Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String,Set<String>> userGroups;
public FlatFilePermissionsResolver() {
@ -90,9 +91,14 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
public void load() {
userGroups = new HashMap<String,Set<String>>();
userPermissionsCache = new HashMap<String,Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String,Set<String>> userGroupPermissions = loadGroupPermissions();
if (userGroupPermissions.containsKey("default")) {
defaultPermissionsCache = userGroupPermissions.get("default");
}
File file = new File("perms_users.txt");
FileReader input = null;
@ -149,7 +155,8 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
public boolean hasPermission(String player, String permission) {
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return false;
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);