/
EntityAreaEffectCloud.java
629 lines (563 loc) · 22.9 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
package net.aufdemrand.denizen.objects.properties.entity;
import net.aufdemrand.denizen.objects.dColor;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.entity.AreaEffectCloudHelper;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.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(dObject entity) {
return entity instanceof dEntity &&
((dEntity) entity).getBukkitEntityType() == EntityType.AREA_EFFECT_CLOUD;
}
public static EntityAreaEffectCloud getFrom(dObject entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityAreaEffectCloud((dEntity) entity);
}
}
///////////////////
// Instance Fields and Methods
/////////////
private EntityAreaEffectCloud(dEntity ent) {
entity = ent;
}
dEntity entity;
/////////
// Property Methods
///////
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "area_effect_cloud";
}
///////////
// dObject Attributes
////////
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// <--[tag]
// @attribute <e@entity.base_potion>
// @returns Element
// @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 <e@entity.base_potion.type>
// @returns Element
// @group properties
// @description
// Returns the Area Effect Cloud's base potion type.
// -->
if (attribute.startsWith("type")) {
return new Element(getHelper().getBPName())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.base_potion.is_upgraded>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether the Area Effect Cloud's base potion is upgraded.
// -->
if (attribute.startsWith("is_upgraded")) {
return new Element(getHelper().getBPUpgraded())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.base_potion.is_extended>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether the Area Effect Cloud's base potion is extended.
// -->
if (attribute.startsWith("is_extended")) {
return new Element(getHelper().getBPExtended())
.getAttribute(attribute.fulfill(1));
}
return new Element(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended())
.getAttribute(attribute);
}
// <--[tag]
// @attribute <e@entity.particle>
// @returns Element
// @group properties
// @description
// Returns the Area Effect Cloud's particle.
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <e@entity.particle.color>
// @returns dColor
// @group properties
// @description
// Returns the Area Effect Cloud's particle color.
// -->
if (attribute.startsWith("color")) {
return new dColor(getHelper().getColor())
.getAttribute(attribute.fulfill(1));
}
return new Element(getHelper().getParticle())
.getAttribute(attribute);
}
// <--[tag]
// @attribute <e@entity.duration>
// @returns Duration
// @group properties
// @description
// Returns the Area Effect Cloud's duration.
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <e@entity.duration.on_use>
// @returns Duration
// @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 Duration(getHelper().getDurationOnUse())
.getAttribute(attribute.fulfill(1));
}
return new Duration(getHelper().getDuration())
.getAttribute(attribute);
}
// <--[tag]
// @attribute <e@entity.radius>
// @returns Element(Decimal)
// @group properties
// @description
// Returns the Area Effect Cloud's radius.
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <e@entity.radius.on_use>
// @returns Element(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 Element(getHelper().getRadiusOnUse())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.radius.per_tick>
// @returns Element(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 Element(getHelper().getRadiusPerTick())
.getAttribute(attribute.fulfill(1));
}
return new Element(getHelper().getRadius())
.getAttribute(attribute);
}
// <--[tag]
// @attribute <e@entity.reapplication_delay>
// @returns Duration
// @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 Duration(getHelper().getReappDelay())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.wait_time>
// @returns Duration
// @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 Duration(getHelper().getWaitTime())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.has_custom_effect[<effect>]>
// @returns Element(Boolean)
// @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 Element(true).getAttribute(attribute.fulfill(1));
}
}
return new Element(false).getAttribute(attribute.fulfill(1));
}
return new Element(getHelper().hasCustomEffects())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.source>
// @returns dEntity
// @group properties
// @description
// Returns the source of the Area Effect Cloud.
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter != null && shooter instanceof LivingEntity) {
return new dEntity((LivingEntity) shooter)
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <e@entity.custom_effects>
// @returns dList
// @group properties
// @description
// Returns a dList 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)) {
dList list = new dList();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," +
effect.getAmplifier() + "," +
new Duration((long) effect.getDuration()).identify() + "," +
effect.isAmbient() + "," +
effect.hasParticles());
}
return list.getAttribute(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 <e@entity.custom_effects[<#>].type>
// @returns Element
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect type.
// -->
if (attribute.startsWith("type")) {
return new Element(effect.getType().getName())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.custom_effects[<#>].amplifier>
// @returns Element(Number)
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect amplifier.
// -->
if (attribute.startsWith("amplifier")) {
return new Element(effect.getAmplifier())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.custom_effects[<#>].duration>
// @returns Duration
// @group properties
// @description
// Returns the specified Area Effect Cloud potion effect duration.
// -->
if (attribute.startsWith("duration")) {
return new Duration((long) effect.getDuration())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.custom_effects[<#>].has_particles>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether the specified Area Effect Cloud potion effect has particles.
// -->
if (attribute.startsWith("has_particles")) {
return new Element(effect.hasParticles())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <e@entity.custom_effects[<#>].is_ambient>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether the specified Area Effect Cloud potion effect is ambient.
// -->
if (attribute.startsWith("is_ambient")) {
return new Element(effect.isAmbient())
.getAttribute(attribute.fulfill(1));
}
return new Element(effect.getType().getName() + "," +
effect.getAmplifier() + "," +
new Duration((long) effect.getDuration()).identify() + "," +
effect.isAmbient() + "," +
effect.hasParticles()).getAttribute(attribute);
}
return null;
}
public AreaEffectCloudHelper getHelper() {
return new AreaEffectCloudHelper(entity.getBukkitEntity());
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object dEntity
// @name clear_custom_effects
// @input None
// @description
// Clears all custom effects from the Area Effect Cloud
// @tags
// <e@entity.custom_effects>
// -->
if (mechanism.matches("clear_custom_effects")) {
getHelper().clearEffects();
}
// <--[mechanism]
// @object dEntity
// @name remove_custom_effect
// @input Element
// @description
// Removes the specified custom effect from the Area Effect Cloud
// @tags
// <e@entity.custom_effects>
// -->
if (mechanism.matches("remove_custom_effect")) {
PotionEffectType type = PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase());
if (type != null) {
getHelper().removeEffect(type);
}
}
// <--[mechanism]
// @object dEntity
// @name custom_effects
// @input dList
// @description
// Adds a list of custom potion effects to the Area Effect Cloud
// In the form Type,Amplifier,Duration(,Ambient,Particles)|...
// @tags
// <e@entity.custom_effects>
// -->
if (mechanism.matches("custom_effects")) {
dList list = mechanism.getValue().asType(dList.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));
Element amplifier = new Element(potionData.get(1));
Duration duration = Duration.valueOf(potionData.get(2));
Element ambient = new Element((potionData.size() > 3) ? potionData.get(3) : "false");
Element particles = new Element((potionData.size() > 4) ? potionData.get(4) : "true");
if (type == null || duration == null || !amplifier.isInt() || !ambient.isBoolean() || !particles.isBoolean()) {
dB.echoError(item + " is not a valid potion effect!");
}
else {
getHelper().addEffect(
new PotionEffect(type, duration.getTicksAsInt(), amplifier.asInt(),
ambient.asBoolean(), particles.asBoolean()), true);
}
}
else {
dB.echoError(item + " is not a valid potion effect!");
}
}
}
// <--[mechanism]
// @object dEntity
// @name particle_color
// @input dColor
// @description
// Sets the Area Effect Cloud's particle color.
// @tags
// <e@entity.particle.color>
// -->
if (mechanism.matches("particle_color") && mechanism.requireObject(dColor.class)) {
getHelper().setColor(dColor.valueOf(mechanism.getValue().asString()).getColor());
}
// <--[mechanism]
// @object dEntity
// @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
// <e@entity.base_potion>
// <e@entity.base_potion.type>
// <e@entity.base_potion.is_upgraded>
// <e@entity.base_potion.is_extended>
// -->
if (mechanism.matches("base_potion")) {
List<String> data = CoreUtilities.split(mechanism.getValue().asString().toUpperCase(), ',');
if (data.size() != 3) {
dB.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
}
else {
try {
PotionType type = PotionType.valueOf(data.get(0));
boolean extended = type.isExtendable() && CoreUtilities.toLowerCase(data.get(1)).equals("true");
boolean upgraded = type.isUpgradeable() && CoreUtilities.toLowerCase(data.get(2)).equals("true");
if (extended && upgraded) {
dB.echoError("Potion cannot be both upgraded and extended");
}
else {
getHelper().setBP(type, extended, upgraded);
}
}
catch (Exception e) {
dB.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
}
}
}
// <--[mechanism]
// @object dEntity
// @name duration
// @input Duration
// @description
// Sets the Area Effect Cloud's duration.
// @tags
// <e@entity.duration>
// -->
if (mechanism.matches("duration") && mechanism.requireObject(Duration.class)) {
getHelper().setDuration(Duration.valueOf(mechanism.getValue().asString()).getTicksAsInt());
}
// <--[mechanism]
// @object dEntity
// @name duration_on_use
// @input Duration
// @description
// Sets the duration the Area Effect Cloud
// will increase by when it applies an effect to an entity.
// @tags
// <e@entity.duration.on_use>
// -->
if (mechanism.matches("duration_on_use") && mechanism.requireObject(Duration.class)) {
getHelper().setDurationOnUse(Duration.valueOf(mechanism.getValue().asString()).getTicksAsInt());
}
// <--[mechanism]
// @object dEntity
// @name particle
// @input Element
// @description
// Sets the particle of the Area Effect Cloud
// @tags
// <e@entity.particle>
// -->
if (mechanism.matches("particle") && mechanism.hasValue()) {
getHelper().setParticle(mechanism.getValue().asString().toUpperCase());
}
// <--[mechanism]
// @object dEntity
// @name radius
// @input Element(Decimal)
// @description
// Sets the radius of the Area Effect Cloud
// @tags
// <e@entity.radius>
// -->
if (mechanism.matches("radius") && mechanism.requireFloat()) {
getHelper().setRadius(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object dEntity
// @name radius_on_use
// @input Element(Decimal)
// @description
// Sets the radius the Area Effect Cloud
// will increase by when it applies an effect to an entity.
// @tags
// <e@entity.radius.on_use>
// -->
if (mechanism.matches("radius_on_use") && mechanism.requireFloat()) {
getHelper().setRadiusOnUse(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object dEntity
// @name radius_per_tick
// @input Element(Decimal)
// @description
// Sets the radius the Area Effect Cloud
// will increase by every tick.
// @tags
// <e@entity.radius.per_tick>
// -->
if (mechanism.matches("radius_per_tick") && mechanism.requireFloat()) {
getHelper().setRadiusPerTick(mechanism.getValue().asFloat());
}
// <--[mechanism]
// @object dEntity
// @name reapplication_delay
// @input Duration
// @description
// Sets the duration an entity will be immune
// from the Area Effect Cloud's subsequent exposure.
// @tags
// <e@entity.reapplication_delay>
// -->
if (mechanism.matches("reapplication_delay") && mechanism.requireObject(Duration.class)) {
getHelper().setReappDelay(Duration.valueOf(mechanism.getValue().asString()).getTicksAsInt());
}
// <--[mechanism]
// @object dEntity
// @name source
// @input dEntity
// @description
// Sets the source of the Area Effect Cloud
// @tags
// <e@entity.source>
// -->
if (mechanism.matches("source") && mechanism.requireObject(dEntity.class)) {
getHelper().setSource((ProjectileSource) dEntity.valueOf(mechanism.getValue().asString()).getBukkitEntity());
}
// <--[mechanism]
// @object dEntity
// @name wait_time
// @input Duration
// @description
// Sets the duration an entity must be exposed to
// the Area Effect Cloud before its effect is applied.
// @tags
// <e@entity.wait_time>
// -->
if (mechanism.matches("wait_time") && mechanism.requireObject(Duration.class)) {
getHelper().setWaitTime(Duration.valueOf(mechanism.getValue().asString()).getTicksAsInt());
}
}
}