diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-19 22:39:51 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-19 22:39:51 +0000 |
commit | a3ebd254f2897951a2ce31fdd90b6944c582d82b (patch) | |
tree | 11c8670882eed130d7ff1b33cc7c65e496f1bbac /EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java | |
parent | 487577f2fa856a61077594ad6677f0bdd7150fcd (diff) | |
download | Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.gz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.lz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.xz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.zip |
Moving all files to trunk.
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@969 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java new file mode 100644 index 000000000..c734b208e --- /dev/null +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -0,0 +1,122 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.anjocaido.groupmanager.data; + +import org.anjocaido.groupmanager.dataholder.WorldDataHolder; +import java.util.ArrayList; +import java.util.Map; + +/** + * + * @author gabrielcouto + */ +public class Group extends DataUnit implements Cloneable { + + /** + * The group it inherits DIRECTLY! + */ + private ArrayList<String> inherits = new ArrayList<String>(); + /** + *This one holds the fields in INFO node. + * like prefix = 'c' + * or build = false + */ + private GroupVariables variables = new GroupVariables(this); + + /** + * + * @param name + */ + public Group(WorldDataHolder source, String name) { + super(source,name); + } + + /** + * Clone this group + * @return a clone of this group + */ + @Override + public Group clone() { + Group clone = new Group(getDataSource(), this.getName()); + clone.inherits = ((ArrayList<String>) this.getInherits().clone()); + for(String perm: this.getPermissionList()){ + clone.addPermission(perm); + } + clone.variables = ((GroupVariables) variables).clone(clone); + //clone.flagAsChanged(); + return clone; + } + + /** + * Use this to deliver a group from a different dataSource to another + * @param dataSource + * @return + */ + public Group clone(WorldDataHolder dataSource) { + if (dataSource.groupExists(this.getName())) { + return null; + } + Group clone = getDataSource().createGroup(this.getName()); + clone.inherits = ((ArrayList<String>) this.getInherits().clone()); + for(String perm: this.getPermissionList()){ + clone.addPermission(perm); + } + clone.variables = variables.clone(clone); + clone.flagAsChanged(); //use this to make the new dataSource save the new group + return clone; + } + + /** + * a COPY of inherits list + * You can't manage the list by here + * Lol... version 0.6 had a problem because this. + * @return the inherits + */ + public ArrayList<String> getInherits() { + return (ArrayList<String>) inherits.clone(); + } + + /** + * @param inherits the inherits to set + */ + public void addInherits(Group inherit) { + if (!this.getDataSource().groupExists(inherit.getName())) { + getDataSource().addGroup(inherit); + } + if (!inherits.contains(inherit.getName().toLowerCase())) { + inherits.add(inherit.getName().toLowerCase()); + } + flagAsChanged(); + } + + public boolean removeInherits(String inherit) { + if (this.inherits.contains(inherit.toLowerCase())) { + this.inherits.remove(inherit.toLowerCase()); + flagAsChanged(); + return true; + } + return false; + } + + /** + * @return the variables + */ + public GroupVariables getVariables() { + return variables; + } + + /** + * + * @param varList + */ + public void setVariables(Map<String, Object> varList) { + GroupVariables temp = new GroupVariables(this, varList); + variables.clearVars(); + for(String key: temp.getVarKeyList()){ + variables.addVar(key, temp.getVarObject(key)); + } + flagAsChanged(); + } +} |