-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
dFaction.java
323 lines (279 loc) · 9.86 KB
/
dFaction.java
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package com.denizenscript.depenizen.bukkit.objects;
import com.massivecraft.factions.entity.*;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.ps.PS;
import net.aufdemrand.denizen.objects.dChunk;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Fetchable;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import java.util.Set;
public class dFaction implements dObject {
/////////////////////
// OBJECT FETCHER
/////////////////
public static dFaction valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("faction")
public static dFaction valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
////////
// Match faction name
string = string.replace("faction@", "");
Faction faction = FactionColl.get().getByName(string);
if (faction != null) {
return new dFaction(faction);
}
return null;
}
public static boolean matches(String arg) {
if (valueOf(arg) != null) {
return true;
}
return false;
}
/////////////////////
// STATIC CONSTRUCTORS
/////////////////
Faction faction = null;
public dFaction(Faction faction) {
if (faction != null) {
this.faction = faction;
}
else {
dB.echoError("Faction referenced is null!");
}
}
public Faction getFaction() {
return faction;
}
/////////////////////
// dObject Methods
/////////////////
private String prefix = "Faction";
@Override
public String getPrefix() {
return prefix;
}
@Override
public dObject setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "Faction";
}
@Override
public String identify() {
return "faction@" + faction.getName();
}
@Override
public String identifySimple() {
// TODO: Properties?
return identify();
}
@Override
public String toString() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <faction@faction.balance>
// @returns Element(Decimal)
// @description
// Returns the amount of money the faction currently has.
// @Plugin DepenizenBukkit, Factions
// -->
if (attribute.startsWith("balance")) {
return new Element(Money.get(faction))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.home>
// @returns dLocation
// @description
// Returns the location of the faction's home, if any.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("home")) {
if (faction.hasHome()) {
return new dLocation(faction.getHome().asBukkitLocation())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <faction@faction.id>
// @returns Element
// @description
// Returns the unique ID for this faction.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("id")) {
return new Element(faction.getId()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.is_open>
// @returns Element(Boolean)
// @description
// Returns true if the faction is open.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("isopen") || attribute.startsWith("is_open")) {
return new Element(faction.isOpen())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.is_peaceful>
// @returns Element(Boolean)
// @description
// Returns true if the faction is peaceful.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("ispeaceful") || attribute.startsWith("is_peaceful")) {
return new Element(faction.getFlag(MFlag.getFlagPeaceful()))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.is_permanent>
// @returns Element(Boolean)
// @description
// Returns true if the faction is permanent.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("ispermanent") || attribute.startsWith("is_permanent")) {
return new Element(faction.getFlag(MFlag.getFlagPermanent()))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.leader>
// @returns dPlayer
// @description
// Returns the faction's leader as a dPlayer.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("leader")) {
if (faction.getLeader() != null) {
return dPlayer.valueOf(faction.getLeader().getName())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <faction@faction.name>
// @returns Element
// @description
// Returns the name of the faction.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("name")) {
return new Element(faction.getName())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.player_count>
// @returns Element(Number)
// @description
// Returns the number of players in the faction.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("playercount") || attribute.startsWith("player_count")) {
return new Element(faction.getMPlayers().size())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.power>
// @returns Element(Decimal)
// @description
// Returns the amount of power the faction currently has.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("power")) {
return new Element(faction.getPower())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.relation[<faction>]>
// @returns Element
// @description
// Returns the current relation between the faction and another faction.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("relation")) {
dFaction to = valueOf(attribute.getContext(1));
if (to != null) {
return new Element(faction.getRelationTo(to.getFaction()).toString())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <faction@faction.size>
// @returns Element(Number)
// @description
// Returns the amount of land the faction has.
// @Plugin DepenizenBukkit, Factions
// -->
else if (attribute.startsWith("size")) {
return new Element(faction.getLandCount())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.type>
// @returns Element
// @description
// Always returns 'Faction' for dFaction objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// @Plugin DepenizenBukkit, Factions
// -->
if (attribute.startsWith("type")) {
return new Element("Faction").getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.claimed_chunks>
// @returns dList(dChunk)
// @description
// Returns a list of all chunks claimed in the faction.
// @Plugin DepenizenBukkit, Factions
// -->
if (attribute.startsWith("claimed_chunks")) {
Set<PS> chunks = BoardColl.get().getChunks(faction);
dList dchunks = new dList();
for (PS ps : chunks) {
dchunks.add(new dChunk(ps.asBukkitChunk()).identify());
}
return dchunks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <faction@faction.list_players>
// @returns dList(dPlayer)
// @description
// Returns a list of all players in the faction.
// @Plugin DepenizenBukkit, Factions
// -->
if (attribute.startsWith("list_players")) {
Set<PS> chunks = BoardColl.get().getChunks(faction);
dList players = new dList();
for (MPlayer ps : faction.getMPlayers()) {
players.add(dPlayer.valueOf(faction.getLeader().getUuid().toString()).identify());
}
return players.getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
}