blob: c734b208ec69f0a9a247973e8b67aa79f758748a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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();
}
}
|