mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-02 13:31:54 +01:00
Merge branch 'refs/heads/groupmanager'
This commit is contained in:
commit
d9ee666770
@ -175,3 +175,5 @@ v 2.0:
|
||||
- Startup errors will now lock out ALL commands other than '/manload'
|
||||
- Fix 'manuadd' to use the default or selected world (via 'manselect'), if the world is not specified in the command.
|
||||
- Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance.
|
||||
- Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's.
|
||||
- Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin.
|
@ -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,12 +113,35 @@ public class GlobalGroups {
|
||||
|
||||
if (!GGroups.getKeys(false).isEmpty()) {
|
||||
// Read all global groups
|
||||
Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
||||
Map<String, Object> allGroups = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
allGroups = (Map<String, Object>) 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) {
|
||||
|
||||
Iterator<String> groupItr = allGroups.keySet().iterator();
|
||||
String groupName;
|
||||
Integer groupCount = 0;
|
||||
|
||||
/*
|
||||
* loop each group entry
|
||||
* and read it's data.
|
||||
*/
|
||||
while (groupItr.hasNext()) {
|
||||
try {
|
||||
for (String groupName : allGroups.keySet()) {
|
||||
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);
|
||||
}
|
||||
|
||||
Group newGroup = new Group(groupName.toLowerCase());
|
||||
Object element;
|
||||
|
||||
@ -130,8 +154,8 @@ public class GlobalGroups {
|
||||
for (String node : (List<String>) element) {
|
||||
newGroup.addPermission(node);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException("Invalid permission node for global group: " + groupName);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("Invalid permission node for global group: " + groupName, ex);
|
||||
}
|
||||
} else if (element instanceof String) {
|
||||
newGroup.addPermission((String) element);
|
||||
@ -154,9 +178,6 @@ public class GlobalGroups {
|
||||
// Push a new group
|
||||
addGroup(newGroup);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Invalid node type, or bad indentation in GlobalGroups! ");
|
||||
}
|
||||
}
|
||||
|
||||
removeGroupsChangedFlag();
|
||||
|
@ -98,7 +98,7 @@ public class GroupManager extends JavaPlugin {
|
||||
setLoaded(false);
|
||||
|
||||
// Un-register this service.
|
||||
this.getServer().getServicesManager().unregister(this);
|
||||
this.getServer().getServicesManager().unregister(this.worldsHolder);
|
||||
|
||||
disableScheduler(); // Shutdown before we save, so it doesn't interfere.
|
||||
if (worldsHolder != null) {
|
||||
|
@ -459,11 +459,20 @@ public class WorldDataHolder {
|
||||
|
||||
//PROCESS GROUPS FILE
|
||||
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
|
||||
try {
|
||||
|
||||
/*
|
||||
* Fetch all child nodes under the 'groups' entry.
|
||||
*/
|
||||
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
|
||||
Map<String, Object> allGroupsNode = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
|
||||
} catch (Exception ex) {
|
||||
//ex.printStackTrace();
|
||||
throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.", ex);
|
||||
}
|
||||
|
||||
|
||||
Iterator<String> groupItr = allGroupsNode.keySet().iterator();
|
||||
String groupKey;
|
||||
Integer groupCount = 0;
|
||||
@ -477,14 +486,21 @@ public class WorldDataHolder {
|
||||
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());
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Invalid group name for group entry (" + groupCount + ") in file: " + groupsFile.getPath(), ex);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch this groups child nodes
|
||||
*/
|
||||
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
|
||||
Map<String, Object> thisGroupNode = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Invalid child nodes for group '" + groupKey + "' in file: " + groupsFile.getPath(), ex);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new group with this name
|
||||
* in the assigned data source.
|
||||
@ -494,6 +510,7 @@ public class WorldDataHolder {
|
||||
if (thisGrp == null) {
|
||||
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.
|
||||
*/
|
||||
@ -512,7 +529,7 @@ public class WorldDataHolder {
|
||||
}
|
||||
|
||||
//PERMISSIONS NODE
|
||||
try {
|
||||
|
||||
/*
|
||||
* If no permissions node is found, or it's empty
|
||||
* set an empty permission list
|
||||
@ -534,8 +551,11 @@ public class WorldDataHolder {
|
||||
*/
|
||||
if (!thisGroupNode.get("permissions").toString().isEmpty())
|
||||
thisGrp.addPermission(o.toString());
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
} catch (NullPointerException ex) {
|
||||
// Ignore this entry as it's null. It can be safely dropped
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex);
|
||||
}
|
||||
}
|
||||
} else if (thisGroupNode.get("permissions") instanceof String) {
|
||||
@ -544,6 +564,7 @@ public class WorldDataHolder {
|
||||
*/
|
||||
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());
|
||||
}
|
||||
@ -552,9 +573,6 @@ public class WorldDataHolder {
|
||||
*/
|
||||
thisGrp.sortPermissions();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Invalid formatting found in permissions section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
|
||||
}
|
||||
|
||||
//INFO NODE
|
||||
try {
|
||||
@ -565,8 +583,8 @@ public class WorldDataHolder {
|
||||
}
|
||||
} 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());
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Invalid formatting found in info section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex);
|
||||
}
|
||||
|
||||
//END INFO NODE
|
||||
@ -589,28 +607,30 @@ public class WorldDataHolder {
|
||||
}
|
||||
}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 ex) {
|
||||
throw new IllegalArgumentException("Invalid formatting found in inheritance section for group: " + thisGrp.getName() + " in file: " + groupsFile.getPath(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new IllegalArgumentException("Your " + groupsFile.getPath() + " file is invalid. See console for details.");
|
||||
}
|
||||
|
||||
if (ph.getDefaultGroup() == null) {
|
||||
throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath());
|
||||
}
|
||||
for (String groupKey : inheritance.keySet()) {
|
||||
List<String> inheritedList = inheritance.get(groupKey);
|
||||
Group thisGroup = ph.getGroup(groupKey);
|
||||
|
||||
/*
|
||||
* Build the inheritance map and recored any errors
|
||||
*/
|
||||
for (String group : inheritance.keySet()) {
|
||||
List<String> inheritedList = inheritance.get(group);
|
||||
Group thisGroup = ph.getGroup(group);
|
||||
if (thisGroup != null)
|
||||
for (String inheritedKey : inheritedList) {
|
||||
if (inheritedKey != null) {
|
||||
Group inheritedGroup = ph.getGroup(inheritedKey);
|
||||
if (thisGroup != null && inheritedGroup != null) {
|
||||
if (inheritedGroup != null) {
|
||||
thisGroup.addInherits(inheritedGroup);
|
||||
}
|
||||
} else
|
||||
GroupManager.logger.warning("Inherited group '" + inheritedKey + "' not found for group " + thisGroup.getName() + ". Ignoring entry in file: " + groupsFile.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -654,7 +674,17 @@ public class WorldDataHolder {
|
||||
}
|
||||
|
||||
// PROCESS USERS FILE
|
||||
Map<String, Object> allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
|
||||
Map<String, Object> allUsersNode = new HashMap<String, Object>();
|
||||
|
||||
/*
|
||||
* Fetch all child nodes under the 'users' entry.
|
||||
*/
|
||||
try {
|
||||
allUsersNode = (Map<String, Object>) usersRootDataNode.get("users");
|
||||
} catch (Exception ex) {
|
||||
//ex.printStackTrace();
|
||||
throw new IllegalArgumentException("Your " + usersFile.getPath() + " file is invalid. See console for details.", ex);
|
||||
}
|
||||
|
||||
// Load users if the file is NOT empty
|
||||
if (allUsersNode != null) {
|
||||
@ -668,8 +698,8 @@ public class WorldDataHolder {
|
||||
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());
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Invalid node type for user entry (" + userCount + ") in file: " + usersFile.getPath(), ex);
|
||||
}
|
||||
|
||||
Map<String, Object> thisUserNode = null;
|
||||
@ -702,7 +732,6 @@ public class WorldDataHolder {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user