-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
FactionTag.java
332 lines (289 loc) · 10.3 KB
/
FactionTag.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
324
325
326
327
328
329
330
331
332
package com.denizenscript.depenizen.bukkit.objects.factions;
import com.massivecraft.factions.entity.*;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.ps.PS;
import com.denizenscript.denizen.objects.ChunkTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Fetchable;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import java.util.Set;
public class FactionTag implements ObjectTag {
// <--[language]
// @name FactionTag Objects
// @group Depenizen Object Types
// @plugin Depenizen, Factions
// @description
// A FactionTag represents a Factions faction.
//
// These use the object notation "faction@".
// The identity format for factions is <faction_name>
// For example, 'faction@my_faction'.
//
// -->
/////////////////////
// OBJECT FETCHER
/////////////////
public static FactionTag valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("faction")
public static FactionTag 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 FactionTag(faction);
}
return null;
}
public static boolean matches(String arg) {
if (valueOf(arg) != null) {
return true;
}
return false;
}
/////////////////////
// STATIC CONSTRUCTORS
/////////////////
Faction faction = null;
public FactionTag(Faction faction) {
if (faction != null) {
this.faction = faction;
}
else {
Debug.echoError("Faction referenced is null!");
}
}
public Faction getFaction() {
return faction;
}
/////////////////////
// ObjectTag Methods
/////////////////
private String prefix = "Faction";
@Override
public String getPrefix() {
return prefix;
}
@Override
public ObjectTag 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 <FactionTag.balance>
// @returns ElementTag(Decimal)
// @plugin Depenizen, Factions
// @description
// Returns the amount of money the faction currently has.
// -->
if (attribute.startsWith("balance")) {
return new ElementTag(Money.get(faction))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.warp[<name>]>
// @returns LocationTag
// @plugin Depenizen, Factions
// @description
// Returns the location of the faction's warp by name, if any.
// Note that this was previously named "home" instead of "warp".
// -->
else if (attribute.startsWith("warp") && attribute.hasContext(1)) {
Warp warp = faction.getWarp(attribute.getContext(1));
if (warp != null) {
return new LocationTag(warp.getLocation().asBukkitLocation())
.getAttribute(attribute.fulfill(1));
}
}
else if (attribute.startsWith("home")) { // Legacy sorta-compat
Warp warp = faction.getWarp("home");
if (warp != null) {
return new LocationTag(warp.getLocation().asBukkitLocation())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <FactionTag.id>
// @returns ElementTag
// @plugin Depenizen, Factions
// @description
// Returns the unique ID for this faction.
// -->
else if (attribute.startsWith("id")) {
return new ElementTag(faction.getId()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.is_open>
// @returns ElementTag(Boolean)
// @plugin Depenizen, Factions
// @description
// Returns true if the faction is open.
// -->
else if (attribute.startsWith("isopen") || attribute.startsWith("is_open")) {
return new ElementTag(faction.isOpen())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.is_peaceful>
// @returns ElementTag(Boolean)
// @plugin Depenizen, Factions
// @description
// Returns true if the faction is peaceful.
// -->
else if (attribute.startsWith("ispeaceful") || attribute.startsWith("is_peaceful")) {
return new ElementTag(faction.getFlag(MFlag.getFlagPeaceful()))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.is_permanent>
// @returns ElementTag(Boolean)
// @plugin Depenizen, Factions
// @description
// Returns true if the faction is permanent.
// -->
else if (attribute.startsWith("ispermanent") || attribute.startsWith("is_permanent")) {
return new ElementTag(faction.getFlag(MFlag.getFlagPermanent()))
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.leader>
// @returns PlayerTag
// @plugin Depenizen, Factions
// @description
// Returns the faction's leader as a PlayerTag.
// -->
else if (attribute.startsWith("leader")) {
if (faction.getLeader() != null) {
return PlayerTag.valueOf(faction.getLeader().getName(), attribute.context)
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <FactionTag.name>
// @returns ElementTag
// @plugin Depenizen, Factions
// @description
// Returns the name of the faction.
// -->
else if (attribute.startsWith("name")) {
return new ElementTag(faction.getName())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.player_count>
// @returns ElementTag(Number)
// @plugin Depenizen, Factions
// @description
// Returns the number of players in the faction.
// -->
else if (attribute.startsWith("playercount") || attribute.startsWith("player_count")) {
return new ElementTag(faction.getMPlayers().size())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.power>
// @returns ElementTag(Decimal)
// @plugin Depenizen, Factions
// @description
// Returns the amount of power the faction currently has.
// -->
else if (attribute.startsWith("power")) {
return new ElementTag(faction.getPower())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.relation[<faction>]>
// @returns ElementTag
// @plugin Depenizen, Factions
// @description
// Returns the current relation between the faction and another faction.
// -->
else if (attribute.startsWith("relation")) {
FactionTag to = valueOf(attribute.getContext(1));
if (to != null) {
return new ElementTag(faction.getRelationTo(to.getFaction()).toString())
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <FactionTag.size>
// @returns ElementTag(Number)
// @plugin Depenizen, Factions
// @description
// Returns the amount of land the faction has.
// -->
else if (attribute.startsWith("size")) {
return new ElementTag(faction.getLandCount())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.claimed_chunks>
// @returns ListTag(ChunkTag)
// @plugin Depenizen, Factions
// @description
// Returns a list of all chunks claimed in the faction.
// -->
if (attribute.startsWith("claimed_chunks")) {
Set<PS> chunks = BoardColl.get().getChunks(faction);
ListTag dchunks = new ListTag();
for (PS ps : chunks) {
dchunks.addObject(new ChunkTag(ps.asBukkitChunk()));
}
return dchunks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <FactionTag.list_players>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, Factions
// @description
// Returns a list of all players in the faction.
// -->
if (attribute.startsWith("list_players")) {
Set<PS> chunks = BoardColl.get().getChunks(faction);
ListTag players = new ListTag();
for (MPlayer ps : faction.getMPlayers()) {
players.addObject(PlayerTag.valueOf(faction.getLeader().getUuid().toString(), attribute.context));
}
return players.getAttribute(attribute.fulfill(1));
}
return new ElementTag(identify()).getAttribute(attribute);
}
}