-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
EssentialsPlayerExtension.java
275 lines (246 loc) · 9.36 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
package net.gnomeffinway.depenizen.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 net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.gnomeffinway.depenizen.support.Support;
import net.gnomeffinway.depenizen.support.plugins.EssentialsSupport;
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
/////////////
private EssentialsPlayerExtension(dPlayer player) {
// TODO: UUID
Essentials essentials = Support.getPlugin(EssentialsSupport.class);
this.essUser = essentials.getUser(player.getOfflinePlayer().getUniqueId());
}
User essUser = null;
@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(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 Depenizen, Essentials
// -->
if (attribute.startsWith("has_home")) {
return new Element(essUser.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(essUser.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(essUser.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(essUser.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 : 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 Depenizen, 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 Depenizen, 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 Depenizen, 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 Depenizen, 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)
// @mechanism dPlayer.socialspy
// @description
// Returns whether the player has SocialSpy enabled.
// @plugin Depenizen, 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 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()) {
essUser.setAfk(value.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()) {
essUser.setGodModeEnabled(value.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 (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.
// @tags
// <p@player.socialspy>
// @plugin Depenizen, Essentials
// -->
if (mechanism.matches("socialspy") && mechanism.requireBoolean()) {
essUser.setSocialSpyEnabled(value.asBoolean());
}
}
}