-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
GriefPreventionClaim.java
247 lines (217 loc) · 7.77 KB
/
GriefPreventionClaim.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
package com.morphanone.depenizenbukkit.objects.griefprevention;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.aufdemrand.denizen.objects.dChunk;
import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import org.bukkit.Chunk;
public class GriefPreventionClaim implements dObject, Adjustable {
static DataStore dataStore = GriefPrevention.instance.dataStore;
public static boolean matches(String id) {
return valueOf(id) != null;
}
public static GriefPreventionClaim valueOf(String id) {
return valueOf(id, null);
}
@Fetchable("gpclaim")
public static GriefPreventionClaim 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 GriefPreventionClaim(claim);
}
public GriefPreventionClaim(Claim claim) {
this.claim = claim;
}
private String prefix;
Claim claim;
@Override
public dObject 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();
}
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 <gpclaim@gpclaim.id>
// @returns Element(Number)
// @description
// Returns the GriefPreventionClaim's ID.
// @plugin Depenizen, GriefPrevention
// -->
if (attribute.startsWith("id")) {
return new Element(claim.getID()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <gpclaim@gpclaim.owner>
// @returns dPlayer/Element
// @description
// Returns the GriefPreventionClaim's owner.
// Can be "Admin" or a dPlayer.
// @mechanism GriefPreventionClaim.owner
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("owner")) {
if (claim.isAdminClaim()) {
return new Element("Admin").getAttribute(attribute.fulfill(1));
}
return new dPlayer(claim.ownerID)
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <gpclaim@gpclaim.cuboid>
// @returns dCuboid
// @description
// Returns the GriefPreventionClaim's cuboid area.
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("cuboid")) {
dLocation lower = new dLocation(claim.getLesserBoundaryCorner());
lower.setY(0);
dLocation upper = new dLocation(claim.getGreaterBoundaryCorner());
upper.setY(255);
return new dCuboid(lower, upper).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <gpclaim@gpclaim.is_adminclaim>
// @returns Element(Boolean)
// @description
// Returns whether GriefPreventionClaim is an Admin Claim.
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("is_adminclaim") || attribute.startsWith("is_admin_claim")) {
return new Element(claim.isAdminClaim()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <gpclaim@gpclaim.chunks>
// @returns dList(dChunk)
// @description
// Returns a list of all chunks in the GriefPreventionClaim.
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("chunks")) {
dList chunks = new dList();
for (Chunk chunk : claim.getChunks()) {
chunks.add(new dChunk(chunk).identify());
}
return chunks.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <gpclaim@gpclaim.can_siege[<player>]>
// @returns Element(Boolean)
// @description
// Returns whether the GriefPreventionClaim can siege the player.
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("can_siege") && attribute.hasContext(1)) {
dPlayer defender = dPlayer.valueOf(attribute.getContext(1));
if (defender == null || defender.getPlayerEntity() == null) {
return null;
}
return new Element(claim.canSiege(defender.getPlayerEntity())).getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
// <--[mechanism]
// @object GriefPreventionClaim
// @name owner
// @input dPlayer/Element
// @description
// Sets the owner of the GriefPreventionClaim.
// Accepts dPlayer or "admin" to set as admin claim.
// @tags
// <gpclaim@gpclaim.owner>
// -->
if (mechanism.matches("owner")) {
try {
if (dPlayer.matches(value.asString())) {
dPlayer player = dPlayer.valueOf(value.asString());
dataStore.changeClaimOwner(claim, player.getOfflinePlayer().getUniqueId());
}
else if (CoreUtilities.toLowerCase(value.asString()).equals("admin")) {
dataStore.changeClaimOwner(claim, null);
}
}
catch (Exception e) {
dB.echoError("Unable to transfer ownership of claim: " + this.identify() + ".");
}
}
// <--[mechanism]
// @object GriefPreventionClaim
// @name depth
// @input Element(Number)
// @description
// Sets the protection depth of the GriefPreventionClaim.
// @tags
// None
// -->
if (mechanism.matches("depth") && mechanism.requireInteger()) {
dataStore.extendClaim(claim, value.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) {
dB.echoError("Cannot apply Properties to a GriefPreventionClaim!");
}
}