-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
GriefPreventionLocationExtension.java
95 lines (79 loc) · 3.25 KB
/
GriefPreventionLocationExtension.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
package net.gnomeffinway.depenizen.extensions.griefprevention;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.objects.griefprevention.GriefPreventionClaim;
public class GriefPreventionLocationExtension extends dObjectExtension {
static DataStore dataStore = GriefPrevention.instance.dataStore;
public static boolean describes(dObject object) {
return object instanceof dLocation;
}
public static GriefPreventionLocationExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new GriefPreventionLocationExtension((dLocation) object);
}
}
///////////////////
// Instance Fields and Methods
/////////////
private GriefPreventionLocationExtension(dLocation location) {
this.location = location;
}
dLocation location;
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("grief_protection")
|| attribute.startsWith("gp")
|| attribute.startsWith("griefprotection")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <l@location.griefprotection.has_claim>
// @returns Element(Boolean)
// @description
// Returns whether there is a GriefPreventionClaim at this location.
// @plugin Depenizen, GriefPrevention
// -->
if (attribute.startsWith("has_claim")) {
Element ignoreHeight = Element.TRUE;
if (attribute.hasContext(1)) {
ignoreHeight = new Element(attribute.getContext(1));
if (!ignoreHeight.asString().isEmpty() || !ignoreHeight.isBoolean()) {
ignoreHeight = Element.TRUE;
}
}
return new Element(dataStore.getClaimAt(location, ignoreHeight.asBoolean(), null) != null).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <l@location.griefprotection.get_claim>
// @returns GriefPreventionClaim
// @description
// Returns the GriefPreventionClaim at this location.
// @plugin Depenizen, GriefPrevention
// -->
else if (attribute.startsWith("get_claim")) {
Claim claim = dataStore.getClaimAt(location, false, null);
if (claim == null) {
return null;
}
return new GriefPreventionClaim(claim).getAttribute(attribute.fulfill(1));
}
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
}
}