Stop throwing errors on an empty users file.

This commit is contained in:
ElgarL 2011-11-21 09:51:31 +00:00
parent 000d060ea6
commit fd1c2824ce
2 changed files with 65 additions and 68 deletions

View file

@ -74,4 +74,5 @@ v 1.5:
- Fixed GM holding files open and causing the time stamp to be incorrect. This caused GM to require a '/mansave force' when it shouldn't be needed. - Fixed GM holding files open and causing the time stamp to be incorrect. This caused GM to require a '/mansave force' when it shouldn't be needed.
- Fixed a crash on reload due to bukkit not unloading plugins before reloading. - Fixed a crash on reload due to bukkit not unloading plugins before reloading.
v 1.6: v 1.6:
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups. - Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
- Stop throwing errors on an empty users file.

View file

@ -711,78 +711,74 @@ public class WorldDataHolder {
// PROCESS USERS FILE // PROCESS USERS FILE
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users"); Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
// Stop loading if the file is empty // Load users if the file is NOT empty
if (allUsersNode == null) if (allUsersNode != null)
return ; for (String usersKey : allUsersNode.keySet()) {
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
for (String usersKey : allUsersNode.keySet()) { User thisUser = ph.createUser(usersKey);
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey); if (thisUser == null) {
User thisUser = ph.createUser(usersKey); throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey);
if (thisUser == null) { }
throw new IllegalArgumentException("I think this user was declared more than once: " + usersKey); if (thisUserNode.get("permissions") == null) {
} thisUserNode.put("permissions", new ArrayList<String>());
if (thisUserNode.get("permissions") == null) { }
thisUserNode.put("permissions", new ArrayList<String>()); if (thisUserNode.get("permissions") instanceof List) {
} for (Object o : ((List) thisUserNode.get("permissions"))) {
if (thisUserNode.get("permissions") instanceof List) { thisUser.addPermission(o.toString());
for (Object o : ((List) thisUserNode.get("permissions"))) { }
thisUser.addPermission(o.toString()); } else if (thisUserNode.get("permissions") instanceof String) {
} thisUser.addPermission(thisUserNode.get("permissions").toString());
} else if (thisUserNode.get("permissions") instanceof String) { }
thisUser.addPermission(thisUserNode.get("permissions").toString());
} //SUBGROUPS LOADING
if (thisUserNode.get("subgroups") == null) {
//SUBGROUPS LOADING thisUserNode.put("subgroups", new ArrayList<String>());
if (thisUserNode.get("subgroups") == null) { }
thisUserNode.put("subgroups", new ArrayList<String>()); if (thisUserNode.get("subgroups") instanceof List) {
} for (Object o : ((List) thisUserNode.get("subgroups"))) {
if (thisUserNode.get("subgroups") instanceof List) { Group subGrp = ph.getGroup(o.toString());
for (Object o : ((List) thisUserNode.get("subgroups"))) { if (subGrp != null) {
Group subGrp = ph.getGroup(o.toString()); thisUser.addSubGroup(subGrp);
if (subGrp != null) { } else {
thisUser.addSubGroup(subGrp); GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry.");
} else { }
GroupManager.logger.warning("Subgroup " + o.toString() + " not found for user " + thisUser.getName() + ". Ignoring entry."); }
} } else if (thisUserNode.get("subgroups") instanceof String) {
} Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString());
} else if (thisUserNode.get("subgroups") instanceof String) { if (subGrp != null) {
Group subGrp = ph.getGroup(thisUserNode.get("subgroups").toString()); thisUser.addSubGroup(subGrp);
if (subGrp != null) { } else {
thisUser.addSubGroup(subGrp); GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry.");
} else { }
GroupManager.logger.warning("Subgroup " + thisUserNode.get("subgroups").toString() + " not found for user " + thisUser.getName() + ". Ignoring entry."); }
}
}
//USER INFO NODE - BETA
//USER INFO NODE - BETA //INFO NODE
Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info");
//INFO NODE if (infoNode != null) {
Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info"); thisUser.setVariables(infoNode);
if (infoNode != null) { }
thisUser.setVariables(infoNode); //END INFO NODE - BETA
}
//END INFO NODE - BETA if (thisUserNode.get("group") != null) {
Group hisGroup = ph.getGroup(thisUserNode.get("group").toString());
if (thisUserNode.get("group") != null) { if (hisGroup == null) {
Group hisGroup = ph.getGroup(thisUserNode.get("group").toString()); GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "'.");
if (hisGroup == null) { hisGroup = ph.defaultGroup;
GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "'."); //throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName());
hisGroup = ph.defaultGroup; }
//throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName()); thisUser.setGroup(hisGroup);
} } else {
thisUser.setGroup(hisGroup); thisUser.setGroup(ph.defaultGroup);
} else { }
thisUser.setGroup(ph.defaultGroup); }
}
}
ph.removeUsersChangedFlag(); ph.removeUsersChangedFlag();
// Update the LastModified time. // Update the LastModified time.
ph.usersFile = usersFile; ph.usersFile = usersFile;
ph.setTimeStampUsers(usersFile.lastModified()); ph.setTimeStampUsers(usersFile.lastModified());
//return ph;
} }
/** /**