From 62a297ec6d2dc417c2e8d97d5e3e9abbf15c6ed6 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. --- .../org/anjocaido/groupmanager/GlobalGroups.java | 101 +++++++++++++-------- 1 file changed, 61 insertions(+), 40 deletions(-) (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java') 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); } } -- cgit v1.2.3