mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Fixed default permissions with the built-in permission resolvers.
This commit is contained in:
parent
01fa16aa54
commit
ecb2942f1d
@ -29,6 +29,7 @@ import org.bukkit.util.config.Configuration;
|
|||||||
public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
private Map<String,Set<String>> userPermissionsCache;
|
private Map<String,Set<String>> userPermissionsCache;
|
||||||
|
private Set<String> defaultPermissionsCache;
|
||||||
private Map<String,Set<String>> userGroups;
|
private Map<String,Set<String>> userGroups;
|
||||||
|
|
||||||
public ConfigurationPermissionsResolver(Configuration config) {
|
public ConfigurationPermissionsResolver(Configuration config) {
|
||||||
@ -38,6 +39,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
public void load() {
|
public void load() {
|
||||||
userGroups = new HashMap<String,Set<String>>();
|
userGroups = new HashMap<String,Set<String>>();
|
||||||
userPermissionsCache = 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>>();
|
Map<String,Set<String>> userGroupPermissions = new HashMap<String,Set<String>>();
|
||||||
|
|
||||||
@ -51,6 +53,10 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
if (permissions.size() > 0) {
|
if (permissions.size() > 0) {
|
||||||
Set<String> groupPerms = new HashSet<String>(permissions);
|
Set<String> groupPerms = new HashSet<String>(permissions);
|
||||||
userGroupPermissions.put(key, groupPerms);
|
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) {
|
public boolean hasPermission(String player, String permission) {
|
||||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
return false;
|
return defaultPermissionsCache.contains(permission)
|
||||||
|
|| defaultPermissionsCache.contains("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
return perms.contains("*") || perms.contains(permission);
|
return perms.contains("*") || perms.contains(permission);
|
||||||
|
@ -31,6 +31,7 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class FlatFilePermissionsResolver implements PermissionsResolver {
|
public class FlatFilePermissionsResolver implements PermissionsResolver {
|
||||||
private Map<String,Set<String>> userPermissionsCache;
|
private Map<String,Set<String>> userPermissionsCache;
|
||||||
|
private Set<String> defaultPermissionsCache;
|
||||||
private Map<String,Set<String>> userGroups;
|
private Map<String,Set<String>> userGroups;
|
||||||
|
|
||||||
public FlatFilePermissionsResolver() {
|
public FlatFilePermissionsResolver() {
|
||||||
@ -90,8 +91,13 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
public void load() {
|
public void load() {
|
||||||
userGroups = new HashMap<String,Set<String>>();
|
userGroups = new HashMap<String,Set<String>>();
|
||||||
userPermissionsCache = new HashMap<String,Set<String>>();
|
userPermissionsCache = new HashMap<String,Set<String>>();
|
||||||
|
defaultPermissionsCache = new HashSet<String>();
|
||||||
|
|
||||||
Map<String,Set<String>> userGroupPermissions = loadGroupPermissions();
|
Map<String,Set<String>> userGroupPermissions = loadGroupPermissions();
|
||||||
|
|
||||||
|
if (userGroupPermissions.containsKey("default")) {
|
||||||
|
defaultPermissionsCache = userGroupPermissions.get("default");
|
||||||
|
}
|
||||||
|
|
||||||
File file = new File("perms_users.txt");
|
File file = new File("perms_users.txt");
|
||||||
FileReader input = null;
|
FileReader input = null;
|
||||||
@ -149,7 +155,8 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
public boolean hasPermission(String player, String permission) {
|
public boolean hasPermission(String player, String permission) {
|
||||||
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
return false;
|
return defaultPermissionsCache.contains(permission)
|
||||||
|
|| defaultPermissionsCache.contains("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
return perms.contains("*") || perms.contains(permission);
|
return perms.contains("*") || perms.contains(permission);
|
||||||
|
Loading…
Reference in New Issue
Block a user