summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java67
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java11
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java7
3 files changed, 71 insertions, 14 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java
index 85f15899e..a7d0dd920 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java
@@ -16,6 +16,7 @@ import java.util.logging.Level;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.Tasks;
+import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@@ -96,15 +97,33 @@ public class GlobalGroups {
if (allGroups != null)
for (String groupName : allGroups.keySet()) {
Group newGroup = new Group(groupName.toLowerCase());
- Object permissions = GGroups.get("groups." + groupName + ".permissions");
-
- if (permissions instanceof List) {
- for (String permission : (List<String>) permissions) {
- newGroup.addPermission(permission);
- }
- } else if (permissions instanceof String) {
- newGroup.addPermission((String) permissions);
- }
+ Object element;
+
+ // Permission nodes
+ element = GGroups.get("groups." + groupName + ".permissions");
+
+ if (element != null)
+ if (element instanceof List) {
+ for (String node : (List<String>) element) {
+ newGroup.addPermission(node);
+ }
+ } 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);
@@ -129,9 +148,19 @@ public class GlobalGroups {
for (String groupKey : groups.keySet()) {
Group group = groups.get(groupKey);
+ // Group header
Map<String, Object> aGroupMap = new HashMap<String, Object>();
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());
}
@@ -147,13 +176,29 @@ public class GlobalGroups {
}
}
+
+ /**
+ * 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;
+ }
/**
- * Add a new group if it doesn't already exist.
+ * Creates a new group if it doesn't already exist.
*
* @param newGroup
*/
- public Group addGroup(Group newGroup) {
+ public Group newGroup(Group newGroup) {
// Push a new group
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
groups.put(newGroup.getName().toLowerCase(), newGroup);
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java
index 09eabb43f..e580918e7 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java
@@ -50,8 +50,15 @@ public class Group extends DataUnit implements Cloneable {
*/
@Override
public Group clone() {
- Group clone = new Group(getDataSource(), this.getName());
- clone.inherits = new ArrayList<String>(this.getInherits());
+ Group clone;
+
+ if (getDataSource() == null) {
+ clone = new Group(this.getName());
+ } else {
+ clone = new Group(getDataSource(), this.getName());
+ clone.inherits = new ArrayList<String>(this.getInherits());
+ }
+
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index c8aa15cec..a9f7e3f6e 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -207,6 +207,11 @@ public class WorldDataHolder {
* @param groupToAdd
*/
public void addGroup(Group groupToAdd) {
+ if (groupToAdd.getName().startsWith("g:")) {
+ GroupManager.getGlobalGroups().addGroup(groupToAdd);
+ return;
+ }
+
if (groupToAdd.getDataSource() != this) {
groupToAdd = groupToAdd.clone(this);
}
@@ -263,7 +268,7 @@ public class WorldDataHolder {
public Group createGroup(String groupName) {
if (groupName.startsWith("g:")) {
Group newGroup = new Group(groupName);
- return GroupManager.getGlobalGroups().addGroup(newGroup);
+ return GroupManager.getGlobalGroups().newGroup(newGroup);
}
if (this.groups.containsKey(groupName.toLowerCase())) {