-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
GriefPreventionClaimTag.java
362 lines (324 loc) · 12.3 KB
/
GriefPreventionClaimTag.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package com.denizenscript.depenizen.bukkit.objects.griefprevention;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import com.denizenscript.denizen.objects.ChunkTag;
import com.denizenscript.denizen.objects.CuboidTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Chunk;
import java.util.ArrayList;
import java.util.UUID;
public class GriefPreventionClaimTag implements ObjectTag, Adjustable {
// <--[language]
// @name GriefPreventionClaimTag Objects
// @group Depenizen Object Types
// @plugin Depenizen, GriefPrevention
// @description
// A GriefPreventionClaimTag represents a GriefPrevention claim.
//
// These use the object notation "gpclaim@".
// The identity format for claims is <claim_id>
// For example, 'gpclaim@1234'.
//
// -->
static DataStore dataStore = GriefPrevention.instance.dataStore;
public static boolean matches(String id) {
return valueOf(id) != null;
}
public static GriefPreventionClaimTag valueOf(String id) {
return valueOf(id, null);
}
@Fetchable("gpclaim")
public static GriefPreventionClaimTag valueOf(String id, TagContext context) {
long claimID;
id = id.replace("gpclaim@", "");
try {
claimID = Long.valueOf(id);
}
catch (NumberFormatException e) {
return null;
}
Claim claim = dataStore.getClaim(claimID);
if (claim == null) {
return null;
}
return new GriefPreventionClaimTag(claim);
}
public GriefPreventionClaimTag(Claim claim) {
this.claim = claim;
}
private String prefix;
Claim claim;
@Override
public ObjectTag setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public String debug() {
return prefix + "='<A>" + identify() + "<G>' ";
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "GriefPreventionClaim";
}
@Override
public String identify() {
return "gpclaim@" + claim.getID();
}
@Override
public String toString() {
return identify();
}
public String simple() {
return String.valueOf(claim.getID());
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.id>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's ID.
// -->
if (attribute.startsWith("id")) {
return new ElementTag(claim.getID()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.managers>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's managers.
// -->
if (attribute.startsWith("managers")) {
ListTag managers = new ListTag();
for (String manager : claim.managers) {
managers.addObject(new PlayerTag(UUID.fromString(manager)));
}
return managers.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.trusted>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's trusted.
// -->
if (attribute.startsWith("trusted")) {
ListTag trusted = new ListTag();
ArrayList<String> b = new ArrayList<>();
claim.getPermissions(b, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
for (String trust : b) {
trusted.addObject(new PlayerTag(UUID.fromString(trust)));
}
return trusted.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.builders>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's builders.
// -->
if (attribute.startsWith("builders")) {
ListTag trusted = new ListTag();
ArrayList<String> b = new ArrayList<>();
claim.getPermissions(b, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
for (String trust : b) {
trusted.addObject(new PlayerTag(UUID.fromString(trust)));
}
return trusted.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.containers>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's containers.
// -->
if (attribute.startsWith("containers")) {
ListTag trusted = new ListTag();
ArrayList<String> c = new ArrayList<>();
claim.getPermissions(new ArrayList<>(), c, new ArrayList<>(), new ArrayList<>());
for (String container : c) {
trusted.addObject(new PlayerTag(UUID.fromString(container)));
}
return trusted.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.accessors>
// @returns ListTag(PlayerTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's accessors.
// -->
if (attribute.startsWith("accessors")) {
ListTag trusted = new ListTag();
ArrayList<String> a = new ArrayList<>();
claim.getPermissions(new ArrayList<>(), new ArrayList<>(), a, new ArrayList<>());
for (String access : a) {
trusted.addObject(new PlayerTag(UUID.fromString(access)));
}
return trusted.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.owner>
// @returns PlayerTag/Element
// @mechanism GriefPreventionClaim.owner
// @Plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's owner.
// Can be "Admin" or a PlayerTag.
// -->
else if (attribute.startsWith("owner")) {
if (claim.isAdminClaim()) {
return new ElementTag("Admin").getAttribute(attribute.fulfill(1));
}
return new PlayerTag(claim.ownerID)
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.cuboid>
// @returns CuboidTag
// @Plugin Depenizen, GriefPrevention
// @description
// Returns the GriefPreventionClaim's cuboid area.
// -->
else if (attribute.startsWith("cuboid")) {
LocationTag lower = new LocationTag(claim.getLesserBoundaryCorner());
lower.setY(0);
LocationTag upper = new LocationTag(claim.getGreaterBoundaryCorner());
upper.setY(255);
return new CuboidTag(lower, upper).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.is_adminclaim>
// @returns ElementTag(Boolean)
// @plugin Depenizen, GriefPrevention
// @description
// Returns whether GriefPreventionClaim is an Admin Claim.
// -->
else if (attribute.startsWith("is_adminclaim") || attribute.startsWith("is_admin_claim")) {
return new ElementTag(claim.isAdminClaim()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.chunks>
// @returns ListTag(ChunkTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns a list of all chunks in the GriefPreventionClaim.
// -->
else if (attribute.startsWith("chunks")) {
ListTag chunks = new ListTag();
for (Chunk chunk : claim.getChunks()) {
chunks.addObject(new ChunkTag(chunk));
}
return chunks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.can_siege[<player>]>
// @returns ElementTag(Boolean)
// @plugin Depenizen, GriefPrevention
// @description
// Returns whether the GriefPreventionClaim can siege the player.
// -->
else if (attribute.startsWith("can_siege") && attribute.hasContext(1)) {
PlayerTag defender = PlayerTag.valueOf(attribute.getContext(1));
if (defender == null || defender.getPlayerEntity() == null) {
return null;
}
return new ElementTag(claim.canSiege(defender.getPlayerEntity())).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <GriefPreventionClaimTag.is_sieged>
// @returns ElementTag(Boolean)
// @plugin Depenizen, GriefPrevention
// @description
// Returns whether the GriefPreventionClaim is currently under siege.
// -->
else if (attribute.startsWith("is_sieged")) {
return new ElementTag(claim.siegeData != null).getAttribute(attribute.fulfill(1));
}
return new ElementTag(identify()).getAttribute(attribute);
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object GriefPreventionClaim
// @name owner
// @input PlayerTag/Element
// @description
// Sets the owner of the GriefPreventionClaim.
// Accepts PlayerTag or "admin" to set as admin claim.
// @tags
// <GriefPreventionClaimTag.owner>
// -->
if (mechanism.matches("owner")) {
try {
if (PlayerTag.matches(mechanism.getValue().asString())) {
PlayerTag player = PlayerTag.valueOf(mechanism.getValue().asString());
dataStore.changeClaimOwner(claim, player.getOfflinePlayer().getUniqueId());
}
else if (CoreUtilities.toLowerCase(mechanism.getValue().asString()).equals("admin")) {
dataStore.changeClaimOwner(claim, null);
}
}
catch (Exception e) {
Debug.echoError("Unable to transfer ownership of claim: " + this.identify() + ".");
}
}
// <--[mechanism]
// @object GriefPreventionClaim
// @name depth
// @input ElementTag(Number)
// @description
// Sets the protection depth of the GriefPreventionClaim.
// @tags
// None
// -->
if (mechanism.matches("depth") && mechanism.requireInteger()) {
dataStore.extendClaim(claim, mechanism.getValue().asInt());
}
// Iterate through this object's properties' mechanisms
for (Property property : PropertyParser.getProperties(this)) {
property.adjust(mechanism);
if (mechanism.fulfilled()) {
break;
}
}
if (!mechanism.fulfilled()) {
mechanism.reportInvalid();
}
}
@Override
public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply Properties to a GriefPreventionClaim!");
}
}