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
This commit is contained in:
ElgarL 2012-01-30 14:41:19 +00:00
parent 2c8aa20542
commit 5b4966c888
3 changed files with 54 additions and 31 deletions

View file

@ -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.
- 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

View file

@ -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

View file

@ -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())