summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido/groupmanager
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java101
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java313
2 files changed, 232 insertions, 182 deletions
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<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
+ Map<String, Object> allGroups = new HashMap<String, Object>();
+
+ try {
+ allGroups = (Map<String, Object>) 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<String>) 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<String, Object> vars = new HashMap<String, Object>();
- 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<String> 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<String>) 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<String, Object> vars = new HashMap<String, Object>();
+ 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<String, List<String>> inheritance = new HashMap<String, List<String>>();
+
+ /*
+ * Fetch all child nodes under the 'groups' entry.
+ */
+ Map<String, Object> allGroupsNode = new HashMap<String, Object>();
+
try {
- /*
- * Fetch all child nodes under the 'groups' entry.
- */
- Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
- Iterator<String> 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<String, Object> thisGroupNode = (Map<String, Object>) 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<String, Object>) groupsRootDataNode.get("groups");
+ } catch (Exception ex) {
+ //ex.printStackTrace();
+ throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex);
+ }
+
+
+ Iterator<String> 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<String, Object> thisGroupNode = new HashMap<String, Object>();
+
+ try {
+ thisGroupNode = (Map<String, Object>) 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<String>());
+ } 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<String>());
- } 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<String>) 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<String, Object> infoNode = (Map<String, Object>) 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<String>());
- } else if (inheritNode instanceof List) {
- List<String> groupsInh = (List<String>) inheritNode;
- for (String grp : groupsInh) {
- if (inheritance.get(groupKey) == null) {
- List<String> thisInherits = new ArrayList<String>();
- 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<String>) 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<String, Object> infoNode = (Map<String, Object>) 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<String>());
+ } else if (inheritNode instanceof List) {
+ List<String> groupsInh = (List<String>) inheritNode;
+ for (String grp : groupsInh) {
+ if (inheritance.get(groupKey) == null) {
+ List<String> thisInherits = new ArrayList<String>();
+ 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<String> 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<String> 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<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
+ Map<String, Object> allUsersNode = new HashMap<String, Object>();
+
+ /*
+ * Fetch all child nodes under the 'users' entry.
+ */
+ try {
+ allUsersNode = (Map<String, Object>) 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<String, Object> 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();