summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager
diff options
context:
space:
mode:
authorElgarL <ElgarL@palmergames.com>2011-10-31 17:23:24 +0000
committerElgarL <ElgarL@palmergames.com>2011-10-31 17:23:24 +0000
commit3f2916967d88fddc1c69f62ffd7ca572d25d9992 (patch)
tree6e31f90d20a84720d1c2f7731762477fd45ee080 /EssentialsGroupManager
parent0731de53b499592abdffcc6237a5b52db4f5a706 (diff)
downloadEssentials-3f2916967d88fddc1c69f62ffd7ca572d25d9992.tar
Essentials-3f2916967d88fddc1c69f62ffd7ca572d25d9992.tar.gz
Essentials-3f2916967d88fddc1c69f62ffd7ca572d25d9992.tar.lz
Essentials-3f2916967d88fddc1c69f62ffd7ca572d25d9992.tar.xz
Essentials-3f2916967d88fddc1c69f62ffd7ca572d25d9992.zip
Added Info node support to Global Groups.
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r--EssentialsGroupManager/src/Changelog.txt3
-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
4 files changed, 73 insertions, 15 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index 7659e092b..6c23895ec 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -58,4 +58,5 @@ v 1.5:
- Improved error reporting for invalid groups.yml
- Added Global Groups
Defined in groupmanager/globalgroups.yml.
- Create groups in the yml with a g: prefix, then inherit in the worlds groups files. \ No newline at end of file
+ Create groups in the yml with a g: prefix, then inherit in the worlds groups files.
+ - Added Info node support to Global Groups. \ No newline at end of file
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())) {