1
1
package com .denizenscript .denizen .objects .properties .entity ;
2
2
3
+ import com .denizenscript .denizen .nms .NMSHandler ;
4
+ import com .denizenscript .denizen .nms .NMSVersion ;
5
+ import com .denizenscript .denizen .objects .EntityTag ;
3
6
import com .denizenscript .denizen .objects .properties .bukkit .BukkitColorExtensions ;
7
+ import com .denizenscript .denizen .utilities .BukkitImplDeprecations ;
8
+ import com .denizenscript .denizen .utilities .Utilities ;
4
9
import com .denizenscript .denizen .utilities .entity .AreaEffectCloudHelper ;
5
- import com .denizenscript .denizencore .objects .* ;
6
- import com .denizenscript .denizen .objects .EntityTag ;
10
+ import com .denizenscript .denizencore .objects .Mechanism ;
11
+ import com .denizenscript .denizencore .objects .ObjectTag ;
7
12
import com .denizenscript .denizencore .objects .core .ColorTag ;
8
13
import com .denizenscript .denizencore .objects .core .DurationTag ;
9
14
import com .denizenscript .denizencore .objects .core .ElementTag ;
10
15
import com .denizenscript .denizencore .objects .core .ListTag ;
11
16
import com .denizenscript .denizencore .objects .properties .Property ;
12
17
import com .denizenscript .denizencore .tags .Attribute ;
13
18
import com .denizenscript .denizencore .utilities .CoreUtilities ;
19
+ import org .bukkit .Particle ;
14
20
import org .bukkit .entity .EntityType ;
15
21
import org .bukkit .entity .LivingEntity ;
16
22
import org .bukkit .potion .PotionEffect ;
20
26
21
27
import java .util .List ;
22
28
23
- // TODO: 1.20.6: PotionData API
29
+ // TODO: most of the tags and mechs here need to become properties/be merged into existing properties
24
30
public class EntityAreaEffectCloud implements Property {
25
31
26
32
public static boolean describes (ObjectTag entity ) {
@@ -75,20 +81,22 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
75
81
// @attribute <EntityTag.base_potion>
76
82
// @returns ElementTag
77
83
// @mechanism EntityTag.base_potion
78
- // @group properties
84
+ // @deprecated use 'EntityTag.potion_type' on MC 1.20+.
79
85
// @description
80
- // Returns the Area Effect Cloud's base potion data.
81
- // In the format Type,Upgraded,Extended
86
+ // Deprecated in favor of <@link property EntityTag.potion_type> on MC 1.20+.
82
87
// -->
83
88
if (attribute .startsWith ("base_potion" )) {
84
89
attribute = attribute .fulfill (1 );
90
+ if (NMSHandler .getVersion ().isAtLeast (NMSVersion .v1_20 )) {
91
+ BukkitImplDeprecations .areaEffectCloudControls .warn (attribute .context );
92
+ }
85
93
86
94
// <--[tag]
87
95
// @attribute <EntityTag.base_potion.type>
88
96
// @returns ElementTag
89
- // @group properties
97
+ // @deprecated use 'EntityTag.potion_type' on MC 1.20+.
90
98
// @description
91
- // Returns the Area Effect Cloud's base potion type .
99
+ // Deprecated in favor of <@link property EntityTag.potion_type> on MC 1.20+ .
92
100
// -->
93
101
if (attribute .startsWith ("type" )) {
94
102
return new ElementTag (getHelper ().getBPName ())
@@ -98,9 +106,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
98
106
// <--[tag]
99
107
// @attribute <EntityTag.base_potion.is_upgraded>
100
108
// @returns ElementTag(Boolean)
101
- // @group properties
109
+ // @deprecated use 'EntityTag.potion_type' on MC 1.20+.
102
110
// @description
103
- // Returns whether the Area Effect Cloud's base potion is upgraded .
111
+ // Deprecated in favor of <@link property EntityTag.potion_type> on MC 1.20+ .
104
112
// -->
105
113
if (attribute .startsWith ("is_upgraded" )) {
106
114
return new ElementTag (getHelper ().getBPUpgraded ())
@@ -110,9 +118,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
110
118
// <--[tag]
111
119
// @attribute <EntityTag.base_potion.is_extended>
112
120
// @returns ElementTag(Boolean)
113
- // @group properties
121
+ // @deprecated use 'EntityTag.potion_type' on MC 1.20+.
114
122
// @description
115
- // Returns whether the Area Effect Cloud's base potion is extended .
123
+ // Deprecated in favor of <@link property EntityTag.potion_type> on MC 1.20+ .
116
124
// -->
117
125
if (attribute .startsWith ("is_extended" )) {
118
126
return new ElementTag (getHelper ().getBPExtended ())
@@ -136,11 +144,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
136
144
// <--[tag]
137
145
// @attribute <EntityTag.particle.color>
138
146
// @returns ColorTag
139
- // @group properties
147
+ // @deprecated use 'EntityTag.color'.
140
148
// @description
141
- // Returns the Area Effect Cloud's particle color.
149
+ // Deprecated in favor of <@link property EntityTag. color> .
142
150
// -->
143
151
if (attribute .startsWith ("color" )) {
152
+ BukkitImplDeprecations .areaEffectCloudControls .warn (attribute .context );
144
153
return BukkitColorExtensions .fromColor (getHelper ().getColor ())
145
154
.getObjectAttribute (attribute .fulfill (1 ));
146
155
}
@@ -246,12 +255,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
246
255
// @attribute <EntityTag.has_custom_effect[(<effect>)]>
247
256
// @returns ElementTag(Boolean)
248
257
// @mechanism EntityTag.custom_effects
249
- // @group properties
258
+ // @deprecated use 'EntityTag.has_effect'.
250
259
// @description
251
- // Returns whether the Area Effect Cloud has a specified effect.
252
- // If no effect is specified, returns whether it has any custom effect.
260
+ // Deprecated in favor of <@link tag EntityTag.has_effect>.
253
261
// -->
254
262
if (attribute .startsWith ("has_custom_effect" )) {
263
+ BukkitImplDeprecations .areaEffectCloudControls .warn (attribute .context );
255
264
if (attribute .hasParam ()) {
256
265
PotionEffectType effectType = PotionEffectType .getByName (attribute .getParam ());
257
266
for (PotionEffect effect : getHelper ().getCustomEffects ()) {
@@ -285,12 +294,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
285
294
// @attribute <EntityTag.custom_effects>
286
295
// @returns ListTag
287
296
// @mechanism EntityTag.custom_effects
288
- // @group properties
297
+ // @deprecated use 'EntityTag.effects_data'.
289
298
// @description
290
- // Returns a ListTag of the Area Effect Cloud's custom effects
291
- // In the form Type,Amplifier,Duration,Ambient,Particles|...
299
+ // Deprecated in favor of <@link tag EntityTag.effects_data>.
292
300
// -->
293
301
if (attribute .startsWith ("custom_effects" )) {
302
+ BukkitImplDeprecations .areaEffectCloudControls .warn (attribute .context );
294
303
List <PotionEffect > effects = getHelper ().getCustomEffects ();
295
304
if (!attribute .hasParam ()) {
296
305
ListTag list = new ListTag ();
@@ -313,9 +322,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
313
322
// <--[tag]
314
323
// @attribute <EntityTag.custom_effects[<#>].type>
315
324
// @returns ElementTag
316
- // @group properties
325
+ // @deprecated use 'EntityTag.effects_data'.
317
326
// @description
318
- // Returns the specified Area Effect Cloud potion effect type .
327
+ // Deprecated in favor of <@link tag EntityTag.effects_data> .
319
328
// -->
320
329
if (attribute .startsWith ("type" )) {
321
330
return new ElementTag (effect .getType ().getName ())
@@ -325,9 +334,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
325
334
// <--[tag]
326
335
// @attribute <EntityTag.custom_effects[<#>].amplifier>
327
336
// @returns ElementTag(Number)
328
- // @group properties
337
+ // @deprecated use 'EntityTag.effects_data'.
329
338
// @description
330
- // Returns the specified Area Effect Cloud potion effect amplifier .
339
+ // Deprecated in favor of <@link tag EntityTag.effects_data> .
331
340
// -->
332
341
if (attribute .startsWith ("amplifier" )) {
333
342
return new ElementTag (effect .getAmplifier ())
@@ -337,9 +346,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
337
346
// <--[tag]
338
347
// @attribute <EntityTag.custom_effects[<#>].duration>
339
348
// @returns DurationTag
340
- // @group properties
349
+ // @deprecated use 'EntityTag.effects_data'.
341
350
// @description
342
- // Returns the specified Area Effect Cloud potion effect duration .
351
+ // Deprecated in favor of <@link tag EntityTag.effects_data> .
343
352
// -->
344
353
if (attribute .startsWith ("duration" )) {
345
354
return new DurationTag ((long ) effect .getDuration ())
@@ -349,9 +358,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
349
358
// <--[tag]
350
359
// @attribute <EntityTag.custom_effects[<#>].has_particles>
351
360
// @returns ElementTag(Boolean)
352
- // @group properties
361
+ // @deprecated use 'EntityTag.effects_data'.
353
362
// @description
354
- // Returns whether the specified Area Effect Cloud potion effect has particles .
363
+ // Deprecated in favor of <@link tag EntityTag.effects_data> .
355
364
// -->
356
365
if (attribute .startsWith ("has_particles" )) {
357
366
return new ElementTag (effect .hasParticles ())
@@ -361,9 +370,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
361
370
// <--[tag]
362
371
// @attribute <EntityTag.custom_effects[<#>].is_ambient>
363
372
// @returns ElementTag(Boolean)
364
- // @group properties
373
+ // @deprecated use 'EntityTag.effects_data'.
365
374
// @description
366
- // Returns whether the specified Area Effect Cloud potion effect is ambient .
375
+ // Deprecated in favor of <@link tag EntityTag.effects_data> .
367
376
// -->
368
377
if (attribute .startsWith ("is_ambient" )) {
369
378
return new ElementTag (effect .isAmbient ())
@@ -391,25 +400,29 @@ public void adjust(Mechanism mechanism) {
391
400
// @object EntityTag
392
401
// @name clear_custom_effects
393
402
// @input None
403
+ // @deprecated use 'EntityTag.potion_effects'.
394
404
// @description
395
- // Clears all custom effects from the Area Effect Cloud
405
+ // Deprecated in favor of <@link mechanism EntityTag.potion_effects>.
396
406
// @tags
397
407
// <EntityTag.custom_effects>
398
408
// -->
399
409
if (mechanism .matches ("clear_custom_effects" )) {
410
+ BukkitImplDeprecations .areaEffectCloudControls .warn (mechanism .context );
400
411
getHelper ().clearEffects ();
401
412
}
402
413
403
414
// <--[mechanism]
404
415
// @object EntityTag
405
416
// @name remove_custom_effect
406
417
// @input ElementTag
418
+ // @deprecated use 'EntityTag.potion_effects'.
407
419
// @description
408
- // Removes the specified custom effect from the Area Effect Cloud
420
+ // Deprecated in favor of <@link mechanism EntityTag.potion_effects>.
409
421
// @tags
410
422
// <EntityTag.custom_effects>
411
423
// -->
412
424
if (mechanism .matches ("remove_custom_effect" )) {
425
+ BukkitImplDeprecations .areaEffectCloudControls .warn (mechanism .context );
413
426
PotionEffectType type = PotionEffectType .getByName (mechanism .getValue ().asString ().toUpperCase ());
414
427
if (type != null ) {
415
428
getHelper ().removeEffect (type );
@@ -420,13 +433,14 @@ public void adjust(Mechanism mechanism) {
420
433
// @object EntityTag
421
434
// @name custom_effects
422
435
// @input ListTag
436
+ // @deprecated use 'EntityTag.potion_effects'.
423
437
// @description
424
- // Adds a list of custom potion effects to the Area Effect Cloud
425
- // In the form Type,Amplifier,Duration(,Ambient,Particles)|...
438
+ // Deprecated in favor of <@link mechanism EntityTag.potion_effects>.
426
439
// @tags
427
440
// <EntityTag.custom_effects>
428
441
// -->
429
442
if (mechanism .matches ("custom_effects" )) {
443
+ BukkitImplDeprecations .areaEffectCloudControls .warn (mechanism .context );
430
444
ListTag list = mechanism .valueAsType (ListTag .class );
431
445
getHelper ().clearEffects ();
432
446
@@ -458,50 +472,48 @@ public void adjust(Mechanism mechanism) {
458
472
// @object EntityTag
459
473
// @name particle_color
460
474
// @input ColorTag
475
+ // @deprecated use 'EntityTag.color'.
461
476
// @description
462
- // Sets the Area Effect Cloud's particle color.
477
+ // Deprecated in favor of <@link property EntityTag. color> .
463
478
// @tags
464
479
// <EntityTag.particle.color>
465
480
// -->
466
481
if (mechanism .matches ("particle_color" ) && mechanism .requireObject (ColorTag .class )) {
482
+ BukkitImplDeprecations .areaEffectCloudControls .warn (mechanism .context );
467
483
getHelper ().setColor (BukkitColorExtensions .getColor (mechanism .valueAsType (ColorTag .class )));
468
484
}
469
485
470
486
// <--[mechanism]
471
487
// @object EntityTag
472
488
// @name base_potion
473
489
// @input ElementTag
490
+ // @deprecated use 'EntityTag.potion_type' on MC 1.20+.
474
491
// @description
475
- // Sets the Area Effect Cloud's base potion.
476
- // In the form: Type,Upgraded,Extended
477
- // NOTE: Potion cannot be both upgraded and extended
492
+ // Deprecated in favor of <@link property EntityTag.potion_type> on MC 1.20+.
478
493
// @tags
479
494
// <EntityTag.base_potion>
480
- // <EntityTag.base_potion.type>
481
- // <EntityTag.base_potion.is_upgraded>
482
- // <EntityTag.base_potion.is_extended>
483
- // <server.potion_types>
484
495
// -->
485
496
if (mechanism .matches ("base_potion" )) {
497
+ if (NMSHandler .getVersion ().isAtLeast (NMSVersion .v1_20 )) {
498
+ BukkitImplDeprecations .areaEffectCloudControls .warn (mechanism .context );
499
+ }
486
500
List <String > data = CoreUtilities .split (mechanism .getValue ().asString ().toUpperCase (), ',' );
487
501
if (data .size () != 3 ) {
488
- mechanism .echoError (mechanism .getValue ().asString () + " is not a valid base potion!" );
502
+ mechanism .echoError (mechanism .getValue () + " is not a valid base potion!" );
503
+ return ;
504
+ }
505
+ PotionType type = Utilities .elementToEnumlike (new ElementTag (data .get (0 ), true ), PotionType .class );
506
+ if (type == null ) {
507
+ mechanism .echoError (mechanism .getValue () + " is not a valid base potion!" );
508
+ return ;
509
+ }
510
+ boolean upgraded = type .isUpgradeable () && CoreUtilities .equalsIgnoreCase (data .get (1 ), "true" );
511
+ boolean extended = type .isExtendable () && CoreUtilities .equalsIgnoreCase (data .get (2 ), "true" );
512
+ if (extended && upgraded ) {
513
+ mechanism .echoError ("Potion cannot be both upgraded and extended" );
489
514
}
490
515
else {
491
- try {
492
- PotionType type = PotionType .valueOf (data .get (0 ));
493
- boolean upgraded = type .isUpgradeable () && CoreUtilities .equalsIgnoreCase (data .get (1 ), "true" );
494
- boolean extended = type .isExtendable () && CoreUtilities .equalsIgnoreCase (data .get (2 ), "true" );
495
- if (extended && upgraded ) {
496
- mechanism .echoError ("Potion cannot be both upgraded and extended" );
497
- }
498
- else {
499
- getHelper ().setBP (type , extended , upgraded );
500
- }
501
- }
502
- catch (Exception e ) {
503
- mechanism .echoError (mechanism .getValue ().asString () + " is not a valid base potion!" );
504
- }
516
+ getHelper ().setBP (type , extended , upgraded );
505
517
}
506
518
}
507
519
@@ -541,7 +553,8 @@ public void adjust(Mechanism mechanism) {
541
553
// @tags
542
554
// <EntityTag.particle>
543
555
// -->
544
- if (mechanism .matches ("particle" ) && mechanism .hasValue ()) {
556
+ // TODO: some particles require additional data - need a new property that supports playeffect's special_data input
557
+ if (mechanism .matches ("particle" ) && Utilities .requireEnumlike (mechanism , Particle .class )) {
545
558
getHelper ().setParticle (mechanism .getValue ().asString ().toUpperCase ());
546
559
}
547
560
0 commit comments