-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
EssentialsPlayerExtension.java
343 lines (310 loc) · 12.3 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
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
package com.denizenscript.depenizen.bukkit.extensions.essentials;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.tags.Attribute;
import com.denizenscript.depenizen.bukkit.extensions.dObjectExtension;
import com.denizenscript.depenizen.bukkit.bridges.EssentialsBridge;
import java.util.GregorianCalendar;
public class EssentialsPlayerExtension extends dObjectExtension {
public static boolean describes(dObject object) {
return object instanceof dPlayer && ((dPlayer) object).isOnline();
}
public static EssentialsPlayerExtension getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new EssentialsPlayerExtension((dPlayer) object);
}
}
///////////////////
// Instance Fields and Methods
/////////////
public static final String[] handledTags = new String[] {
"god_mode", "has_home", "is_afk", "is_muted", "is_vanished", "home_list", "home_location_list",
"ignored_players", "home_name_list", "mail_list", "mute_timout", "socialspy"
};
public static final String[] handledMechs = new String[] {
"is_afk", "god_mode", "is_muted", "socialspy", "vanish", "essentials_ignore"
};
private EssentialsPlayerExtension(dPlayer player) {
this.player = player;
}
public User getUser() {
return ((Essentials) EssentialsBridge.instance.plugin).getUser(player.getOfflinePlayer().getUniqueId());
}
dPlayer player;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <p@player.god_mode>
// @returns Element(Boolean)
// @mechanism dPlayer.god_mode
// @description
// Returns whether the player is currently in god mode.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("god_mode")) {
return new Element(getUser().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 Depenizen, Essentials
// -->
if (attribute.startsWith("has_home")) {
return new Element(getUser().hasHome()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.is_afk>
// @returns Element(Boolean)
// @mechanism dPlayer.is_afk
// @description
// Returns whether the player is AFK.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("is_afk")) {
return new Element(getUser().isAfk()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.is_muted>
// @returns Element(Boolean)
// @mechanism dPlayer.is_muted
// @description
// Returns whether the player is muted.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("is_muted")) {
return new Element(getUser().isMuted()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.is_vanished>
// @returns Element(Boolean)
// @mechanism dPlayer.is_vanished
// @description
// Returns whether the player is vanished.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("is_vanished")) {
return new Element(getUser().isVanished()).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 Depenizen, Essentials
// -->
if (attribute.startsWith("home_list")) {
dList homes = new dList();
for (String home : getUser().getHomes()) {
try {
homes.add(home + "/" + new dLocation(getUser().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 Depenizen, Essentials
// -->
if (attribute.startsWith("home_location_list")) {
dList homes = new dList();
for (String home : getUser().getHomes()) {
try {
homes.add(new dLocation(getUser().getHome(home)).identifySimple());
}
catch (Exception e) {
if (!attribute.hasAlternative()) {
dB.echoError(e);
}
}
}
return homes.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.ignored_players>
// @returns dList(dPlayer)
// @description
// Returns a list of the ignored players of the player.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("ignored_players")) {
dList players = new dList();
Essentials ess = (Essentials) EssentialsBridge.instance.plugin;
for (String player : getUser()._getIgnoredPlayers()) {
try {
players.add(new dPlayer(ess.getOfflineUser(player).getBase()).identifySimple());
}
catch (Exception e) {
if (!attribute.hasAlternative()) {
dB.echoError(e);
}
}
}
return players.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 Depenizen, Essentials
// -->
if (attribute.startsWith("home_name_list")) {
return new dList(getUser().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 Depenizen, Essentials
// -->
if (attribute.startsWith("mail_list")) {
return new dList(getUser().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 Depenizen, Essentials
// -->
if (attribute.startsWith("mute_timeout")) {
return new Duration((int) (getUser().getMuteTimeout() - new GregorianCalendar().getTimeInMillis()) / 1000)
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.socialspy>
// @returns Element(Boolean)
// @mechanism dPlayer.socialspy
// @description
// Returns whether the player has SocialSpy enabled.
// @Plugin Depenizen, Essentials
// -->
if (attribute.startsWith("socialspy")) {
return new Element(getUser().isSocialSpyEnabled()).getAttribute(attribute.fulfill(1));
}
return null;
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object dPlayer
// @name is_afk
// @input Element(Boolean)
// @description
// Sets whether the player is marked as AFK.
// @tags
// <p@player.is_afk>
// @Plugin Depenizen, Essentials
// -->
if ((mechanism.matches("afk") || mechanism.matches("is_afk")) && mechanism.requireBoolean()) {
getUser().setAfk(mechanism.getValue().asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name god_mode
// @input Element(Boolean)
// @description
// Sets whether the player has god mode enabled.
// @tags
// <p@player.god_mode>
// @Plugin Depenizen, Essentials
// -->
if (mechanism.matches("god_mode") && mechanism.requireBoolean()) {
getUser().setGodModeEnabled(mechanism.getValue().asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name is_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.
// @tags
// <p@player.is_muted>
// <p@player.mute_timeout>
// @Plugin Depenizen, Essentials
// -->
if ((mechanism.matches("muted") || mechanism.matches("is_muted")) && mechanism.requireBoolean()) {
if (mechanism.getValue().asString().length() > 0) {
dList split = mechanism.valueAsType(dList.class);
if (split.size() > 0 && new Element(split.get(0)).isBoolean()) {
getUser().setMuted(new Element(split.get(0)).asBoolean());
if (split.size() > 1 && Duration.matches(split.get(1))) {
getUser().setMuteTimeout(new GregorianCalendar().getTimeInMillis()
+ Duration.valueOf(split.get(1)).getMillis());
}
}
else {
dB.echoError("'" + split.get(0) + "' is not a valid boolean!");
}
}
}
// <--[mechanism]
// @object dPlayer
// @name socialspy
// @input Element(Boolean)
// @description
// Sets whether the player has SocialSpy enabled.
// @tags
// <p@player.socialspy>
// @Plugin Depenizen, Essentials
// -->
if (mechanism.matches("socialspy") && mechanism.requireBoolean()) {
getUser().setSocialSpyEnabled(mechanism.getValue().asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name vanish
// @input Element(Boolean)
// @description
// Sets whether the player has vanish enabled.
// @tags
// <p@player.is_vanished>
// @Plugin Depenizen, Essentials
// -->
if (mechanism.matches("vanish") && mechanism.requireBoolean()) {
getUser().setVanished(mechanism.getValue().asBoolean());
}
// <--[mechanism]
// @object dPlayer
// @name essentials_ignore
// @input Element(dPlayer)(|Boolean)
// @description
// Sets whether the player should ignore anther player. If no boolean is provided, it is by default true.
// @tags
// <p@player.ignored_players>
// @Plugin Depenizen, Essentials
// -->
if (mechanism.matches("essentials_ignore")) {
Essentials ess = (Essentials) EssentialsBridge.instance.plugin;
if (mechanism.getValue().asString().contains("|")) {
int split = mechanism.getValue().asString().indexOf("|");
int len = mechanism.getValue().asString().length();
String after = mechanism.getValue().asString().substring(split + 1, len);
String before = mechanism.getValue().asString().substring(0, split - 1);
getUser().setIgnoredPlayer(ess.getUser(new Element(before).asType(dPlayer.class, mechanism.context).getOfflinePlayer().getUniqueId()), new Element(after).asBoolean());
}
else {
getUser().setIgnoredPlayer(ess.getUser(mechanism.valueAsType(dPlayer.class).getOfflinePlayer().getUniqueId()), true);
}
}
}
}