mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 12:23:59 +00:00
Better handling of errors in user and group yml's.
This commit is contained in:
parent
e8dd963545
commit
e8a42e3947
2 changed files with 232 additions and 178 deletions
|
@ -168,3 +168,4 @@ v 2.0:
|
||||||
- Remove all permission attachments when performing a manload or restart.
|
- Remove all permission attachments when performing a manload or restart.
|
||||||
- Expand 'manwhois' to also list a users subgroups.
|
- Expand 'manwhois' to also list a users subgroups.
|
||||||
- Fix a concurrent modification error when removing all attachments.
|
- Fix a concurrent modification error when removing all attachments.
|
||||||
|
- Better handling of errors in user and group yml's.
|
|
@ -14,6 +14,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -459,18 +460,50 @@ public class WorldDataHolder {
|
||||||
//PROCESS GROUPS FILE
|
//PROCESS GROUPS FILE
|
||||||
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
|
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
|
||||||
try {
|
try {
|
||||||
|
/*
|
||||||
|
* Fetch all child nodes under the 'groups' entry.
|
||||||
|
*/
|
||||||
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
|
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 {
|
try {
|
||||||
for (String groupKey : allGroupsNode.keySet()) {
|
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);
|
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);
|
Group thisGrp = ph.createGroup(groupKey);
|
||||||
|
|
||||||
if (thisGrp == null) {
|
if (thisGrp == null) {
|
||||||
throw new IllegalArgumentException("I think this Group was declared more than once: " + groupKey + " in file: " + groupsFile.getPath());
|
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) {
|
if (thisGroupNode.get("default") == null) {
|
||||||
thisGroupNode.put("default", false);
|
thisGroupNode.put("default", false);
|
||||||
}
|
} else if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) {
|
||||||
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) {
|
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("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());
|
GroupManager.logger.warning("Overriding first request for file: " + groupsFile.getPath());
|
||||||
|
@ -480,10 +513,20 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
//PERMISSIONS NODE
|
//PERMISSIONS NODE
|
||||||
try {
|
try {
|
||||||
|
/*
|
||||||
|
* If no permissions node is found, or it's empty
|
||||||
|
* set an empty permission list
|
||||||
|
*/
|
||||||
if (thisGroupNode.get("permissions") == null) {
|
if (thisGroupNode.get("permissions") == null) {
|
||||||
thisGroupNode.put("permissions", new ArrayList<String>());
|
thisGroupNode.put("permissions", new ArrayList<String>());
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* There is a permission list Which seems to hold some data
|
||||||
|
*/
|
||||||
if (thisGroupNode.get("permissions") instanceof List) {
|
if (thisGroupNode.get("permissions") instanceof List) {
|
||||||
|
/*
|
||||||
|
* Check each entry and add it as a new permission.
|
||||||
|
*/
|
||||||
for (Object o : ((List) thisGroupNode.get("permissions"))) {
|
for (Object o : ((List) thisGroupNode.get("permissions"))) {
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
|
@ -492,8 +535,7 @@ public class WorldDataHolder {
|
||||||
if (!thisGroupNode.get("permissions").toString().isEmpty())
|
if (!thisGroupNode.get("permissions").toString().isEmpty())
|
||||||
thisGrp.addPermission(o.toString());
|
thisGrp.addPermission(o.toString());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// Ignore this entry as it's null.
|
// Ignore this entry as it's null. It can be safely dropped
|
||||||
//throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (thisGroupNode.get("permissions") instanceof String) {
|
} else if (thisGroupNode.get("permissions") instanceof String) {
|
||||||
|
@ -505,6 +547,9 @@ public class WorldDataHolder {
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
|
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();
|
thisGrp.sortPermissions();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -548,9 +593,7 @@ public class WorldDataHolder {
|
||||||
throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
|
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.");
|
||||||
|
@ -614,9 +657,21 @@ public class WorldDataHolder {
|
||||||
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
|
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
|
||||||
|
|
||||||
// Load users if the file is NOT empty
|
// Load users if the file is NOT empty
|
||||||
if (allUsersNode != null)
|
if (allUsersNode != null) {
|
||||||
|
|
||||||
|
Iterator<String> usersItr = allUsersNode.keySet().iterator();
|
||||||
|
String usersKey;
|
||||||
|
Integer userCount = 0;
|
||||||
|
|
||||||
|
while (usersItr.hasNext()) {
|
||||||
try {
|
try {
|
||||||
for (String usersKey : allUsersNode.keySet()) {
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> thisUserNode = null;
|
Map<String, Object> thisUserNode = null;
|
||||||
try {
|
try {
|
||||||
thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
|
thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
|
||||||
|
@ -702,8 +757,6 @@ public class WorldDataHolder {
|
||||||
thisUser.setGroup(ph.getDefaultGroup());
|
thisUser.setGroup(ph.getDefaultGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Invalid node type, or bad indentation in file: " + usersFile.getPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ph.removeUsersChangedFlag();
|
ph.removeUsersChangedFlag();
|
||||||
|
|
Loading…
Reference in a new issue