Catch errors caused by bad indentation in yml's.

This commit is contained in:
ElgarL 2012-03-29 14:02:53 +01:00
parent 1ef8ab70d1
commit 9dbeb1407c
3 changed files with 219 additions and 206 deletions

View file

@ -155,4 +155,5 @@ v 1.9:
- Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now). - Treat all world names as lower case for file handling (please check in your worlds folder. You should have no folders with upper case letters from now).
- Auto rename all case sensitive world folders to lower case (if possible). - Auto rename all case sensitive world folders to lower case (if possible).
- Update GlobalGroups.yml for new/changed Towny permission nodes. - Update GlobalGroups.yml for new/changed Towny permission nodes.
- Stop attempting to push empty permissions when players edit the yml's incorrectly. - Stop attempting to push empty permissions when players edit the yml's incorrectly.
- Catch errors caused by bad indentation in yml's.

View file

@ -116,42 +116,46 @@ public class GlobalGroups {
// Load each groups permissions list. // Load each groups permissions list.
if (allGroups != null) { if (allGroups != null) {
for (String groupName : allGroups.keySet()) { try {
Group newGroup = new Group(groupName.toLowerCase()); for (String groupName : allGroups.keySet()) {
Object element; Group newGroup = new Group(groupName.toLowerCase());
Object element;
// Permission nodes
element = GGroups.get("groups." + groupName + ".permissions"); // Permission nodes
element = GGroups.get("groups." + groupName + ".permissions");
if (element != null)
if (element instanceof List) { if (element != null)
try { if (element instanceof List) {
for (String node : (List<String>) element) { try {
newGroup.addPermission(node); for (String node : (List<String>) element) {
newGroup.addPermission(node);
}
} catch (ClassCastException e) {
throw new IllegalArgumentException("Invalid permission node for global group: " + groupName);
} }
} catch (ClassCastException e) { } else if (element instanceof String) {
throw new IllegalArgumentException("Invalid permission node for global group: " + groupName); newGroup.addPermission((String) element);
} } else
} else if (element instanceof String) { throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName);
newGroup.addPermission((String) element);
} else // Info nodes
throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName); element = GGroups.get("groups." + groupName + ".info");
// Info nodes if (element != null)
element = GGroups.get("groups." + groupName + ".info"); if (element instanceof MemorySection) {
Map<String, Object> vars = new HashMap<String, Object>();
if (element != null) for (String key : ((MemorySection) element).getKeys(false)) {
if (element instanceof MemorySection) { vars.put(key, ((MemorySection) element).get(key));
Map<String, Object> vars = new HashMap<String, Object>(); }
for (String key : ((MemorySection) element).getKeys(false)) { newGroup.setVariables(vars);
vars.put(key, ((MemorySection) element).get(key)); } else
} throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName);
newGroup.setVariables(vars);
} else // Push a new group
throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName); addGroup(newGroup);
}
// Push a new group } catch (Exception e) {
addGroup(newGroup); throw new IllegalArgumentException("Invalid node type, or bad indentation in GlobalGroups! ");
} }
} }

View file

@ -460,93 +460,97 @@ public class WorldDataHolder {
Map<String, List<String>> inheritance = new HashMap<String, List<String>>(); Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
try { try {
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups"); Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
for (String groupKey : allGroupsNode.keySet()) { try {
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey); for (String groupKey : allGroupsNode.keySet()) {
Group thisGrp = ph.createGroup(groupKey); Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
if (thisGrp == null) { Group thisGrp = ph.createGroup(groupKey);
throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath()); 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<String>());
} 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<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
}
thisGrp.sortPermissions();
} }
} catch (Exception e) { if (thisGroupNode.get("default") == null) {
throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); thisGroupNode.put("default", false);
} }
if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) {
//INFO NODE if (ph.getDefaultGroup() != null) {
try { GroupManager.logger.warning("The group " + thisGrp.getName() + " is claiming to be default where" + ph.getDefaultGroup().getName() + " already was.");
if (thisGroupNode.get("info") instanceof Map) { GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath());
Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info"); }
if (infoNode != null) { ph.setDefaultGroup(thisGrp);
thisGrp.setVariables(infoNode); }
//PERMISSIONS NODE
try {
if (thisGroupNode.get("permissions") == null) {
thisGroupNode.put("permissions", new ArrayList<String>());
} 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<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
}
thisGrp.sortPermissions();
} }
} else } catch (Exception e) {
throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); throw new IllegalArgumentException("Invalid formatting found in permissions 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());
} //INFO NODE
try {
//END INFO NODE if (thisGroupNode.get("info") instanceof Map) {
Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
try { if (infoNode != null) {
if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) { thisGrp.setVariables(infoNode);
Object inheritNode = thisGroupNode.get("inheritance"); }
if (inheritNode == null) { } else
thisGroupNode.put("inheritance", new ArrayList<String>()); throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
} else if (inheritNode instanceof List) { } catch (Exception e1) {
List<String> groupsInh = (List<String>) inheritNode; throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
for (String grp : groupsInh) { }
if (inheritance.get(groupKey) == null) {
List<String> thisInherits = new ArrayList<String>(); //END INFO NODE
inheritance.put(groupKey, thisInherits);
} try {
inheritance.get(groupKey).add(grp); 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 } else if (inheritNode instanceof List) {
throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); List<String> groupsInh = (List<String>) inheritNode;
} catch (Exception e2) { for (String grp : groupsInh) {
throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath()); 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());
}
}
} catch (Exception e) {
throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath());
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details."); throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.");
@ -609,92 +613,96 @@ public class WorldDataHolder {
// Load users if the file is NOT empty // Load users if the file is NOT empty
if (allUsersNode != null) if (allUsersNode != null)
for (String usersKey : allUsersNode.keySet()) { try {
Map<String, Object> thisUserNode = null; for (String usersKey : allUsersNode.keySet()) {
try { Map<String, Object> thisUserNode = null;
thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey); try {
} catch (Exception ex) { thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath()); } 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<String>());
} 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(); 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());
//SUBGROUPS LOADING }
if (thisUserNode.get("subgroups") == null) { if (thisUserNode.get("permissions") == null) {
thisUserNode.put("subgroups", new ArrayList<String>()); thisUserNode.put("permissions", new ArrayList<String>());
} } else {
if (thisUserNode.get("subgroups") instanceof List) { if (thisUserNode.get("permissions") instanceof List) {
for (Object o : ((List) thisUserNode.get("subgroups"))) { for (Object o : ((List) thisUserNode.get("permissions"))) {
Group subGrp = ph.getGroup(o.toString()); /*
if (subGrp != null) { * Only add this permission if it's not empty
thisUser.addSubGroup(subGrp); */
} else { if (!o.toString().isEmpty())
GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); thisUser.addPermission(o.toString());
} }
} } else if (thisUserNode.get("permissions") instanceof String) {
} else if (thisUserNode.get("subgroups") instanceof String) { try {
Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); /*
if (subGrp != null) { * Only add this permission if it's not empty
thisUser.addSubGroup(subGrp); */
} else { if (!thisUserNode.get("permissions").toString().isEmpty())
GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath()); 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());
}
//USER INFO NODE }
thisUser.sortPermissions();
//INFO NODE }
if (thisUserNode.get("info") instanceof Map) {
Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info"); //SUBGROUPS LOADING
if (infoNode != null) { if (thisUserNode.get("subgroups") == null) {
thisUser.setVariables(infoNode); thisUserNode.put("subgroups", new ArrayList<String>());
} }
} else if (thisUserNode.get("info") != null) if (thisUserNode.get("subgroups") instanceof List) {
throw new IllegalArgumentException("Unknown entry found in Info section for user: " + thisUser.getName() + " in file: " + usersFile.getPath()); for (Object o : ((List) thisUserNode.get("subgroups"))) {
Group subGrp = ph.getGroup(o.toString());
//END INFO NODE if (subGrp != null) {
thisUser.addSubGroup(subGrp);
} else {
if (thisUserNode.get("group") != null) { GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath());
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()); } else if (thisUserNode.get("subgroups") instanceof String) {
hisGroup = ph.getDefaultGroup(); Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString());
//throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); if (subGrp != null) {
} thisUser.addSubGroup(subGrp);
thisUser.setGroup(hisGroup); } else {
} else { GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry in file: " + usersFile.getPath());
thisUser.setGroup(ph.getDefaultGroup()); }
} }
}
//USER INFO NODE
//INFO NODE
if (thisUserNode.get("info") instanceof Map) {
Map<String, Object> infoNode = (Map<String, Object>) 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());
}
}
} catch (Exception e) {
throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + usersFile.getPath());
}
ph.removeUsersChangedFlag(); ph.removeUsersChangedFlag();
// Update the LastModified time. // Update the LastModified time.