/
MythicMobsMobTag.java
453 lines (406 loc) · 15.1 KB
/
MythicMobsMobTag.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
package com.denizenscript.depenizen.bukkit.objects.mythicmobs;
import com.denizenscript.denizen.objects.EntityFormObject;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
import com.denizenscript.depenizen.bukkit.bridges.MythicMobsBridge;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import io.lumine.xikage.mythicmobs.adapters.AbstractEntity;
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitEntity;
import io.lumine.xikage.mythicmobs.mobs.ActiveMob;
import io.lumine.xikage.mythicmobs.mobs.MythicMob;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import java.util.Map;
import java.util.UUID;
public class MythicMobsMobTag implements ObjectTag, Adjustable {
// <--[ObjectType]
// @name MythicMobsMobTag
// @prefix mythicmob
// @base ElementTag
// @format
// The identity format for MythicMobsMobTag is <uuid>
// For example, 'mythicmob@1234-1234-1234'.
//
// @plugin Depenizen, MythicMobs
// @description
// A MythicMobsMobTag represents a Mythic mob entity in the world.
//
// -->
public static MythicMobsMobTag valueOf(String uuid) {
return valueOf(uuid, null);
}
@Fetchable("mythicmob")
public static MythicMobsMobTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
try {
string = string.replace("mythicmob@", "");
UUID uuid = UUID.fromString(string);
if (!MythicMobsBridge.isMythicMob(uuid)) {
return null;
}
return new MythicMobsMobTag(MythicMobsBridge.getActiveMob(EntityTag.getEntityForID(uuid)));
}
catch (Exception e) {
return null;
}
}
public static boolean matches(String string) {
return valueOf(string) != null;
}
public MythicMobsMobTag(ActiveMob mob) {
if (mob != null) {
this.mob = mob;
this.mobType = mob.getType();
}
else {
Debug.echoError("ActiveMob referenced is null!");
}
}
public ActiveMob getMob() {
return mob;
}
public MythicMob getMobType() {
return mobType;
}
public LivingEntity getLivingEntity() {
return (LivingEntity) mob.getEntity().getBukkitEntity();
}
public Entity getEntity() {
return mob.getEntity().getBukkitEntity();
}
private String prefix;
ActiveMob mob;
MythicMob mobType;
@Override
public ObjectTag setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "MythicMob";
}
@Override
public String identify() {
return "mythicmob@" + mob.getUniqueId();
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String toString() {
return identify();
}
public static ObjectTagProcessor<MythicMobsMobTag> tagProcessor = new ObjectTagProcessor<>();
public static void registerTags() {
// <--[tag]
// @attribute <MythicMobsMobTag.internal_name>
// @returns ElementTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the name MythicMobs identifies the MythicMob with.
// -->
tagProcessor.registerTag(ElementTag.class, "internal_name", (attribute, object) -> {
return new ElementTag(object.getMobType().getInternalName());
});
// <--[tag]
// @attribute <MythicMobsMobTag.display_name>
// @returns ElementTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the display name of the MythicMob.
// -->
tagProcessor.registerTag(ElementTag.class, "display_name", (attribute, object) -> {
return new ElementTag(object.getMob().getDisplayName());
});
// <--[tag]
// @attribute <MythicMobsMobTag.spawner_name>
// @returns ElementTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the name of the spawner (as set on creation in-game) that spawned this mob.
// Returns null, if the mob was spawned by something other than a spawner.
// -->
tagProcessor.registerTag(ElementTag.class, "spawner_name", (attribute, object) -> {
if (object.getMob().getSpawner() == null) {
return null;
}
return new ElementTag(object.getMob().getSpawner().getName());
});
// <--[tag]
// @attribute <MythicMobsMobTag.spawner>
// @returns MythicSpawnerTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the MythicSpawnerTag that spawned this mob.
// Returns null, if the mob was spawned by something other than a spawner.
// -->
tagProcessor.registerTag(MythicSpawnerTag.class, "spawner", (attribute, object) -> {
if (object.getMob().getSpawner() == null) {
return null;
}
return new MythicSpawnerTag(object.getMob().getSpawner());
});
// <--[tag]
// @attribute <MythicMobsMobTag.level>
// @returns ElementTag(Number)
// @plugin Depenizen, MythicMobs
// @mechanism MythicMobsMobTag.level
// @description
// Returns the level of the MythicMob.
// -->
tagProcessor.registerTag(ElementTag.class, "level", (attribute, object) -> {
return new ElementTag(object.getMob().getLevel());
});
// <--[tag]
// @attribute <MythicMobsMobTag.players_killed>
// @returns ElementTag(Number)
// @plugin Depenizen, MythicMobs
// @description
// Returns the number of players the MythicMob has killed.
// -->
tagProcessor.registerTag(ElementTag.class, "players_killed", (attribute, object) -> {
return new ElementTag(object.getMob().getPlayerKills());
});
// <--[tag]
// @attribute <MythicMobsMobTag.damage>
// @returns ElementTag(Decimal)
// @plugin Depenizen, MythicMobs
// @description
// Returns the damage the MythicMob deals.
// -->
tagProcessor.registerTag(ElementTag.class, "damage", (attribute, object) -> {
return new ElementTag(object.getMob().getDamage());
});
// <--[tag]
// @attribute <MythicMobsMobTag.armor>
// @returns ElementTag(Decimal)
// @plugin Depenizen, MythicMobs
// @description
// Returns the armor the MythicMob has.
// -->
tagProcessor.registerTag(ElementTag.class, "armor", (attribute, object) -> {
return new ElementTag(object.getMob().getArmor());
});
// <--[tag]
// @attribute <MythicMobsMobTag.has_target>
// @returns ElementTag(Boolean)
// @plugin Depenizen, MythicMobs
// @description
// Returns whether the MythicMob has a target.
// -->
tagProcessor.registerTag(ElementTag.class, "has_target", (attribute, object) -> {
return new ElementTag(object.getMob().hasTarget());
});
// <--[tag]
// @attribute <MythicMobsMobTag.target>
// @returns EntityTag
// @mechanism MythicMobsMobTag.target
// @plugin Depenizen, MythicMobs
// @description
// Returns the MythicMob's target.
// -->
tagProcessor.registerTag(EntityFormObject.class, "target", (attribute, object) -> {
AbstractEntity target = object.getMob().getThreatTable().getTopThreatHolder();
if (target == null) {
return null;
}
return new EntityTag(target.getBukkitEntity()).getDenizenObject();
});
// <--[tag]
// @attribute <MythicMobsMobTag.has_threat_table>
// @returns ElementTag(Boolean)
// @plugin Depenizen, MythicMobs
// @description
// Returns whether the MythicMob has a threat table.
// -->
tagProcessor.registerTag(ElementTag.class, "has_threat_table", (attribute, object) -> {
return new ElementTag(object.getMob().hasThreatTable());
});
// <--[tag]
// @attribute <MythicMobsMobTag.threat_table>
// @returns MapTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the MythicMob's threat table, can contain multiple types of entities.
// Map is in the formatting of "UUID/Threat|UUID/Threat"
// -->
tagProcessor.registerTag(MapTag.class, "threat_table", (attribute, object) -> {
if (!object.getMob().hasThreatTable()) {
return null;
}
Map<AbstractEntity, Double> table = object.getMob().getThreatTable().asMap();
MapTag map = new MapTag();
for (AbstractEntity entity : table.keySet()) {
map.putObject(entity.getUniqueId().toString(), new ElementTag(table.get(entity)));
}
return map;
});
// <--[tag]
// @attribute <MythicMobsMobTag.threat_table_players>
// @returns MapTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the MythicMob's threat table, only containing players.
// Map is in the formatting of "UUID/Threat|UUID/Threat"
// -->
tagProcessor.registerTag(MapTag.class, "threat_table_players", (attribute, object) -> {
if (!object.getMob().hasThreatTable()) {
return null;
}
Map<AbstractEntity, Double> table = object.getMob().getThreatTable().asMap();
MapTag map = new MapTag();
for (AbstractEntity entity : table.keySet()) {
if (entity.isPlayer()) {
map.putObject(entity.getUniqueId().toString(), new ElementTag(table.get(entity)));
}
}
return map;
});
// <--[tag]
// @attribute <MythicMobsMobTag.is_damaging>
// @returns ElementTag(Boolean)
// @plugin Depenizen, MythicMobs
// @description
// Returns whether the MythicMob is using its damaging skill.
// -->
tagProcessor.registerTag(ElementTag.class, "is_damaging", (attribute, object) -> {
return new ElementTag(object.getMob().isUsingDamageSkill());
});
// <--[tag]
// @attribute <MythicMobsMobTag.stance>
// @returns ElementTag
// @plugin Depenizen, MythicMobs
// @mechanism MythicMobsMobTag.stance
// @description
// Returns the current stance of the MythicMob.
// -->
tagProcessor.registerTag(ElementTag.class, "stance", (attribute, object) -> {
return new ElementTag(object.getMob().getStance());
});
// <--[tag]
// @attribute <MythicMobsMobTag.entity>
// @returns EntityTag
// @plugin Depenizen, MythicMobs
// @description
// Returns the EntityTag for the MythicMob.
// -->
tagProcessor.registerTag(EntityFormObject.class, "entity", (attribute, object) -> {
return new EntityTag(object.getMob().getEntity().getBukkitEntity()).getDenizenObject();
});
// <--[tag]
// @attribute <MythicMobsMobTag.global_cooldown>
// @returns DurationTag
// @mechanism MythicMobsMobTag.global_cooldown
// @plugin Depenizen, MythicMobs
// @description
// Returns the MythicMob's global cooldown.
// -->
tagProcessor.registerTag(DurationTag.class, "global_cooldown", (attribute, object) -> {
return new DurationTag(object.getMob().getGlobalCooldown());
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object MythicMobsMobTag
// @name global_cooldown
// @input ElementTag(Number)
// @plugin Depenizen, MythicMobs
// @description
// Sets global cooldown of the MythicMob.
// @tags
// <MythicMobsMobTag.global_cooldown>
// -->
if (mechanism.matches("global_cooldown") && mechanism.requireInteger()) {
mob.setGlobalCooldown(mechanism.getValue().asInt());
}
// <--[mechanism]
// @object MythicMobsMobTag
// @name stance
// @input ElementTag
// @plugin Depenizen, MythicMobs
// @description
// Set the stance of the MythicMob.
// @tags
// <MythicMobsMobTag.stance>
// -->
if (mechanism.matches("stance")) {
mob.setStance(mechanism.getValue().asString());
}
// <--[mechanism]
// @object MythicMobsMobTag
// @name reset_target
// @input None
// @plugin Depenizen, MythicMobs
// @description
// Reset the MythicMob's target.
// @tags
// <MythicMobsMobTag.target>
// -->
else if (mechanism.matches("reset_target")) {
mob.resetTarget();
}
// <--[mechanism]
// @object MythicMobsMobTag
// @name level
// @input ElementTag(Number)
// @plugin Depenizen, MythicMobs
// @description
// Set the MythicMob's level.
// @tags
// <MythicMobsMobTag.level>
// -->
else if (mechanism.matches("level") && mechanism.requireInteger()) {
mob.setLevel(mechanism.getValue().asInt());
}
// <--[mechanism]
// @object MythicMobsMobTag
// @name target
// @input EntityTag
// @plugin Depenizen, MythicMobs
// @description
// Sets MythicMob's target.
// @tags
// <MythicMobsMobTag.target>
// -->
else if (mechanism.matches("target") && mechanism.requireObject(EntityTag.class)) {
EntityTag mTarget = mechanism.valueAsType(EntityTag.class);
if (mTarget == null || !mTarget.isValid() || mTarget.getLivingEntity() == null) {
return;
}
BukkitEntity target = new BukkitEntity(mTarget.getBukkitEntity());
mob.setTarget(target);
}
CoreUtilities.autoPropertyMechanism(this, mechanism);
if (!mechanism.fulfilled()) {
mechanism.reportInvalid();
}
}
@Override
public void applyProperty(Mechanism mechanism) {
Debug.echoError("Cannot apply properties to a MythicMob!");
}
}