mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Added Info node support to Global Groups.
This commit is contained in:
parent
0731de53b4
commit
3f2916967d
4 changed files with 72 additions and 14 deletions
|
@ -59,3 +59,4 @@ v 1.5:
|
||||||
- Added Global Groups
|
- Added Global Groups
|
||||||
Defined in groupmanager/globalgroups.yml.
|
Defined in groupmanager/globalgroups.yml.
|
||||||
Create groups in the yml with a g: prefix, then inherit in the worlds groups files.
|
Create groups in the yml with a g: prefix, then inherit in the worlds groups files.
|
||||||
|
- Added Info node support to Global Groups.
|
|
@ -16,6 +16,7 @@ import java.util.logging.Level;
|
||||||
import org.anjocaido.groupmanager.data.Group;
|
import org.anjocaido.groupmanager.data.Group;
|
||||||
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||||
import org.anjocaido.groupmanager.utils.Tasks;
|
import org.anjocaido.groupmanager.utils.Tasks;
|
||||||
|
import org.bukkit.configuration.MemorySection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
@ -96,15 +97,33 @@ public class GlobalGroups {
|
||||||
if (allGroups != null)
|
if (allGroups != null)
|
||||||
for (String groupName : allGroups.keySet()) {
|
for (String groupName : allGroups.keySet()) {
|
||||||
Group newGroup = new Group(groupName.toLowerCase());
|
Group newGroup = new Group(groupName.toLowerCase());
|
||||||
Object permissions = GGroups.get("groups." + groupName + ".permissions");
|
Object element;
|
||||||
|
|
||||||
if (permissions instanceof List) {
|
// Permission nodes
|
||||||
for (String permission : (List<String>) permissions) {
|
element = GGroups.get("groups." + groupName + ".permissions");
|
||||||
newGroup.addPermission(permission);
|
|
||||||
|
if (element != null)
|
||||||
|
if (element instanceof List) {
|
||||||
|
for (String node : (List<String>) element) {
|
||||||
|
newGroup.addPermission(node);
|
||||||
}
|
}
|
||||||
} else if (permissions instanceof String) {
|
} else if (element instanceof String) {
|
||||||
newGroup.addPermission((String) permissions);
|
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
|
// Push a new group
|
||||||
addGroup(newGroup);
|
addGroup(newGroup);
|
||||||
|
@ -129,9 +148,19 @@ public class GlobalGroups {
|
||||||
for (String groupKey : groups.keySet()) {
|
for (String groupKey : groups.keySet()) {
|
||||||
Group group = groups.get(groupKey);
|
Group group = groups.get(groupKey);
|
||||||
|
|
||||||
|
// Group header
|
||||||
Map<String, Object> aGroupMap = new HashMap<String, Object>();
|
Map<String, Object> aGroupMap = new HashMap<String, Object>();
|
||||||
groupsMap.put(group.getName(), aGroupMap);
|
groupsMap.put(group.getName(), aGroupMap);
|
||||||
|
|
||||||
|
// Info nodes
|
||||||
|
Map<String, Object> infoMap = new HashMap<String, Object>();
|
||||||
|
aGroupMap.put("info", infoMap);
|
||||||
|
|
||||||
|
for (String infoKey : group.getVariables().getVarKeyList()) {
|
||||||
|
infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permission nodes
|
||||||
aGroupMap.put("permissions", group.getPermissionList());
|
aGroupMap.put("permissions", group.getPermissionList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,11 +178,27 @@ public class GlobalGroups {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new group if it doesn't already exist.
|
* Adds a group, or replaces an existing one.
|
||||||
|
*
|
||||||
|
* @param groupToAdd
|
||||||
|
*/
|
||||||
|
public void addGroup(Group groupToAdd) {
|
||||||
|
// Create a new group if it already exists
|
||||||
|
if (hasGroup(groupToAdd.getName())) {
|
||||||
|
groupToAdd = groupToAdd.clone();
|
||||||
|
removeGroup(groupToAdd.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
newGroup(groupToAdd);
|
||||||
|
haveGroupsChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new group if it doesn't already exist.
|
||||||
*
|
*
|
||||||
* @param newGroup
|
* @param newGroup
|
||||||
*/
|
*/
|
||||||
public Group addGroup(Group newGroup) {
|
public Group newGroup(Group newGroup) {
|
||||||
// Push a new group
|
// Push a new group
|
||||||
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
||||||
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
||||||
|
|
|
@ -50,8 +50,15 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Group clone() {
|
public Group clone() {
|
||||||
Group clone = new Group(getDataSource(), this.getName());
|
Group clone;
|
||||||
|
|
||||||
|
if (getDataSource() == null) {
|
||||||
|
clone = new Group(this.getName());
|
||||||
|
} else {
|
||||||
|
clone = new Group(getDataSource(), this.getName());
|
||||||
clone.inherits = new ArrayList<String>(this.getInherits());
|
clone.inherits = new ArrayList<String>(this.getInherits());
|
||||||
|
}
|
||||||
|
|
||||||
for (String perm : this.getPermissionList()) {
|
for (String perm : this.getPermissionList()) {
|
||||||
clone.addPermission(perm);
|
clone.addPermission(perm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,11 @@ public class WorldDataHolder {
|
||||||
* @param groupToAdd
|
* @param groupToAdd
|
||||||
*/
|
*/
|
||||||
public void addGroup(Group groupToAdd) {
|
public void addGroup(Group groupToAdd) {
|
||||||
|
if (groupToAdd.getName().startsWith("g:")) {
|
||||||
|
GroupManager.getGlobalGroups().addGroup(groupToAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (groupToAdd.getDataSource() != this) {
|
if (groupToAdd.getDataSource() != this) {
|
||||||
groupToAdd = groupToAdd.clone(this);
|
groupToAdd = groupToAdd.clone(this);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +268,7 @@ public class WorldDataHolder {
|
||||||
public Group createGroup(String groupName) {
|
public Group createGroup(String groupName) {
|
||||||
if (groupName.startsWith("g:")) {
|
if (groupName.startsWith("g:")) {
|
||||||
Group newGroup = new Group(groupName);
|
Group newGroup = new Group(groupName);
|
||||||
return GroupManager.getGlobalGroups().addGroup(newGroup);
|
return GroupManager.getGlobalGroups().newGroup(newGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.groups.containsKey(groupName.toLowerCase())) {
|
if (this.groups.containsKey(groupName.toLowerCase())) {
|
||||||
|
|
Loading…
Reference in a new issue