summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager
diff options
context:
space:
mode:
authorElgarL <ElgarL@palmergames.com>2012-01-30 14:41:19 +0000
committerElgarL <ElgarL@palmergames.com>2012-01-30 14:41:19 +0000
commit5b4966c8883609b40dced835a0a38935df063f30 (patch)
treee75d6984f494d0d360f3da3e5ddc3bdf0d786ce2 /EssentialsGroupManager
parent2c8aa20542b6fbb1555c11e9cd6485534beee39d (diff)
downloadEssentials-5b4966c8883609b40dced835a0a38935df063f30.tar
Essentials-5b4966c8883609b40dced835a0a38935df063f30.tar.gz
Essentials-5b4966c8883609b40dced835a0a38935df063f30.tar.lz
Essentials-5b4966c8883609b40dced835a0a38935df063f30.tar.xz
Essentials-5b4966c8883609b40dced835a0a38935df063f30.zip
Auto sort permissions on load to speed up population of superperms.
Negating a parent node after adding all nodes with * will now correctly remove all child nodes of that parent before populating superperms. eg. - '*' - -vanish.* - vanish.standard
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r--EssentialsGroupManager/src/Changelog.txt8
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java56
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java21
3 files changed, 54 insertions, 31 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index 41b5613af..c3dce16d9 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -125,4 +125,10 @@ v 1.9:
- Fixed an infinite loop error when using '/manudel' on a logged in player. It caused setDefaultGroup to trigger a bukkit update when no GM User existed yet.
- do not allow inherited permissions to negate higher perms.
- Fixed a bug when pushing superperms in the wrong order.
- - Fix players retaining permissions when demoted. \ No newline at end of file
+ - Fix players retaining permissions when demoted.
+ - Auto sort permissions on load to speed up population of superperms.
+ - Negating a parent node after adding all nodes with * will now correctly remove all child nodes of that parent before populating superperms.
+ eg.
+ - '*'
+ - -vanish.*
+ - vanish.standard \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index 3cbfbd50b..4fe1daaa5 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -451,7 +451,7 @@ public class WorldDataHolder {
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
Group thisGrp = ph.createGroup(groupKey);
if (thisGrp == null) {
- throw new IllegalArgumentException("I think this user was declared more than once: " + groupKey + " in file: " + groupsFile.getPath());
+ throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath());
}
if (thisGroupNode.get("default") == null) {
thisGroupNode.put("default", false);
@@ -467,20 +467,22 @@ public class WorldDataHolder {
//PERMISSIONS NODE
if (thisGroupNode.get("permissions") == null) {
thisGroupNode.put("permissions", new ArrayList<String>());
- }
- if (thisGroupNode.get("permissions") instanceof List) {
- for (Object o : ((List) thisGroupNode.get("permissions"))) {
- try {
- thisGrp.addPermission(o.toString());
- } catch (NullPointerException e) {
- // Ignore this entry as it's null.
- //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
- }
- }
- } else if (thisGroupNode.get("permissions") instanceof String) {
- thisGrp.addPermission((String) thisGroupNode.get("permissions"));
} else {
- throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
+ if (thisGroupNode.get("permissions") instanceof List) {
+ for (Object o : ((List) thisGroupNode.get("permissions"))) {
+ try {
+ thisGrp.addPermission(o.toString());
+ } catch (NullPointerException e) {
+ // Ignore this entry as it's null.
+ //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
+ }
+ }
+ } else if (thisGroupNode.get("permissions") instanceof String) {
+ thisGrp.addPermission((String) thisGroupNode.get("permissions"));
+ } else {
+ throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
+ }
+ thisGrp.sortPermissions();
}
//INFO NODE
@@ -581,18 +583,20 @@ public class WorldDataHolder {
}
if (thisUserNode.get("permissions") == null) {
thisUserNode.put("permissions", new ArrayList<String>());
- }
- if (thisUserNode.get("permissions") instanceof List) {
- for (Object o : ((List) thisUserNode.get("permissions"))) {
- thisUser.addPermission(o.toString());
- }
- } else if (thisUserNode.get("permissions") instanceof String) {
- try {
- thisUser.addPermission(thisUserNode.get("permissions").toString());
- } catch (NullPointerException e) {
- // Ignore this entry as it's null.
- //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath());
- }
+ } else {
+ if (thisUserNode.get("permissions") instanceof List) {
+ for (Object o : ((List) thisUserNode.get("permissions"))) {
+ thisUser.addPermission(o.toString());
+ }
+ } else if (thisUserNode.get("permissions") instanceof String) {
+ try {
+ thisUser.addPermission(thisUserNode.get("permissions").toString());
+ } catch (NullPointerException e) {
+ // Ignore this entry as it's null.
+ //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath());
+ }
+ }
+ thisUser.sortPermissions();
}
//SUBGROUPS LOADING
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index 2e008e223..7436bec70 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -153,15 +153,23 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
private Set<String> populatePerms (List<String> perms, boolean includeChildren) {
Set<String> permArray = new HashSet<String>();
+ Boolean allPerms = false;
- // Allow * node to populate ALL perms in Bukkit.
+ // Allow * node to populate ALL permissions to Bukkit.
if (perms.contains("*")) {
permArray.addAll(GroupManager.BukkitPermissions.getAllRegisteredPermissions(includeChildren));
+ allPerms = true;
}
for (String perm : perms) {
if (!perm.equalsIgnoreCase("*")) {
+
+ /**
+ * all permission sets are passed here pre-sorted, alphabetically.
+ * This means negated nodes will be processed before all permissions
+ * other than *.
+ */
boolean negated = false;
if (perm.startsWith("-"))
negated = true;
@@ -172,12 +180,17 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if ((negated) && (permArray.contains(perm.substring(1))))
permArray.remove(perm.substring(1));
- if (includeChildren) {
+ /**
+ * Process child nodes if required,
+ * or this is a negated node AND we used * to include all permissions,
+ * in which case we need to remove all children of that node.
+ */
+ if ((includeChildren) || (negated && allPerms)) {
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>());
if (children != null) {
- if (negated) {
+ if (negated || (negated && allPerms)) {
// Remove children of negated nodes
for (String child : children.keySet())
@@ -185,7 +198,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if (permArray.contains(child))
permArray.remove(child);
- } else {
+ } else if (!negated){
// Add child nodes
for (String child : children.keySet())