From c3225d16071564f2a1ad52f4c3c4d69ca38eabe3 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 5 Apr 2012 21:06:48 +0100 Subject: Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../anjocaido/groupmanager/permissions/BukkitPermissions.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c5fe5564d..2cfe57f62 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -163,4 +163,5 @@ v 1.9: - Prevent Null entries in group inheritance from throwing errors. v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. \ No newline at end of file + - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. + - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 5c711351e..6df18cb05 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -351,7 +351,14 @@ public class BukkitPermissions { */ private void removeAttachment(Player player) { if (attachments.containsKey(player)) { - player.removeAttachment(attachments.get(player)); + try { + player.removeAttachment(attachments.get(player)); + } catch (IllegalArgumentException e) { + /* + * Failed to remove attachment + * This usually means Bukkit no longer know of it. + */ + } attachments.remove(player); } } -- cgit v1.2.3 From 55433e2288238d06a35fe1a81e832d2510d91429 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 6 Apr 2012 12:53:36 +0100 Subject: Remove all permission attachments when performing a manload or restart. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 3 +++ .../anjocaido/groupmanager/permissions/BukkitPermissions.java | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 2cfe57f62..a9355e608 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -164,4 +164,5 @@ v 1.9: v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). \ No newline at end of file + - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). + - Remove all permission attachments when performing a manload or restart. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 8bd346735..d1c62d4de 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -106,6 +106,9 @@ public class GroupManager extends JavaPlugin { } WorldEvents = null; + + // Remove all attachments before clearing + BukkitPermissions.removeAllAttachments(); BukkitPermissions = null; // EXAMPLE: Custom code, here we just output some info so we can check that diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 6df18cb05..3b66c1eb9 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -362,6 +362,15 @@ public class BukkitPermissions { attachments.remove(player); } } + + /** + * Remove all attachments in case of a restart or reload. + */ + public void removeAllAttachments() { + + for (Player player : attachments.keySet()) + removeAttachment(player); + } /** * Player events tracked to cause Superperms updates -- cgit v1.2.3 From 3a9f1f098892e2089b33891d5a18b0515a0f909f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 11:47:07 +0100 Subject: Expand 'manwhois' to also list a users subgroups. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index a9355e608..42b7b989c 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -165,4 +165,5 @@ v 2.0: - Fix GM reporting of permission inheritance to retain the correct order. Lower inheritance groups can no longer negate a higher groups permissions. - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - - Remove all permission attachments when performing a manload or restart. \ No newline at end of file + - Remove all permission attachments when performing a manload or restart. + - Expand 'manwhois' to also list a users subgroups. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index d1c62d4de..76babb1ec 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1398,6 +1398,16 @@ public class GroupManager extends JavaPlugin { // Seems OK sender.sendMessage(ChatColor.YELLOW + "Name: " + ChatColor.GREEN + auxUser.getName()); sender.sendMessage(ChatColor.YELLOW + "Group: " + ChatColor.GREEN + auxUser.getGroup().getName()); + // Compile a list of subgroups + auxString = ""; + for (String subGroup : auxUser.subGroupListStringCopy()) { + auxString += subGroup + ", "; + } + if (auxString.lastIndexOf(",") > 0) { + auxString = auxString.substring(0, auxString.lastIndexOf(",")); + sender.sendMessage(ChatColor.YELLOW + "subgroups: " + auxString); + } + sender.sendMessage(ChatColor.YELLOW + "Overloaded: " + ChatColor.GREEN + dataHolder.isOverloaded(auxUser.getName())); auxGroup = dataHolder.surpassOverload(auxUser.getName()).getGroup(); if (!auxGroup.equals(auxUser.getGroup())) { -- cgit v1.2.3 From 159a140b46ed783899815db91778228535a31107 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 17:21:48 +0100 Subject: Fix a concurrent modification error when removing all attachments. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../org/anjocaido/groupmanager/permissions/BukkitPermissions.java | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 42b7b989c..f699c3f6f 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -166,4 +166,5 @@ v 2.0: - Fix an error I caused trying to modify an unmodifiable list when parsing '*' permissions. - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - Remove all permission attachments when performing a manload or restart. - - Expand 'manwhois' to also list a users subgroups. \ No newline at end of file + - Expand 'manwhois' to also list a users subgroups. + - Fix a concurrent modification error when removing all attachments. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 3b66c1eb9..51f019efc 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -20,6 +20,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -368,8 +369,11 @@ public class BukkitPermissions { */ public void removeAllAttachments() { - for (Player player : attachments.keySet()) - removeAttachment(player); + Iterator itr = attachments.keySet().iterator(); + + while (itr.hasNext()){ + removeAttachment(itr.next()); + } } /** -- cgit v1.2.3 From 60eac790960adac6a1a1b9e7f8e113af3901e444 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 19:24:46 +0100 Subject: Better handling of errors in user and group yml's. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../groupmanager/dataholder/WorldDataHolder.java | 407 ++++++++++++--------- 2 files changed, 232 insertions(+), 178 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index f699c3f6f..c6c3853fb 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -167,4 +167,5 @@ v 2.0: - Don't throw errors when attempting to remove permission attachments (bukkit will have already removed it). - Remove all permission attachments when performing a manload or restart. - Expand 'manwhois' to also list a users subgroups. - - Fix a concurrent modification error when removing all attachments. \ No newline at end of file + - Fix a concurrent modification error when removing all attachments. + - Better handling of errors in user and group yml's. \ 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 cee2ec0b8..135417068 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -14,6 +14,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -459,98 +460,140 @@ public class WorldDataHolder { //PROCESS GROUPS FILE Map> inheritance = new HashMap>(); try { + /* + * Fetch all child nodes under the 'groups' entry. + */ Map allGroupsNode = (Map) groupsRootDataNode.get("groups"); - try { - for (String groupKey : allGroupsNode.keySet()) { - Map thisGroupNode = (Map) allGroupsNode.get(groupKey); - Group thisGrp = ph.createGroup(groupKey); - if (thisGrp == null) { - 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); - } - if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); - } - ph.setDefaultGroup(thisGrp); - } - - //PERMISSIONS NODE - try { - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); + Iterator groupItr = allGroupsNode.keySet().iterator(); + String groupKey; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupKey = groupItr.next(); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type for group entry (" + groupCount + ") in file: " + groupsFile.getPath()); + } + + /* + * Fetch this groups child nodes + */ + Map thisGroupNode = (Map) allGroupsNode.get(groupKey); + /* + * Create a new group with this name + * in the assigned data source. + */ + Group thisGrp = ph.createGroup(groupKey); + + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + } + /* + * If no default node is found set it as false. + */ + if (thisGroupNode.get("default") == null) { + thisGroupNode.put("default", false); + } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + /* + * Set this as the default group. + * Warn if some other group has already claimed that position. + */ + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + } + ph.setDefaultGroup(thisGrp); + } + + //PERMISSIONS NODE + try { + /* + * If no permissions node is found, or it's empty + * set an empty permission list + */ + if (thisGroupNode.get("permissions") == null) { + thisGroupNode.put("permissions", new ArrayList()); + } else { + /* + * There is a permission list Which seems to hold some data + */ + if (thisGroupNode.get("permissions") instanceof List) { + /* + * Check each entry and add it as a new permission. + */ + for (Object o : ((List) thisGroupNode.get("permissions"))) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); + } catch (NullPointerException e) { + // Ignore this entry as it's null. It can be safely dropped + } + } + } else if (thisGroupNode.get("permissions") instanceof String) { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); } else { - if (thisGroupNode.get("permissions") instanceof List) { - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - 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) { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); - } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - thisGrp.sortPermissions(); + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); - } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e1) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + /* + * Sort all permissions so they are in the correct order for checking. + */ + thisGrp.sortPermissions(); } - - //END INFO NODE - - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); - } - inheritance.get(groupKey).add(grp); - - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e2) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath()); - } + } catch (Exception e) { + throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + + //INFO NODE + try { + if (thisGroupNode.get("info") instanceof Map) { + Map infoNode = (Map) thisGroupNode.get("info"); + if (infoNode != null) { + thisGrp.setVariables(infoNode); + } + } else + throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e1) { + throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + + //END INFO NODE + + try { + if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { + Object inheritNode = thisGroupNode.get("inheritance"); + if (inheritNode == null) { + thisGroupNode.put("inheritance", new ArrayList()); + } else if (inheritNode instanceof List) { + List groupsInh = (List) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List thisInherits = new ArrayList(); + inheritance.put(groupKey, thisInherits); + } + inheritance.get(groupKey).add(grp); + + } + } + }else + throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception e2) { + throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } + } + } catch (Exception ex) { ex.printStackTrace(); throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); @@ -614,97 +657,107 @@ public class WorldDataHolder { Map allUsersNode = (Map) usersRootDataNode.get("users"); // Load users if the file is NOT empty - if (allUsersNode != null) - try { - for (String usersKey : allUsersNode.keySet()) { - Map thisUserNode = null; - try { - thisUserNode = (Map) allUsersNode.get(usersKey); - } catch (Exception ex) { - throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); - } - User thisUser = ph.createUser(usersKey); - if (thisUser == null) { - throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); - } - if (thisUserNode.get("permissions") == null) { - thisUserNode.put("permissions", new ArrayList()); - } else { - if (thisUserNode.get("permissions") instanceof List) { - for (Object o : ((List) thisUserNode.get("permissions"))) { - /* - * Only add this permission if it's not empty - */ - if (!o.toString().isEmpty()) - thisUser.addPermission(o.toString()); - } - } else if (thisUserNode.get("permissions") instanceof String) { - try { - /* - * Only add this permission if it's not empty - */ - if (!thisUserNode.get("permissions").toString().isEmpty()) - 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 - if (thisUserNode.get("subgroups") == null) { - thisUserNode.put("subgroups", new ArrayList()); - } - if (thisUserNode.get("subgroups") instanceof List) { - for (Object o : ((List) thisUserNode.get("subgroups"))) { - Group subGrp = ph.getGroup(o.toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - } else if (thisUserNode.get("subgroups") instanceof String) { - Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); - if (subGrp != null) { - thisUser.addSubGroup(subGrp); - } else { - GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); - } - } - - - //USER INFO NODE - - //INFO NODE - if (thisUserNode.get("info") instanceof Map) { - Map infoNode = (Map) thisUserNode.get("info"); - if (infoNode != null) { - thisUser.setVariables(infoNode); - } - } else if (thisUserNode.get("info") != null) - throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); - - //END INFO NODE - - - if (thisUserNode.get("group") != null) { - Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); - if (hisGroup == null) { - GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); - hisGroup = ph.getDefaultGroup(); - //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); + if (allUsersNode != null) { + + Iterator usersItr = allUsersNode.keySet().iterator(); + String usersKey; + Integer userCount = 0; + + while (usersItr.hasNext()) { + try { + userCount++; + // Attempt to fetch the next user name. + usersKey = usersItr.next(); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath()); + } + + Map thisUserNode = null; + try { + thisUserNode = (Map) allUsersNode.get(usersKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); + } + User thisUser = ph.createUser(usersKey); + if (thisUser == null) { + throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey + " in file: " + usersFile.getPath()); + } + if (thisUserNode.get("permissions") == null) { + thisUserNode.put("permissions", new ArrayList()); + } else { + if (thisUserNode.get("permissions") instanceof List) { + for (Object o : ((List) thisUserNode.get("permissions"))) { + /* + * Only add this permission if it's not empty + */ + if (!o.toString().isEmpty()) + thisUser.addPermission(o.toString()); } - thisUser.setGroup(hisGroup); - } else { - thisUser.setGroup(ph.getDefaultGroup()); + } else if (thisUserNode.get("permissions") instanceof String) { + try { + /* + * Only add this permission if it's not empty + */ + if (!thisUserNode.get("permissions").toString().isEmpty()) + 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()); + } } - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + usersFile.getPath()); - } + thisUser.sortPermissions(); + } + + //SUBGROUPS LOADING + if (thisUserNode.get("subgroups") == null) { + thisUserNode.put("subgroups", new ArrayList()); + } + if (thisUserNode.get("subgroups") instanceof List) { + for (Object o : ((List) thisUserNode.get("subgroups"))) { + Group subGrp = ph.getGroup(o.toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + } else if (thisUserNode.get("subgroups") instanceof String) { + Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); + if (subGrp != null) { + thisUser.addSubGroup(subGrp); + } else { + GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); + } + } + + + //USER INFO NODE + + //INFO NODE + if (thisUserNode.get("info") instanceof Map) { + Map infoNode = (Map) thisUserNode.get("info"); + if (infoNode != null) { + thisUser.setVariables(infoNode); + } + } else if (thisUserNode.get("info") != null) + throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); + + //END INFO NODE + + + if (thisUserNode.get("group") != null) { + Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); + if (hisGroup == null) { + GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath()); + hisGroup = ph.getDefaultGroup(); + //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); + } + thisUser.setGroup(hisGroup); + } else { + thisUser.setGroup(ph.getDefaultGroup()); + } + } + } ph.removeUsersChangedFlag(); // Update the LastModified time. -- cgit v1.2.3 From cfda56697b7b077b6c7512936ccda8f50f638bcc Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 7 Apr 2012 21:30:49 +0100 Subject: Added missing confirmation message on '/manload'. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index c6c3853fb..0a9708773 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -168,4 +168,5 @@ v 2.0: - Remove all permission attachments when performing a manload or restart. - Expand 'manwhois' to also list a users subgroups. - Fix a concurrent modification error when removing all attachments. - - Better handling of errors in user and group yml's. \ No newline at end of file + - Better handling of errors in user and group yml's. + - Added missing confirmation message on '/manload'. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 76babb1ec..e10675e8d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -1590,6 +1590,8 @@ public class GroupManager extends JavaPlugin { */ onDisable(); onEnable(); + + sender.sendMessage("All settings and worlds were reloaded!"); } /** -- cgit v1.2.3 From 74534d7781850f4cbb854c084911503c12f13cdf Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 17:02:50 +0100 Subject: Properly fix concurrent modification when removing all attachments. --- .../groupmanager/permissions/BukkitPermissions.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java index 51f019efc..516679544 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java @@ -357,7 +357,7 @@ public class BukkitPermissions { } catch (IllegalArgumentException e) { /* * Failed to remove attachment - * This usually means Bukkit no longer know of it. + * This usually means Bukkit no longer knows of it. */ } attachments.remove(player); @@ -372,8 +372,17 @@ public class BukkitPermissions { Iterator itr = attachments.keySet().iterator(); while (itr.hasNext()){ - removeAttachment(itr.next()); + Player player = itr.next(); + try { + player.removeAttachment(attachments.get(player)); + } catch (IllegalArgumentException e) { + /* + * Failed to remove attachment + * This usually means Bukkit no longer knows of it. + */ + } } + attachments.clear(); } /** -- cgit v1.2.3 From 90dc7b628727cb976bb05dbd692d52c752df068d Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 20:40:04 +0100 Subject: Stop the error on shutdown if GM failed to load at startup. GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. Startup errors will now lock out ALL commands other than '/manload' --- EssentialsGroupManager/src/Changelog.txt | 5 +- .../org/anjocaido/groupmanager/GroupManager.java | 170 ++++++++++++++++----- .../org/anjocaido/groupmanager/utils/Tasks.java | 41 +++++ 3 files changed, 173 insertions(+), 43 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0a9708773..2c38acf1b 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -169,4 +169,7 @@ v 2.0: - Expand 'manwhois' to also list a users subgroups. - Fix a concurrent modification error when removing all attachments. - Better handling of errors in user and group yml's. - - Added missing confirmation message on '/manload'. \ No newline at end of file + - Added missing confirmation message on '/manload'. + - Stop the error on shutdown if GM failed to load at startup. + - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. + - Startup errors will now lock out ALL commands other than '/manload' \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index e10675e8d..b39b640a4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -14,6 +14,7 @@ import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; @@ -60,6 +61,9 @@ public class GroupManager extends JavaPlugin { private Map selectedWorlds = new HashMap(); private WorldsHolder worldsHolder; private boolean validateOnlinePlayer = true; + + private String lastError = ""; + /** * @return the validateOnlinePlayer */ @@ -108,8 +112,10 @@ public class GroupManager extends JavaPlugin { WorldEvents = null; // Remove all attachments before clearing - BukkitPermissions.removeAllAttachments(); - BukkitPermissions = null; + if (BukkitPermissions != null) { + BukkitPermissions.removeAllAttachments(); + BukkitPermissions = null; + } // EXAMPLE: Custom code, here we just output some info so we can check that // all is well @@ -118,53 +124,108 @@ public class GroupManager extends JavaPlugin { GroupManager.logger.removeHandler(ch); } - @Override + //@Override public void onEnable() { - GroupManager.logger.setUseParentHandlers(false); - ch = new GMLoggerHandler(); - GroupManager.logger.addHandler(ch); - logger.setLevel(Level.ALL); - - // Create the backup folder, if it doesn't exist. - prepareFileFields(); - // Load the config.yml - prepareConfig(); - // Load the global groups - globalGroups = new GlobalGroups(this); - worldsHolder = new WorldsHolder(this); + + try { + lastError = ""; + + GroupManager.logger.setUseParentHandlers(false); + ch = new GMLoggerHandler(); + GroupManager.logger.addHandler(ch); + logger.setLevel(Level.ALL); + + // Create the backup folder, if it doesn't exist. + prepareFileFields(); + // Load the config.yml + prepareConfig(); + // Load the global groups + globalGroups = new GlobalGroups(this); + worldsHolder = new WorldsHolder(this); + + + PluginDescriptionFile pdfFile = this.getDescription(); + if (worldsHolder == null) { + GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); + this.getServer().getPluginManager().disablePlugin(this); + throw new IllegalStateException("An error ocurred while loading GroupManager"); + } + + // Set a few defaults (reloads) + setLoaded(false); + + // Initialize the world listener and bukkit permissions to handle + // events. + WorldEvents = new GMWorldListener(this); + BukkitPermissions = new BukkitPermissions(this); + + enableScheduler(); + + /* + * Schedule a Bukiit Permissions update for 1 tick later. All plugins + * will be loaded by then + */ + + if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { + GroupManager.logger.severe("Could not schedule superperms Update."); + setLoaded(true); + } + + System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); + + // Register as a service + this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); + } catch (Exception ex) { + + /* + * Store the error and write to the log. + */ + saveErrorLog(ex); + /* + * Throw an error so Bukkit knows about it. + */ + throw new IllegalArgumentException(ex.getMessage(),ex); - PluginDescriptionFile pdfFile = this.getDescription(); - if (worldsHolder == null) { - GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!"); - this.getServer().getPluginManager().disablePlugin(this); - throw new IllegalStateException("An error ocurred while loading GroupManager"); } - - // Set a few defaults (reloads) - setLoaded(false); + } + + /** + * Write an error.log + * + * @param ex + */ + private void saveErrorLog(Exception ex) { - // Initialize the world listener and bukkit permissions to handle - // events. - WorldEvents = new GMWorldListener(this); - BukkitPermissions = new BukkitPermissions(this); - - enableScheduler(); - - /* - * Schedule a Bukiit Permissions update for 1 tick later. All plugins - * will be loaded by then - */ - - if (getServer().getScheduler().scheduleSyncDelayedTask(this, new BukkitPermsUpdateTask(), 1) == -1) { - GroupManager.logger.severe("Could not schedule superperms Update."); - setLoaded(true); + if (!getDataFolder().exists()) { + getDataFolder().mkdirs(); + } + + lastError = ex.getMessage(); + + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("= ERROR REPORT START ="); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("=== PLEASE COPY AND PASTE THE ERROR.LOG FROM THE =="); + GroupManager.logger.severe("= GROUPMANAGER FOLDER TO AN ESSENTIALS DEVELOPER ="); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe(lastError); + GroupManager.logger.severe("==================================================="); + GroupManager.logger.severe("= ERROR REPORT ENDED ="); + GroupManager.logger.severe("==================================================="); + + // Append this error to the error log. + try { + String error = "=============================== GM ERROR LOG ===============================\n\n"; + error += Tasks.getStackTraceAsString(ex); + error += "\n============================================================================\n"; + + Tasks.appendStringToFile(error, (getDataFolder() + System.getProperty("file.separator") + "ERROR.LOG")); + } catch (IOException e) { + // Failed to write file. + e.printStackTrace(); } - System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!"); - - // Register as a service - this.getServer().getServicesManager().register(WorldsHolder.class, this.worldsHolder, this, ServicePriority.Lowest); } public static boolean isLoaded() { @@ -300,10 +361,17 @@ public class GroupManager extends JavaPlugin { Group senderGroup = null; User senderUser = null; boolean isOpOverride = config.isOpOverride(); + // DETERMINING PLAYER INFORMATION if (sender instanceof Player) { senderPlayer = (Player) sender; + + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName()); senderGroup = senderUser.getGroup(); isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op"))); @@ -313,6 +381,12 @@ public class GroupManager extends JavaPlugin { playerCanDo = true; } } else if (sender instanceof ConsoleCommandSender) { + + if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + isConsole = true; } @@ -1560,10 +1634,17 @@ public class GroupManager extends JavaPlugin { return true; case manload: + /** * Attempt to reload a specific world */ if (args.length > 0) { + + if (!lastError.isEmpty()) { + sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. Check the log and then try a '/manload'.)"); + return true; + } + auxString = ""; for (int i = 0; i < args.length; i++) { auxString += args[i]; @@ -1588,6 +1669,11 @@ public class GroupManager extends JavaPlugin { /** * Reload all settings and data as no world was specified. */ + + /* + * Reset the last error as we are attempting a fresh load. + */ + lastError = ""; onDisable(); onEnable(); diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java index f3defd94a..663da1123 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java @@ -4,12 +4,17 @@ */ package org.anjocaido.groupmanager.utils; +import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; @@ -17,11 +22,25 @@ import java.util.List; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; + /** * * @author gabrielcouto */ public abstract class Tasks { + + /** + * Gets the exception stack trace as a string. + * + * @param exception + * @return stack trace as a string + */ + public static String getStackTraceAsString(Exception exception) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + exception.printStackTrace(pw); + return sw.toString(); + } public static void copy(InputStream src, File dst) throws IOException { InputStream in = src; @@ -44,6 +63,28 @@ public abstract class Tasks { InputStream in = new FileInputStream(src); copy(in, dst); } + + /** + * Appends a string to a file + * + * @param data + * @param file + */ + public static void appendStringToFile(String data, String file) throws IOException { + + FileWriter outStream = new FileWriter("." + System.getProperty("file.separator") + file, true); + + BufferedWriter out = new BufferedWriter(outStream); + + data.replaceAll("\n", System.getProperty("line.separator")); + + out.append(new SimpleDateFormat("yyyy-MM-dd HH-mm").format(System.currentTimeMillis())); + out.append(System.getProperty("line.separator")); + out.append(data); + out.append(System.getProperty("line.separator")); + + out.close(); + } public static void removeOldFiles(GroupManager gm, File folder) { if (folder.isDirectory()) { -- cgit v1.2.3 From 06a4a7fbd2211af538bcff74553ee70daf9992fa Mon Sep 17 00:00:00 2001 From: ElgarL Date: Tue, 10 Apr 2012 20:48:34 +0100 Subject: Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 2c38acf1b..7c10cc3ac 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -172,4 +172,5 @@ v 2.0: - Added missing confirmation message on '/manload'. - Stop the error on shutdown if GM failed to load at startup. - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - - Startup errors will now lock out ALL commands other than '/manload' \ No newline at end of file + - Startup errors will now lock out ALL commands other than '/manload' + - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index b39b640a4..1177e3357 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -457,9 +457,18 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Review your arguments count! (/ | optional [world])"); return false; } - // Select the relevant world - dataHolder = worldsHolder.getWorldData((args.length == 3)? args[2]:Bukkit.getWorlds().get(0).getName()); - permissionHandler = dataHolder.getPermissionsHandler(); + + // Select the relevant world (if specified) + if (args.length == 3) { + dataHolder = worldsHolder.getWorldData(args[2]); + permissionHandler = dataHolder.getPermissionsHandler(); + } + + // Validating state of sender + if (dataHolder == null || permissionHandler == null) { + if (!setDefaultWorldHandler(sender)) + return true; + } if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) { return false; -- cgit v1.2.3 From 4047eb78952a21dac3773ebeea40a77e1db1e4ac Mon Sep 17 00:00:00 2001 From: ElgarL Date: Wed, 11 Apr 2012 19:10:28 +0100 Subject: Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. --- EssentialsGroupManager/src/Changelog.txt | 3 +- EssentialsGroupManager/src/globalgroups.yml | 186 ++++++++++++++------- EssentialsGroupManager/src/groups.yml | 23 ++- .../groupmanager/dataholder/WorldDataHolder.java | 10 +- 4 files changed, 146 insertions(+), 76 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 7c10cc3ac..b957f4515 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -173,4 +173,5 @@ v 2.0: - Stop the error on shutdown if GM failed to load at startup. - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - Startup errors will now lock out ALL commands other than '/manload' - - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. \ No newline at end of file + - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. + - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. \ No newline at end of file diff --git a/EssentialsGroupManager/src/globalgroups.yml b/EssentialsGroupManager/src/globalgroups.yml index 885c6675d..fa8808e00 100644 --- a/EssentialsGroupManager/src/globalgroups.yml +++ b/EssentialsGroupManager/src/globalgroups.yml @@ -1,5 +1,101 @@ +# These groups only contain permission nodes. +# +# **** You can NOT add anything other than permission nodes **** +# +# These collections are to be inherited in your different worlds groups.yml's +# They can also be added as one of a users subgroups, but NOT as a primary group. +# These collections are available to ALL group and user yml's. +# +# Add to and customize these groups to fit yoru needs. + groups: +# Permission nodes for GroupManager +# by ElgarL, snowleo, continued from gabrielcouto's original +# http://dev.bukkit.org/server-mods/essentials/ + + g:groupmanager_default: + permissions: + - groupmanager.notify.self + + g:groupmanager_moderator: + permissions: + - groupmanager.listgroups + - groupmanager.mandemote + - groupmanager.manpromote + - groupmanager.manselect + - groupmanager.manuadd + - groupmanager.manudel + - groupmanager.manwhois + - groupmanager.notify.other + + g:groupmanager_admin: + permissions: + - groupmanager.mantogglevalidate + - groupmanager.mansave + - groupmanager.mangcheckp + - groupmanager.manglistp + - groupmanager.manucheckp + - groupmanager.manulistp + +# Permission nodes for CraftBukkit +# by many devs and contributors +# http://dl.bukkit.org/ + + g:bukkit_default: + permissions: + - bukkit.broadcast.user + - -bukkit.command.plugins + + g:bukkit_moderator: + permissions: + - bukkit.command.ban + - bukkit.command.ban.ip + - bukkit.command.ban.player + - bukkit.command.gamemode + - bukkit.command.kick + - bukkit.command.unban + - bukkit.command.unban.ip + - bukkit.command.unban.player + + g:bukkit_admin: + permissions: + - bukkit.broadcast + - bukkit.broadcast.admin + - bukkit.command.give + - bukkit.command.help + - bukkit.command.kill + - bukkit.command.list + - bukkit.command.me + - -bukkit.command.op + - -bukkit.command.op.give + - -bukkit.command.op.take + - bukkit.command.plugins + - bukkit.command.reload + - bukkit.command.save + - bukkit.command.save.disable + - bukkit.command.save.enable + - bukkit.command.save.perform + - bukkit.command.say + - bukkit.command.stop + - bukkit.command.teleport + - bukkit.command.tell + - bukkit.command.time + - bukkit.command.time.add + - bukkit.command.time.set + - bukkit.command.version + - bukkit.command.whitelist + - bukkit.command.whitelist.add + - bukkit.command.whitelist.disable + - bukkit.command.whitelist.enable + - bukkit.command.whitelist.list + - bukkit.command.whitelist.reload + - bukkit.command.whitelist.remove + +# Permission nodes for Essentials +# by ementalo, snowleo, and KHobbits +# http://dev.bukkit.org/server-mods/essentials/ + g:essentials_default: permissions: - essentials.help @@ -8,7 +104,6 @@ groups: - essentials.motd - essentials.rules - essentials.spawn - - groupmanager.notify.self g:essentials_builder: permissions: @@ -101,14 +196,6 @@ groups: - essentials.weather - essentials.whois - essentials.world - - groupmanager.listgroups - - groupmanager.mandemote - - groupmanager.manpromote - - groupmanager.manselect - - groupmanager.manuadd - - groupmanager.manudel - - groupmanager.manwhois - - groupmanager.notify.other g:essentials_admin: permissions: @@ -118,62 +205,13 @@ groups: - -essentials.reloadall - -essentials.plugin - essentials.* - - groupmanager.mantogglevalidate - - groupmanager.mansave - - groupmanager.mangcheckp - - groupmanager.manglistp - - groupmanager.manucheckp - - groupmanager.manulistp - - g:bukkit_default: - permissions: - - bukkit.broadcast.user - - -bukkit.command.plugins - - g:bukkit_moderator: - permissions: - - bukkit.command.ban - - bukkit.command.ban.ip - - bukkit.command.ban.player - - bukkit.command.gamemode - - bukkit.command.kick - - bukkit.command.unban - - bukkit.command.unban.ip - - bukkit.command.unban.player - g:bukkit_admin: +# Permission nodes for Towny by ElgarL +# http://dev.bukkit.org/server-mods/towny-advanced/ + + g:towny_default: permissions: - - bukkit.broadcast - - bukkit.broadcast.admin - - bukkit.command.give - - bukkit.command.help - - bukkit.command.kill - - bukkit.command.list - - bukkit.command.me - - -bukkit.command.op - - -bukkit.command.op.give - - -bukkit.command.op.take - - bukkit.command.plugins - - bukkit.command.reload - - bukkit.command.save - - bukkit.command.save.disable - - bukkit.command.save.enable - - bukkit.command.save.perform - - bukkit.command.say - - bukkit.command.stop - - bukkit.command.teleport - - bukkit.command.tell - - bukkit.command.time - - bukkit.command.time.add - - bukkit.command.time.set - - bukkit.command.version - - bukkit.command.whitelist - - bukkit.command.whitelist.add - - bukkit.command.whitelist.disable - - bukkit.command.whitelist.enable - - bukkit.command.whitelist.list - - bukkit.command.whitelist.reload - - bukkit.command.whitelist.remove + - towny.chat.general g:towny_builder: permissions: @@ -224,4 +262,24 @@ groups: - towny.admin - -towny.wild.destroy.119 - -towny.wild.destroy.120 - - towny.chat.admin \ No newline at end of file + - towny.chat.admin + +# Permission nodes for VanishNoPacket by mbaxter +# http://dev.bukkit.org/server-mods/vanish/ + + g:vanish_moderator: + permissions: + - -vanish.* + - vanish.vanish + - vanish.smokin + - vanish.nofollow + - vanish.nopickup + - vanish.preventincomingdamage + - vanish.hooks.dynmap.alwayshidden + - vanish.hooks.essentials.hide + + g:vanish_admin: + permissions: + - vanish.silentjoin + - vanish.silentquit + - vanish.silentchests \ No newline at end of file diff --git a/EssentialsGroupManager/src/groups.yml b/EssentialsGroupManager/src/groups.yml index ec8b0422f..9c63ffd94 100644 --- a/EssentialsGroupManager/src/groups.yml +++ b/EssentialsGroupManager/src/groups.yml @@ -1,10 +1,12 @@ # Group inheritance -# any inherited groups prefixed with a g: are global groups -# These groups are defined in the globalgroups.yml -# and can be inherited in any worlds groups/users.yml. +# +# Any inherited groups prefixed with a g: are global groups +# and are inherited from the GlobalGroups.yml. # # Groups without the g: prefix are groups local to this world -# and defined in the this groups.yml file. +# and are defined in the this groups.yml file. +# +# Local group inheritances define your promotion tree when using 'manpromote/mandemote' groups: Default: @@ -12,8 +14,10 @@ groups: permissions: - -bukkit.command.kill inheritance: - - g:essentials_default + - g:groupmanager_default - g:bukkit_default + - g:essentials_default + - g:towny_default info: prefix: '&e' build: false @@ -34,9 +38,11 @@ groups: permissions: [] inheritance: - builder - - g:essentials_moderator + - g:groupmanager_moderator - g:bukkit_moderator + - g:essentials_moderator - g:towny_moderator + - g:vanish_moderator info: prefix: '&5' build: true @@ -46,9 +52,11 @@ groups: permissions: [] inheritance: - moderator - - g:essentials_admin + - g:groupmanager_admin - g:bukkit_admin + - g:essentials_admin - g:towny_admin + - g:vanish_admin info: prefix: '&c' build: true @@ -57,6 +65,7 @@ groups: default: false permissions: - '*' + - -vanish.* inheritance: - admin info: diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 135417068..8c974f34a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -809,12 +809,14 @@ public class WorldDataHolder { String newLine = System.getProperty("line.separator"); out.write("# Group inheritance" + newLine); - out.write("# any inherited groups prefixed with a g: are global groups" + newLine); - out.write("# These groups are defined in the globalgroups.yml" + newLine); - out.write("# and can be inherited in any worlds groups/users.yml." + newLine); + out.write("#" + newLine); + out.write("# Any inherited groups prefixed with a g: are global groups" + newLine); + out.write("# and are inherited from the GlobalGroups.yml." + newLine); out.write("#" + newLine); out.write("# Groups without the g: prefix are groups local to this world" + newLine); - out.write("# and defined in the this groups.yml file." + newLine); + out.write("# and are defined in the this groups.yml file." + newLine); + out.write("#" + newLine); + out.write("# Local group inheritances define your promotion tree when using 'manpromote/mandemote'" + newLine); out.write(newLine); yaml.dump(root, out); -- cgit v1.2.3 From c02a2c9dcac9008011399cfc7248c2e84e0d638f Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 11 Apr 2012 22:51:34 +0300 Subject: Prevent that a config file is loaded/saved by more than one thread. --- Essentials/src/com/earth2me/essentials/EssentialsConf.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 85c2bbd8c..b2cb1fd12 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -39,7 +39,7 @@ public class EssentialsConf extends YamlConfiguration this.configFile = configFile; } - public void load() + public synchronized void load() { configFile = configFile.getAbsoluteFile(); if (!configFile.getParentFile().exists()) @@ -356,7 +356,7 @@ public class EssentialsConf extends YamlConfiguration } @Override - public void save(final File file) throws IOException + public synchronized void save(final File file) throws IOException { if (file == null) { -- cgit v1.2.3 From 0d5e4321a9ab88e1cef6109c621cbc783e454642 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 12 Apr 2012 01:21:22 +0100 Subject: Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../org/anjocaido/groupmanager/GlobalGroups.java | 101 ++++--- .../groupmanager/dataholder/WorldDataHolder.java | 313 +++++++++++---------- 3 files changed, 234 insertions(+), 183 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index b957f4515..0bf6c47bf 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -174,4 +174,5 @@ v 2.0: - GroupManager will now generate it's own log (in the GM folder) to keep things tidy, but also to account of those players unable to find/access their server.log. - Startup errors will now lock out ALL commands other than '/manload' - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. - - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. \ No newline at end of file + - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. + - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index 0219a1a08..6fa8b0d1d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -8,6 +8,7 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -112,50 +113,70 @@ public class GlobalGroups { if (!GGroups.getKeys(false).isEmpty()) { // Read all global groups - Map allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); + Map allGroups = new HashMap(); + + try { + allGroups = (Map) GGroups.getConfigurationSection("groups").getValues(false); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", ex); + } // Load each groups permissions list. if (allGroups != null) { - try { - for (String groupName : allGroups.keySet()) { - Group newGroup = new Group(groupName.toLowerCase()); - Object element; - - // Permission nodes - element = GGroups.get("groups." + groupName + ".permissions"); - - if (element != null) - if (element instanceof List) { - try { - for (String node : (List) element) { - newGroup.addPermission(node); - } - } catch (ClassCastException e) { - throw new IllegalArgumentException("Invalid permission node for global group: " + groupName); - } - } else if (element instanceof String) { - newGroup.addPermission((String) element); - } else - throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); - - // Info nodes - element = GGroups.get("groups." + groupName + ".info"); - - if (element != null) - if (element instanceof MemorySection) { - Map vars = new HashMap(); - for (String key : ((MemorySection) element).getKeys(false)) { - vars.put(key, ((MemorySection) element).get(key)); - } - newGroup.setVariables(vars); - } else - throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); - - // Push a new group - addGroup(newGroup); + + Iterator groupItr = allGroups.keySet().iterator(); + String groupName; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupName = groupItr.next(); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid group name for GlobalGroup entry (" + groupCount + ") in file: " + GlobalGroupsFile.getPath(), ex); } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type, or bad indentation in GlobalGroups! "); + + Group newGroup = new Group(groupName.toLowerCase()); + Object element; + + // Permission nodes + element = GGroups.get("groups." + groupName + ".permissions"); + + if (element != null) + if (element instanceof List) { + try { + for (String node : (List) element) { + newGroup.addPermission(node); + } + } catch (ClassCastException ex) { + throw new IllegalArgumentException("Invalid permission node for global group: " + groupName, ex); + } + } else if (element instanceof String) { + newGroup.addPermission((String) element); + } else + throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); + + // Info nodes + element = GGroups.get("groups." + groupName + ".info"); + + if (element != null) + if (element instanceof MemorySection) { + Map vars = new HashMap(); + for (String key : ((MemorySection) element).getKeys(false)) { + vars.put(key, ((MemorySection) element).get(key)); + } + newGroup.setVariables(vars); + } else + throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); + + // Push a new group + addGroup(newGroup); } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 8c974f34a..6b5958f4b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -459,160 +459,180 @@ public class WorldDataHolder { //PROCESS GROUPS FILE Map> inheritance = new HashMap>(); + + /* + * Fetch all child nodes under the 'groups' entry. + */ + Map allGroupsNode = new HashMap(); + try { - /* - * Fetch all child nodes under the 'groups' entry. - */ - Map allGroupsNode = (Map) groupsRootDataNode.get("groups"); - Iterator groupItr = allGroupsNode.keySet().iterator(); - String groupKey; - Integer groupCount = 0; - - /* - * loop each group entry - * and read it's data. - */ - while (groupItr.hasNext()) { - try { - groupCount++; - // Attempt to fetch the next group name. - groupKey = groupItr.next(); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type for group entry (" + groupCount + ") in file: " + groupsFile.getPath()); - } - - /* - * Fetch this groups child nodes - */ - Map thisGroupNode = (Map) allGroupsNode.get(groupKey); - /* - * Create a new group with this name - * in the assigned data source. - */ - Group thisGrp = ph.createGroup(groupKey); - - if (thisGrp == null) { - throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + allGroupsNode = (Map) groupsRootDataNode.get("groups"); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex); + } + + + Iterator groupItr = allGroupsNode.keySet().iterator(); + String groupKey; + Integer groupCount = 0; + + /* + * loop each group entry + * and read it's data. + */ + while (groupItr.hasNext()) { + try { + groupCount++; + // Attempt to fetch the next group name. + groupKey = groupItr.next(); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid group name for group entry (" + groupCount + ") in file: " + groupsFile.getPath(), ex); + } + + /* + * Fetch this groups child nodes + */ + Map thisGroupNode = new HashMap(); + + try { + thisGroupNode = (Map) allGroupsNode.get(groupKey); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid child nodes for group '" + groupKey + "' in file: " + groupsFile.getPath(), ex); + } + + /* + * Create a new group with this name + * in the assigned data source. + */ + Group thisGrp = ph.createGroup(groupKey); + + if (thisGrp == null) { + throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); + } + + /* + * If no default node is found set it as false. + */ + if (thisGroupNode.get("default") == null) { + thisGroupNode.put("default", false); + } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + /* + * Set this as the default group. + * Warn if some other group has already claimed that position. + */ + if (ph.getDefaultGroup() != null) { + GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); + GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); } - /* - * If no default node is found set it as false. - */ - if (thisGroupNode.get("default") == null) { - thisGroupNode.put("default", false); - } else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) { + ph.setDefaultGroup(thisGrp); + } + + //PERMISSIONS NODE + + /* + * If no permissions node is found, or it's empty + * set an empty permission list + */ + if (thisGroupNode.get("permissions") == null) { + thisGroupNode.put("permissions", new ArrayList()); + } else { + /* + * There is a permission list Which seems to hold some data + */ + if (thisGroupNode.get("permissions") instanceof List) { /* - * Set this as the default group. - * Warn if some other group has already claimed that position. + * Check each entry and add it as a new permission. */ - if (ph.getDefaultGroup() != null) { - GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was."); - GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath()); + for (Object o : ((List) thisGroupNode.get("permissions"))) { + try { + /* + * Only add this permission if it's not empty. + */ + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission(o.toString()); + + } catch (NullPointerException ex) { + // Ignore this entry as it's null. It can be safely dropped + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } } - ph.setDefaultGroup(thisGrp); - } - - //PERMISSIONS NODE - try { + } else if (thisGroupNode.get("permissions") instanceof String) { /* - * If no permissions node is found, or it's empty - * set an empty permission list + * Only add this permission if it's not empty. */ - if (thisGroupNode.get("permissions") == null) { - thisGroupNode.put("permissions", new ArrayList()); - } else { - /* - * There is a permission list Which seems to hold some data - */ - if (thisGroupNode.get("permissions") instanceof List) { - /* - * Check each entry and add it as a new permission. - */ - for (Object o : ((List) thisGroupNode.get("permissions"))) { - try { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission(o.toString()); - } catch (NullPointerException e) { - // Ignore this entry as it's null. It can be safely dropped - } - } - } else if (thisGroupNode.get("permissions") instanceof String) { - /* - * Only add this permission if it's not empty. - */ - if (!thisGroupNode.get("permissions").toString().isEmpty()) - thisGrp.addPermission((String) thisGroupNode.get("permissions")); - } else { - throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - /* - * Sort all permissions so they are in the correct order for checking. - */ - thisGrp.sortPermissions(); - } - } catch (Exception e) { - throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } - - //INFO NODE - try { - if (thisGroupNode.get("info") instanceof Map) { - Map infoNode = (Map) thisGroupNode.get("info"); - if (infoNode != null) { - thisGrp.setVariables(infoNode); - } - } else - throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e1) { - throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } + if (!thisGroupNode.get("permissions").toString().isEmpty()) + thisGrp.addPermission((String) thisGroupNode.get("permissions")); - //END INFO NODE - - try { - if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { - Object inheritNode = thisGroupNode.get("inheritance"); - if (inheritNode == null) { - thisGroupNode.put("inheritance", new ArrayList()); - } else if (inheritNode instanceof List) { - List groupsInh = (List) inheritNode; - for (String grp : groupsInh) { - if (inheritance.get(groupKey) == null) { - List thisInherits = new ArrayList(); - inheritance.put(groupKey, thisInherits); - } - inheritance.get(groupKey).add(grp); - - } - } - }else - throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); - } catch (Exception e2) { - throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } else { + throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); } + /* + * Sort all permissions so they are in the correct order for checking. + */ + thisGrp.sortPermissions(); } - } catch (Exception ex) { - ex.printStackTrace(); - throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); + //INFO NODE + try { + if (thisGroupNode.get("info") instanceof Map) { + Map infoNode = (Map) thisGroupNode.get("info"); + if (infoNode != null) { + thisGrp.setVariables(infoNode); + } + } else + throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } + + //END INFO NODE + + try { + if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { + Object inheritNode = thisGroupNode.get("inheritance"); + if (inheritNode == null) { + thisGroupNode.put("inheritance", new ArrayList()); + } else if (inheritNode instanceof List) { + List groupsInh = (List) inheritNode; + for (String grp : groupsInh) { + if (inheritance.get(groupKey) == null) { + List thisInherits = new ArrayList(); + inheritance.put(groupKey, thisInherits); + } + inheritance.get(groupKey).add(grp); + + } + } + }else + throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex); + } } + if (ph.getDefaultGroup() == null) { throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath()); } - for (String groupKey : inheritance.keySet()) { - List inheritedList = inheritance.get(groupKey); - Group thisGroup = ph.getGroup(groupKey); - for (String inheritedKey : inheritedList) { - if (inheritedKey != null) { - Group inheritedGroup = ph.getGroup(inheritedKey); - if (thisGroup != null && inheritedGroup != null) { - thisGroup.addInherits(inheritedGroup); - } - } - } + + /* + * Build the inheritance map and recored any errors + */ + for (String group : inheritance.keySet()) { + List inheritedList = inheritance.get(group); + Group thisGroup = ph.getGroup(group); + if (thisGroup != null) + for (String inheritedKey : inheritedList) { + if (inheritedKey != null) { + Group inheritedGroup = ph.getGroup(inheritedKey); + if (inheritedGroup != null) { + thisGroup.addInherits(inheritedGroup); + } else + GroupManager.logger.warning("Inherited group '" + inheritedKey + "' not found for group " + thisGroup.getName() + ". Ignoring entry in file: " + groupsFile.getPath()); + } + } } ph.removeGroupsChangedFlag(); @@ -654,7 +674,17 @@ public class WorldDataHolder { } // PROCESS USERS FILE - Map allUsersNode = (Map) usersRootDataNode.get("users"); + Map allUsersNode = new HashMap(); + + /* + * Fetch all child nodes under the 'users' entry. + */ + try { + allUsersNode = (Map) usersRootDataNode.get("users"); + } catch (Exception ex) { + //ex.printStackTrace(); + throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex); + } // Load users if the file is NOT empty if (allUsersNode != null) { @@ -668,8 +698,8 @@ public class WorldDataHolder { userCount++; // Attempt to fetch the next user name. usersKey = usersItr.next(); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath()); + } catch (Exception ex) { + throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex); } Map thisUserNode = null; @@ -702,7 +732,6 @@ public class WorldDataHolder { 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(); -- cgit v1.2.3 From f2d13677bdd1bfa9bad1f241938131ea01bebf31 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Thu, 12 Apr 2012 03:21:38 +0100 Subject: Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. --- EssentialsGroupManager/src/Changelog.txt | 3 ++- .../src/org/anjocaido/groupmanager/GroupManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 0bf6c47bf..648f5d1de 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -175,4 +175,5 @@ v 2.0: - Startup errors will now lock out ALL commands other than '/manload' - Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command. - Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance. - - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. \ No newline at end of file + - Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's. + - Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 1177e3357..1c4011ff8 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -98,7 +98,7 @@ public class GroupManager extends JavaPlugin { setLoaded(false); // Un-register this service. - this.getServer().getServicesManager().unregister(this); + this.getServer().getServicesManager().unregister(this.worldsHolder); disableScheduler(); // Shutdown before we save, so it doesn't interfere. if (worldsHolder != null) { -- cgit v1.2.3