/
EntityAreaEffectCloud.java
639 lines (576 loc) · 24.3 KB
/
EntityAreaEffectCloud.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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.entity.AreaEffectCloudHelper;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.projectiles.ProjectileSource;
import java.util.List;
public class EntityAreaEffectCloud implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag &&
((EntityTag) entity).getBukkitEntityType() == EntityType.AREA_EFFECT_CLOUD;
}
public static EntityAreaEffectCloud getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityAreaEffectCloud((EntityTag) entity);
}
}
public static final String[] handledTags = new String[] {
"base_potion", "particle", "duration", "radius", "reapplication_delay", "wait_time",
"has_custom_effect", "source", "custom_effects"
};
public static final String[] handledMechs = new String[] {
"clear_custom_effects", "remove_custom_effect", "custom_effects", "particle_color",
"base_potion", "duration", "duration_on_use", "particle", "radius", "radius_on_use",
"radius_per_tick", "reapplication_delay", "source", "wait_time"
};
private EntityAreaEffectCloud(EntityTag ent) {
entity = ent;
}
EntityTag entity;
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "area_effect_cloud";
}
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <EntityTag.base_potion>
// @returns ElementTag
// @mechanism EntityTag.base_potion
// @group properties
// @description
// Returns the Area Effect Cloud's base potion data.
// In the format Type,Upgraded,Extended
// -->
if (attribute.startsWith("base_potion")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <EntityTag.base_potion.type>
// @returns ElementTag
// @group properties
// @description
// Returns the Area Effect Cloud's base potion type.
// -->
if (attribute.startsWith("type")) {
return new ElementTag(getHelper().getBPName())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.base_potion.is_upgraded>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the Area Effect Cloud's base potion is upgraded.
// -->
if (attribute.startsWith("is_upgraded")) {
return new ElementTag(getHelper().getBPUpgraded())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.base_potion.is_extended>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the Area Effect Cloud's base potion is extended.
// -->
if (attribute.startsWith("is_extended")) {
return new ElementTag(getHelper().getBPExtended())
.getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended())
.getObjectAttribute(attribute);
}
// <--[tag]
// @attribute <EntityTag.particle>
// @returns ElementTag
// @mechanism EntityTag.particle
// @group properties
// @description
// Returns the Area Effect Cloud's particle.
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <EntityTag.particle.color>
// @returns ColorTag
// @group properties
// @description
// Returns the Area Effect Cloud's particle color.
// -->
if (attribute.startsWith("color")) {
return new ColorTag(getHelper().getColor())
.getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getParticle())
.getObjectAttribute(attribute);
}
// <--[tag]
// @attribute <EntityTag.duration>
// @returns DurationTag
// @mechanism EntityTag.duration
// @group properties
// @description
// Returns the Area Effect Cloud's duration.
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <EntityTag.duration.on_use>
// @returns DurationTag
// @group properties
// @description
// Returns the duration the Area Effect Cloud
// will increase by when it applies an effect to an entity.
// -->
if (attribute.startsWith("on_use")) {
return new DurationTag(getHelper().getDurationOnUse())
.getObjectAttribute(attribute.fulfill(1));
}
return new DurationTag(getHelper().getDuration())
.getObjectAttribute(attribute);
}
// <--[tag]
// @attribute <EntityTag.radius>
// @returns ElementTag(Decimal)
// @mechanism EntityTag.radius
// @group properties
// @description
// Returns the Area Effect Cloud's radius.
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <EntityTag.radius.on_use>
// @returns ElementTag(Decimal)
// @group properties
// @description
// Returns the amount the Area Effect Cloud's radius
// will increase by when it applies an effect to an entity.
// -->
if (attribute.startsWith("on_use")) {
return new ElementTag(getHelper().getRadiusOnUse())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.radius.per_tick>
// @returns ElementTag(Decimal)
// @group properties
// @description
// Returns the amount the Area Effect Cloud's radius
// will increase by every tick.
// -->
if (attribute.startsWith("per_tick")) {
return new ElementTag(getHelper().getRadiusPerTick())
.getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getRadius())
.getObjectAttribute(attribute);
}
// <--[tag]
// @attribute <EntityTag.reapplication_delay>
// @returns DurationTag
// @mechanism EntityTag.reapplication_delay
// @group properties
// @description
// Returns the duration an entity will be immune
// from the Area Effect Cloud's subsequent exposure.
// -->
if (attribute.startsWith("reapplication_delay")) {
return new DurationTag(getHelper().getReappDelay())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.wait_time>
// @returns DurationTag
// @mechanism EntityTag.wait_time
// @group properties
// @description
// Returns the duration an entity must be exposed to
// the Area Effect Cloud before its effect is applied.
// -->
if (attribute.startsWith("wait_time")) {
return new DurationTag(getHelper().getWaitTime())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.has_custom_effect[<effect>]>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.custom_effects
// @group properties
// @description
// Returns whether the Area Effect Cloud has a specified effect.
// If no effect is specified, returns whether it has any custom effect.
// -->
if (attribute.startsWith("has_custom_effect")) {
if (attribute.hasContext(1)) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getContext(1));
for (PotionEffect effect : getHelper().getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().hasCustomEffects())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.source>
// @returns EntityTag
// @mechanism EntityTag.source
// @group properties
// @description
// Returns the source of the Area Effect Cloud.
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter instanceof LivingEntity) {
return new EntityTag((LivingEntity) shooter)
.getObjectAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <EntityTag.custom_effects>
// @returns ListTag
// @mechanism EntityTag.custom_effects
// @group properties
// @description
// Returns a ListTag of the Area Effect Cloud's custom effects
// In the form Type,Amplifier,Duration,Ambient,Particles|...
// -->
if (attribute.startsWith("custom_effects")) {
List<PotionEffect> effects = getHelper().getCustomEffects();
if (!attribute.hasContext(1)) {
ListTag list = new ListTag();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," +
effect.getAmplifier() + "," +
new DurationTag((long) effect.getDuration()).identify() + "," +
effect.isAmbient() + "," +
effect.hasParticles());
}
return list.getObjectAttribute(attribute.fulfill(1));
}
int val = attribute.getIntContext(1) - 1;
if (val < 0 || val >= effects.size()) {
return null;
}
attribute = attribute.fulfill(1);
PotionEffect effect = effects.get(val);
// <--[tag]
// @attribute <EntityTag.custom_effects[<#>].type>
// @returns ElementTag
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect type.
// -->
if (attribute.startsWith("type")) {
return new ElementTag(effect.getType().getName())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.custom_effects[<#>].amplifier>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect amplifier.
// -->
if (attribute.startsWith("amplifier")) {
return new ElementTag(effect.getAmplifier())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.custom_effects[<#>].duration>
// @returns DurationTag
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect duration.
// -->
if (attribute.startsWith("duration")) {
return new DurationTag((long) effect.getDuration())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.custom_effects[<#>].has_particles>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the specified Area Effect Cloud potion effect has particles.
// -->
if (attribute.startsWith("has_particles")) {
return new ElementTag(effect.hasParticles())
.getObjectAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <EntityTag.custom_effects[<#>].is_ambient>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the specified Area Effect Cloud potion effect is ambient.
// -->
if (attribute.startsWith("is_ambient")) {
return new ElementTag(effect.isAmbient())
.getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(effect.getType().getName() + "," +
effect.getAmplifier() + "," +
new DurationTag((long) effect.getDuration()).identify() + "," +
effect.isAmbient() + "," +
effect.hasParticles()).getObjectAttribute(attribute);
}
return null;
}
public AreaEffectCloudHelper getHelper() {
return new AreaEffectCloudHelper(entity.getBukkitEntity());
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name clear_custom_effects
// @input None
// @description
// Clears all custom effects from the Area Effect Cloud
// @tags
// <EntityTag.custom_effects>
// -->
if (mechanism.matches("clear_custom_effects")) {
getHelper().clearEffects();
}
// <--[mechanism]
// @object EntityTag
// @name remove_custom_effect
// @input Element
// @description
// Removes the specified custom effect from the Area Effect Cloud
// @tags
// <EntityTag.custom_effects>
// -->
if (mechanism.matches("remove_custom_effect")) {
PotionEffectType type = PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase());
if (type != null) {
getHelper().removeEffect(type);
}
}
// <--[mechanism]
// @object EntityTag
// @name custom_effects
// @input ListTag
// @description
// Adds a list of custom potion effects to the Area Effect Cloud
// In the form Type,Amplifier,Duration(,Ambient,Particles)|...
// @tags
// <EntityTag.custom_effects>
// -->
if (mechanism.matches("custom_effects")) {
ListTag list = mechanism.valueAsType(ListTag.class);
getHelper().clearEffects();
for (String item : list) {
List<String> potionData = CoreUtilities.split(item, ',', 5);
if (potionData.size() >= 3) {
PotionEffectType type = PotionEffectType.getByName(potionData.get(0));
ElementTag amplifier = new ElementTag(potionData.get(1));
DurationTag duration = DurationTag.valueOf(potionData.get(2), mechanism.context);
ElementTag ambient = new ElementTag((potionData.size() > 3) ? potionData.get(3) : "false");
ElementTag particles = new ElementTag((potionData.size() > 4) ? potionData.get(4) : "true");
if (type == null || duration == null || !amplifier.isInt() || !ambient.isBoolean() || !particles.isBoolean()) {
Debug.echoError(item + " is not a valid potion effect!");
}
else {
getHelper().addEffect(
new PotionEffect(type, duration.getTicksAsInt(), amplifier.asInt(),
ambient.asBoolean(), particles.asBoolean()), true);
}
}
else {
Debug.echoError(item + " is not a valid potion effect!");
}
}
}
// <--[mechanism]
// @object EntityTag
// @name particle_color
// @input ColorTag
// @description
// Sets the Area Effect Cloud's particle color.
// @tags
// <EntityTag.particle.color>
// -->
if (mechanism.matches("particle_color") && mechanism.requireObject(ColorTag.class)) {
getHelper().setColor(mechanism.valueAsType(ColorTag.class).getColor());
}
// <--[mechanism]
// @object EntityTag
// @name base_potion
// @input Element
// @description
// Sets the Area Effect Cloud's base potion.
// In the form: Type,Upgraded,Extended
// NOTE: Potion cannot be both upgraded and extended
// @tags
// <EntityTag.base_potion>
// <EntityTag.base_potion.type>
// <EntityTag.base_potion.is_upgraded>
// <EntityTag.base_potion.is_extended>
// <server.potion_types>
// -->
if (mechanism.matches("base_potion")) {
List<String> data = CoreUtilities.split(mechanism.getValue().asString().toUpperCase(), ',');
if (data.size() != 3) {
Debug.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
}
else {
try {
PotionType type = PotionType.valueOf(data.get(0));
boolean extended = type.isExtendable() && CoreUtilities.equalsIgnoreCase(data.get(1), "true");
boolean upgraded = type.isUpgradeable() && CoreUtilities.equalsIgnoreCase(data.get(2), "true");
if (extended && upgraded) {
Debug.echoError("Potion cannot be both upgraded and extended");
}
else {
getHelper().setBP(type, extended, upgraded);
}
}
catch (Exception e) {
Debug.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
}
}
}
// <--[mechanism]
// @object EntityTag
// @name duration
// @input DurationTag
// @description
// Sets the Area Effect Cloud's duration.
// @tags
// <EntityTag.duration>
// -->
if (mechanism.matches("duration") && mechanism.requireObject(DurationTag.class)) {
getHelper().setDuration(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// <--[mechanism]
// @object EntityTag
// @name duration_on_use
// @input DurationTag
// @description
// Sets the duration the Area Effect Cloud
// will increase by when it applies an effect to an entity.
// @tags
// <EntityTag.duration.on_use>
// -->
if (mechanism.matches("duration_on_use") && mechanism.requireObject(DurationTag.class)) {
getHelper().setDurationOnUse(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// <--[mechanism]
// @object EntityTag
// @name particle
// @input Element
// @description
// Sets the particle of the Area Effect Cloud
// @tags
// <EntityTag.particle>
// -->
if (mechanism.matches("particle") && mechanism.hasValue()) {
getHelper().setParticle(mechanism.getValue().asString().toUpperCase());
}
// <--[mechanism]
// @object EntityTag
// @name radius
// @input ElementTag(Decimal)
// @description
// Sets the radius of the Area Effect Cloud
// @tags
// <EntityTag.radius>
// -->
if (mechanism.matches("radius") && mechanism.requireFloat()) {
getHelper().setRadius(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object EntityTag
// @name radius_on_use
// @input ElementTag(Decimal)
// @description
// Sets the radius the Area Effect Cloud
// will increase by when it applies an effect to an entity.
// @tags
// <EntityTag.radius.on_use>
// -->
if (mechanism.matches("radius_on_use") && mechanism.requireFloat()) {
getHelper().setRadiusOnUse(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object EntityTag
// @name radius_per_tick
// @input ElementTag(Decimal)
// @description
// Sets the radius the Area Effect Cloud
// will increase by every tick.
// @tags
// <EntityTag.radius.per_tick>
// -->
if (mechanism.matches("radius_per_tick") && mechanism.requireFloat()) {
getHelper().setRadiusPerTick(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object EntityTag
// @name reapplication_delay
// @input DurationTag
// @description
// Sets the duration an entity will be immune
// from the Area Effect Cloud's subsequent exposure.
// @tags
// <EntityTag.reapplication_delay>
// -->
if (mechanism.matches("reapplication_delay") && mechanism.requireObject(DurationTag.class)) {
getHelper().setReappDelay(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// <--[mechanism]
// @object EntityTag
// @name source
// @input EntityTag
// @description
// Sets the source of the Area Effect Cloud
// @tags
// <EntityTag.source>
// -->
if (mechanism.matches("source") && mechanism.requireObject(EntityTag.class)) {
getHelper().setSource((ProjectileSource) mechanism.valueAsType(EntityTag.class).getBukkitEntity());
}
// <--[mechanism]
// @object EntityTag
// @name wait_time
// @input DurationTag
// @description
// Sets the duration an entity must be exposed to
// the Area Effect Cloud before its effect is applied.
// @tags
// <EntityTag.wait_time>
// -->
if (mechanism.matches("wait_time") && mechanism.requireObject(DurationTag.class)) {
getHelper().setWaitTime(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}