-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
GriefPreventionPlayerProperties.java
158 lines (136 loc) · 5.82 KB
/
GriefPreventionPlayerProperties.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
package com.denizenscript.depenizen.bukkit.properties.griefprevention;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import me.ryanhamshire.GriefPrevention.PlayerData;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.depenizen.bukkit.objects.griefprevention.GriefPreventionClaimTag;
public class GriefPreventionPlayerProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "GriefPreventionPlayer";
}
static DataStore dataStore = GriefPrevention.instance.dataStore;
public static boolean describes(ObjectTag object) {
return object instanceof PlayerTag;
}
public static GriefPreventionPlayerProperties getFrom(ObjectTag object) {
if (!describes(object)) {
return null;
}
else {
return new GriefPreventionPlayerProperties((PlayerTag) object);
}
}
public static final String[] handledTags = new String[] {
"griefprevention"
};
public static final String[] handledMechs = new String[] {
"bonus_blocks", "normal_blocks"
};
private GriefPreventionPlayerProperties(PlayerTag player) {
this.player = player;
data = dataStore.getPlayerData(player.getOfflinePlayer().getUniqueId());
}
PlayerData data;
PlayerTag player;
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("grief_prevention")
|| attribute.startsWith("gp")
|| attribute.startsWith("griefprevention")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <PlayerTag.griefprevention.list_claims>
// @returns ListTag(GriefPreventionClaimTag)
// @plugin Depenizen, GriefPrevention
// @description
// Returns a list of all claims the player has.
// -->
if (attribute.startsWith("list_claims")) {
ListTag claims = new ListTag();
for (Claim claim : data.getClaims()) {
claims.addObject(new GriefPreventionClaimTag(claim));
}
return claims.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.griefprevention.claims>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the number of claims the player has in GriefPrevention.
// -->
else if (attribute.startsWith("claims")) {
return new ElementTag(data.getClaims().size()).getAttribute(attribute.fulfill(1));
}
else if (attribute.startsWith("blocks")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <PlayerTag.griefprevention.blocks.remaining>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the number of claim blocks the player has left.
// -->
if (attribute.startsWith("remaining")) {
return new ElementTag(data.getRemainingClaimBlocks()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.griefprevention.blocks.bonus>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the number of bonus claim blocks the player has.
// -->
else if (attribute.startsWith("bonus")) {
return new ElementTag(data.getBonusClaimBlocks()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.griefprevention.blocks.total>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the total number of claim blocks the player has.
// -->
else if (attribute.startsWith("total")) {
return new ElementTag(data.getAccruedClaimBlocks() + data.getBonusClaimBlocks())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.griefprevention.blocks>
// @returns ElementTag(Number)
// @plugin Depenizen, GriefPrevention
// @description
// Returns the number of normal claim blocks the payer has.
// -->
else {
return new ElementTag(data.getAccruedClaimBlocks()).getAttribute(attribute);
}
}
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("bonus_blocks") && mechanism.requireInteger()) {
data.setBonusClaimBlocks(mechanism.getValue().asInt());
}
if (mechanism.matches("normal_blocks") && mechanism.requireInteger()) {
data.setAccruedClaimBlocks(mechanism.getValue().asInt());
}
}
}