2011-03-19 23:39:51 +01:00
|
|
|
/*
|
|
|
|
* To change this template, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
|
|
|
package org.anjocaido.groupmanager.data;
|
|
|
|
|
2011-09-03 00:07:23 +02:00
|
|
|
import org.anjocaido.groupmanager.GroupManager;
|
2011-03-19 23:39:51 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
2011-10-31 09:34:07 +01:00
|
|
|
* Constructor for individual World Groups.
|
2011-03-19 23:39:51 +01:00
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
public Group(WorldDataHolder source, String name) {
|
2011-08-14 21:56:40 +02:00
|
|
|
super(source, name);
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
2011-10-31 09:34:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for Global Groups.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
public Group(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
|
|
|
/**
|
2011-08-14 21:56:40 +02:00
|
|
|
* Clone this group
|
2011-03-19 23:39:51 +01:00
|
|
|
* @return a clone of this group
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Group clone() {
|
|
|
|
Group clone = new Group(getDataSource(), this.getName());
|
2011-10-11 23:05:21 +02:00
|
|
|
clone.inherits = new ArrayList<String>(this.getInherits());
|
2011-08-14 21:56:40 +02:00
|
|
|
for (String perm : this.getPermissionList()) {
|
2011-03-19 23:39:51 +01:00
|
|
|
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
|
2011-09-03 00:07:23 +02:00
|
|
|
* @return Null or Clone
|
2011-03-19 23:39:51 +01:00
|
|
|
*/
|
|
|
|
public Group clone(WorldDataHolder dataSource) {
|
|
|
|
if (dataSource.groupExists(this.getName())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Group clone = getDataSource().createGroup(this.getName());
|
2011-10-11 23:05:21 +02:00
|
|
|
clone.inherits = new ArrayList<String>(this.getInherits());
|
2011-08-14 21:56:40 +02:00
|
|
|
for (String perm : this.getPermissionList()) {
|
2011-03-19 23:39:51 +01:00
|
|
|
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() {
|
2011-10-11 23:05:21 +02:00
|
|
|
return new ArrayList<String>(inherits);
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-03 00:07:23 +02:00
|
|
|
* @param inherit the inherits to set
|
2011-03-19 23:39:51 +01:00
|
|
|
*/
|
|
|
|
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();
|
2011-09-25 04:14:38 +02:00
|
|
|
if (GroupManager.isLoaded())
|
2011-09-03 00:07:23 +02:00
|
|
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-14 21:56:40 +02:00
|
|
|
*
|
2011-03-19 23:39:51 +01:00
|
|
|
* @param varList
|
|
|
|
*/
|
|
|
|
public void setVariables(Map<String, Object> varList) {
|
|
|
|
GroupVariables temp = new GroupVariables(this, varList);
|
|
|
|
variables.clearVars();
|
2011-08-14 21:56:40 +02:00
|
|
|
for (String key : temp.getVarKeyList()) {
|
2011-03-19 23:39:51 +01:00
|
|
|
variables.addVar(key, temp.getVarObject(key));
|
|
|
|
}
|
|
|
|
flagAsChanged();
|
2011-09-25 04:14:38 +02:00
|
|
|
if (GroupManager.isLoaded())
|
2011-09-03 00:07:23 +02:00
|
|
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
}
|