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).
- Auto rename all case sensitive world folders to lower case (if possible).
- 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.
if (allGroups != null) {
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);
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);
}
} 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);
} 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);
}
} catch (Exception e) {
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>>();
try {
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
for (String groupKey : allGroupsNode.keySet()) {
Map<String, Object> thisGroupNode = (Map<String, Object>) 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<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();
try {
for (String groupKey : allGroupsNode.keySet()) {
Map<String, Object> thisGroupNode = (Map<String, Object>) 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());
}
} 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);
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();
}
} 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<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());
}
}
} 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());
}
//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());
}
}
} catch (Exception e) {
throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + groupsFile.getPath());
}
} catch (Exception ex) {
ex.printStackTrace();
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
if (allUsersNode != null)
for (String usersKey : allUsersNode.keySet()) {
Map<String, Object> thisUserNode = null;
try {
thisUserNode = (Map<String, Object>) 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<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());
}
try {
for (String usersKey : allUsersNode.keySet()) {
Map<String, Object> thisUserNode = null;
try {
thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
} catch (Exception ex) {
throw new IllegalArgumentException("Bad format found in file: " + usersFile.getPath());
}
thisUser.sortPermissions();
}
//SUBGROUPS LOADING
if (thisUserNode.get("subgroups") == null) {
thisUserNode.put("subgroups", new ArrayList<String>());
}
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<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());
}
}
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();
}
//SUBGROUPS LOADING
if (thisUserNode.get("subgroups") == null) {
thisUserNode.put("subgroups", new ArrayList<String>());
}
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<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();
// Update the LastModified time.