/
EssentialsPlayerExtension.java
248 lines (220 loc) · 8.24 KB
/
EssentialsPlayerExtension.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
package net.gnomeffinway.depenizen.extensions.essentials;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.support.Supported;
import java.util.GregorianCalendar;
public class EssentialsPlayerExtension extends dObjectExtension {
public static boolean describes(dObject pl) {
return pl instanceof dPlayer && ((dPlayer) pl).isOnline();
}
public static EssentialsPlayerExtension getFrom(dObject pl) {
if (!describes(pl)) return null;
else return new EssentialsPlayerExtension((dPlayer) pl);
}
///////////////////
// Instance Fields and Methods
/////////////
private EssentialsPlayerExtension(dPlayer pl) {
// TODO: UUID
Essentials essentials = Supported.get("ESSENTIALS").getPlugin();
this.essUser = essentials.getUser(pl.getPlayerEntity());
}
User essUser = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <p@player.god_mode>
// @returns Element(Boolean)
// @description
// Returns whether the player is currently in god mode.
// @plugin Essentials
// -->
if (attribute.startsWith("god_mode")) {
return new Element(essUser.isGodModeEnabled()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.has_home>
// @returns Element(Boolean)
// @description
// Returns whether the player has set at least one home.
// @plugin Essentials
// -->
if (attribute.startsWith("has_home")) {
return new Element(essUser.hasHome()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.is_afk>
// @returns Element(Boolean)
// @description
// Returns whether the player is AFK.
// @plugin Essentials
// -->
if (attribute.startsWith("is_afk")) {
return new Element(essUser.isAfk()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.is_muted>
// @returns Element(Boolean)
// @description
// Returns whether the player is muted.
// @plugin Essentials
// -->
if (attribute.startsWith("is_muted")) {
return new Element(essUser.isMuted()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.home_list>
// @returns dList(Element/dLocation)
// @description
// Returns a list of the homes of the player, in the format "HomeName/l@x,y,z,world".
// @plugin Essentials
// -->
if (attribute.startsWith("home_list")) {
dList homes = new dList();
for (String home : essUser.getHomes()) {
try {
homes.add(home + "/" + new dLocation(essUser.getHome(home)).identifySimple());
} catch (Exception e) {
if (!attribute.hasAlternative())
dB.echoError(e);
}
}
return homes.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.home_location_list>
// @returns dList(dLocation)
// @description
// Returns a list of the locations of homes of the player.
// @plugin Essentials
// -->
if (attribute.startsWith("home_location_list")) {
dList homes = new dList();
for (String home : essUser.getHomes()) {
try {
homes.add(new dLocation(essUser.getHome(home)).identifySimple());
} catch (Exception e) {
if (!attribute.hasAlternative())
dB.echoError(e);
}
}
return homes.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.home_name_list>
// @returns dList(Element)
// @description
// Returns a list of the names of homes of the player.
// @plugin Essentials
// -->
if (attribute.startsWith("home_name_list")) {
return new dList(essUser.getHomes()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.mail_list>
// @returns dList(Element)
// @description
// Returns a list of mail the player currently has.
// @plugin Essentials
// -->
if (attribute.startsWith("mail_list")) {
return new dList(essUser.getMails()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.mute_timeout>
// @returns Duration
// @description
// Returns how much time is left until the player is muted.
// @plugin Essentials
// -->
if (attribute.startsWith("mute_timeout")) {
return new Duration((int) (essUser.getMuteTimeout() - new GregorianCalendar().getTimeInMillis())/1000)
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.socialspy>
// @returns Element(Boolean)
// @description
// Returns whether the player has SocialSpy enabled.
// @plugin Essentials
// -->
if (attribute.startsWith("socialspy")) {
return new Element(essUser.isSocialSpyEnabled()).getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
// <--[mechanism]
// @object dPlayer
// @name afk
// @input Element(Boolean)
// @description
// Sets whether the player is marked as AFK.
// @extensions
// <player.is_afk>
// @plugin Essentials
// -->
if (mechanism.matches("afk") && mechanism.requireBoolean()) {
essUser.setAfk(value.asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name god_mode
// @input Element(Boolean)
// @description
// Sets whether the player has god mode enabled.
// @extensions
// <player.god_mode>
// @plugin Essentials
// -->
if (mechanism.matches("god_mode") && mechanism.requireBoolean()) {
essUser.setGodModeEnabled(value.asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name muted
// @input Element(Boolean)(|Duration)
// @description
// Sets whether the player is muted. Optionally, you may also
// specify a duration to set how long they are muted for.
// @extensions
// <player.is_muted>
// <player.mute_timeout>
// @plugin Essentials
// -->
if (mechanism.matches("muted") && mechanism.requireBoolean()) {
if (value.asString().length() > 0) {
String[] split = value.asString().split("[\\|" + dList.internal_escape + "]", 2);
if (split.length > 0 && new Element(split[0]).isBoolean()) {
essUser.setMuted(new Element(split[0]).asBoolean());
if (split.length > 1 && Duration.matches(split[1])) {
essUser.setMuteTimeout(new GregorianCalendar().getTimeInMillis()
+ Duration.valueOf(split[1]).getMillis());
}
}
else {
dB.echoError("'" + split[0] + "' is not a valid boolean!");
}
}
}
// <--[mechanism]
// @object dPlayer
// @name socialspy
// @input Element(Boolean)
// @description
// Sets whether the player has SocialSpy enabled.
// @extensions
// <player.socialspy>
// @plugin Essentials
// -->
if (mechanism.matches("socialspy") && mechanism.requireBoolean()) {
essUser.setSocialSpyEnabled(value.asBoolean());
}
}
}