Skip to content

Commit a8d563f

Browse files
authored
1.21.5 Area effect cloud fixes (#2722)
* Base potion type controls * Custom effect controls * Particle color controls * Backsupport particle names + TODO * Wrap up * Fix meta syntax * Fix meta syntax x2 * Final fixups
1 parent 01a7819 commit a8d563f

File tree

7 files changed

+123
-82
lines changed

7 files changed

+123
-82
lines changed

plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public static void registerMainProperties() {
3434
PropertyParser.registerProperty(EntityAI.class, EntityTag.class);
3535
PropertyParser.registerProperty(EntityAnger.class, EntityTag.class);
3636
PropertyParser.registerProperty(EntityAngry.class, EntityTag.class);
37-
if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_19)) {
38-
PropertyParser.registerProperty(EntityAreaEffectCloud.class, EntityTag.class);
39-
}
37+
PropertyParser.registerProperty(EntityAreaEffectCloud.class, EntityTag.class);
4038
PropertyParser.registerProperty(EntityArmorBonus.class, EntityTag.class);
4139
PropertyParser.registerProperty(EntityArrowDamage.class, EntityTag.class);
4240
PropertyParser.registerProperty(EntityArrowPierceLevel.class, EntityTag.class);

plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAreaEffectCloud.java

+71-58
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package com.denizenscript.denizen.objects.properties.entity;
22

3+
import com.denizenscript.denizen.nms.NMSHandler;
4+
import com.denizenscript.denizen.nms.NMSVersion;
5+
import com.denizenscript.denizen.objects.EntityTag;
36
import com.denizenscript.denizen.objects.properties.bukkit.BukkitColorExtensions;
7+
import com.denizenscript.denizen.utilities.BukkitImplDeprecations;
8+
import com.denizenscript.denizen.utilities.Utilities;
49
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;
712
import com.denizenscript.denizencore.objects.core.ColorTag;
813
import com.denizenscript.denizencore.objects.core.DurationTag;
914
import com.denizenscript.denizencore.objects.core.ElementTag;
1015
import com.denizenscript.denizencore.objects.core.ListTag;
1116
import com.denizenscript.denizencore.objects.properties.Property;
1217
import com.denizenscript.denizencore.tags.Attribute;
1318
import com.denizenscript.denizencore.utilities.CoreUtilities;
19+
import org.bukkit.Particle;
1420
import org.bukkit.entity.EntityType;
1521
import org.bukkit.entity.LivingEntity;
1622
import org.bukkit.potion.PotionEffect;
@@ -20,7 +26,7 @@
2026

2127
import java.util.List;
2228

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
2430
public class EntityAreaEffectCloud implements Property {
2531

2632
public static boolean describes(ObjectTag entity) {
@@ -75,20 +81,22 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
7581
// @attribute <EntityTag.base_potion>
7682
// @returns ElementTag
7783
// @mechanism EntityTag.base_potion
78-
// @group properties
84+
// @deprecated use 'EntityTag.potion_type' on MC 1.20+.
7985
// @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+.
8287
// -->
8388
if (attribute.startsWith("base_potion")) {
8489
attribute = attribute.fulfill(1);
90+
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) {
91+
BukkitImplDeprecations.areaEffectCloudControls.warn(attribute.context);
92+
}
8593

8694
// <--[tag]
8795
// @attribute <EntityTag.base_potion.type>
8896
// @returns ElementTag
89-
// @group properties
97+
// @deprecated use 'EntityTag.potion_type' on MC 1.20+.
9098
// @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+.
92100
// -->
93101
if (attribute.startsWith("type")) {
94102
return new ElementTag(getHelper().getBPName())
@@ -98,9 +106,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
98106
// <--[tag]
99107
// @attribute <EntityTag.base_potion.is_upgraded>
100108
// @returns ElementTag(Boolean)
101-
// @group properties
109+
// @deprecated use 'EntityTag.potion_type' on MC 1.20+.
102110
// @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+.
104112
// -->
105113
if (attribute.startsWith("is_upgraded")) {
106114
return new ElementTag(getHelper().getBPUpgraded())
@@ -110,9 +118,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
110118
// <--[tag]
111119
// @attribute <EntityTag.base_potion.is_extended>
112120
// @returns ElementTag(Boolean)
113-
// @group properties
121+
// @deprecated use 'EntityTag.potion_type' on MC 1.20+.
114122
// @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+.
116124
// -->
117125
if (attribute.startsWith("is_extended")) {
118126
return new ElementTag(getHelper().getBPExtended())
@@ -136,11 +144,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
136144
// <--[tag]
137145
// @attribute <EntityTag.particle.color>
138146
// @returns ColorTag
139-
// @group properties
147+
// @deprecated use 'EntityTag.color'.
140148
// @description
141-
// Returns the Area Effect Cloud's particle color.
149+
// Deprecated in favor of <@link property EntityTag.color>.
142150
// -->
143151
if (attribute.startsWith("color")) {
152+
BukkitImplDeprecations.areaEffectCloudControls.warn(attribute.context);
144153
return BukkitColorExtensions.fromColor(getHelper().getColor())
145154
.getObjectAttribute(attribute.fulfill(1));
146155
}
@@ -246,12 +255,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
246255
// @attribute <EntityTag.has_custom_effect[(<effect>)]>
247256
// @returns ElementTag(Boolean)
248257
// @mechanism EntityTag.custom_effects
249-
// @group properties
258+
// @deprecated use 'EntityTag.has_effect'.
250259
// @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>.
253261
// -->
254262
if (attribute.startsWith("has_custom_effect")) {
263+
BukkitImplDeprecations.areaEffectCloudControls.warn(attribute.context);
255264
if (attribute.hasParam()) {
256265
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
257266
for (PotionEffect effect : getHelper().getCustomEffects()) {
@@ -285,12 +294,12 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
285294
// @attribute <EntityTag.custom_effects>
286295
// @returns ListTag
287296
// @mechanism EntityTag.custom_effects
288-
// @group properties
297+
// @deprecated use 'EntityTag.effects_data'.
289298
// @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>.
292300
// -->
293301
if (attribute.startsWith("custom_effects")) {
302+
BukkitImplDeprecations.areaEffectCloudControls.warn(attribute.context);
294303
List<PotionEffect> effects = getHelper().getCustomEffects();
295304
if (!attribute.hasParam()) {
296305
ListTag list = new ListTag();
@@ -313,9 +322,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
313322
// <--[tag]
314323
// @attribute <EntityTag.custom_effects[<#>].type>
315324
// @returns ElementTag
316-
// @group properties
325+
// @deprecated use 'EntityTag.effects_data'.
317326
// @description
318-
// Returns the specified Area Effect Cloud potion effect type.
327+
// Deprecated in favor of <@link tag EntityTag.effects_data>.
319328
// -->
320329
if (attribute.startsWith("type")) {
321330
return new ElementTag(effect.getType().getName())
@@ -325,9 +334,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
325334
// <--[tag]
326335
// @attribute <EntityTag.custom_effects[<#>].amplifier>
327336
// @returns ElementTag(Number)
328-
// @group properties
337+
// @deprecated use 'EntityTag.effects_data'.
329338
// @description
330-
// Returns the specified Area Effect Cloud potion effect amplifier.
339+
// Deprecated in favor of <@link tag EntityTag.effects_data>.
331340
// -->
332341
if (attribute.startsWith("amplifier")) {
333342
return new ElementTag(effect.getAmplifier())
@@ -337,9 +346,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
337346
// <--[tag]
338347
// @attribute <EntityTag.custom_effects[<#>].duration>
339348
// @returns DurationTag
340-
// @group properties
349+
// @deprecated use 'EntityTag.effects_data'.
341350
// @description
342-
// Returns the specified Area Effect Cloud potion effect duration.
351+
// Deprecated in favor of <@link tag EntityTag.effects_data>.
343352
// -->
344353
if (attribute.startsWith("duration")) {
345354
return new DurationTag((long) effect.getDuration())
@@ -349,9 +358,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
349358
// <--[tag]
350359
// @attribute <EntityTag.custom_effects[<#>].has_particles>
351360
// @returns ElementTag(Boolean)
352-
// @group properties
361+
// @deprecated use 'EntityTag.effects_data'.
353362
// @description
354-
// Returns whether the specified Area Effect Cloud potion effect has particles.
363+
// Deprecated in favor of <@link tag EntityTag.effects_data>.
355364
// -->
356365
if (attribute.startsWith("has_particles")) {
357366
return new ElementTag(effect.hasParticles())
@@ -361,9 +370,9 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
361370
// <--[tag]
362371
// @attribute <EntityTag.custom_effects[<#>].is_ambient>
363372
// @returns ElementTag(Boolean)
364-
// @group properties
373+
// @deprecated use 'EntityTag.effects_data'.
365374
// @description
366-
// Returns whether the specified Area Effect Cloud potion effect is ambient.
375+
// Deprecated in favor of <@link tag EntityTag.effects_data>.
367376
// -->
368377
if (attribute.startsWith("is_ambient")) {
369378
return new ElementTag(effect.isAmbient())
@@ -391,25 +400,29 @@ public void adjust(Mechanism mechanism) {
391400
// @object EntityTag
392401
// @name clear_custom_effects
393402
// @input None
403+
// @deprecated use 'EntityTag.potion_effects'.
394404
// @description
395-
// Clears all custom effects from the Area Effect Cloud
405+
// Deprecated in favor of <@link mechanism EntityTag.potion_effects>.
396406
// @tags
397407
// <EntityTag.custom_effects>
398408
// -->
399409
if (mechanism.matches("clear_custom_effects")) {
410+
BukkitImplDeprecations.areaEffectCloudControls.warn(mechanism.context);
400411
getHelper().clearEffects();
401412
}
402413

403414
// <--[mechanism]
404415
// @object EntityTag
405416
// @name remove_custom_effect
406417
// @input ElementTag
418+
// @deprecated use 'EntityTag.potion_effects'.
407419
// @description
408-
// Removes the specified custom effect from the Area Effect Cloud
420+
// Deprecated in favor of <@link mechanism EntityTag.potion_effects>.
409421
// @tags
410422
// <EntityTag.custom_effects>
411423
// -->
412424
if (mechanism.matches("remove_custom_effect")) {
425+
BukkitImplDeprecations.areaEffectCloudControls.warn(mechanism.context);
413426
PotionEffectType type = PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase());
414427
if (type != null) {
415428
getHelper().removeEffect(type);
@@ -420,13 +433,14 @@ public void adjust(Mechanism mechanism) {
420433
// @object EntityTag
421434
// @name custom_effects
422435
// @input ListTag
436+
// @deprecated use 'EntityTag.potion_effects'.
423437
// @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>.
426439
// @tags
427440
// <EntityTag.custom_effects>
428441
// -->
429442
if (mechanism.matches("custom_effects")) {
443+
BukkitImplDeprecations.areaEffectCloudControls.warn(mechanism.context);
430444
ListTag list = mechanism.valueAsType(ListTag.class);
431445
getHelper().clearEffects();
432446

@@ -458,50 +472,48 @@ public void adjust(Mechanism mechanism) {
458472
// @object EntityTag
459473
// @name particle_color
460474
// @input ColorTag
475+
// @deprecated use 'EntityTag.color'.
461476
// @description
462-
// Sets the Area Effect Cloud's particle color.
477+
// Deprecated in favor of <@link property EntityTag.color>.
463478
// @tags
464479
// <EntityTag.particle.color>
465480
// -->
466481
if (mechanism.matches("particle_color") && mechanism.requireObject(ColorTag.class)) {
482+
BukkitImplDeprecations.areaEffectCloudControls.warn(mechanism.context);
467483
getHelper().setColor(BukkitColorExtensions.getColor(mechanism.valueAsType(ColorTag.class)));
468484
}
469485

470486
// <--[mechanism]
471487
// @object EntityTag
472488
// @name base_potion
473489
// @input ElementTag
490+
// @deprecated use 'EntityTag.potion_type' on MC 1.20+.
474491
// @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+.
478493
// @tags
479494
// <EntityTag.base_potion>
480-
// <EntityTag.base_potion.type>
481-
// <EntityTag.base_potion.is_upgraded>
482-
// <EntityTag.base_potion.is_extended>
483-
// <server.potion_types>
484495
// -->
485496
if (mechanism.matches("base_potion")) {
497+
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) {
498+
BukkitImplDeprecations.areaEffectCloudControls.warn(mechanism.context);
499+
}
486500
List<String> data = CoreUtilities.split(mechanism.getValue().asString().toUpperCase(), ',');
487501
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");
489514
}
490515
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);
505517
}
506518
}
507519

@@ -541,7 +553,8 @@ public void adjust(Mechanism mechanism) {
541553
// @tags
542554
// <EntityTag.particle>
543555
// -->
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)) {
545558
getHelper().setParticle(mechanism.getValue().asString().toUpperCase());
546559
}
547560

plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityColor.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static boolean describes(EntityTag entity) {
5555
type == EntityType.TROPICAL_FISH ||
5656
type == EntityType.GOAT ||
5757
type == EntityType.AXOLOTL ||
58+
type == EntityType.AREA_EFFECT_CLOUD ||
5859
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && MultiVersionHelper1_19.colorIsApplicable(type));
5960
}
6061

@@ -214,6 +215,9 @@ else if (type == EntityType.GOAT) {
214215
else if (type == EntityType.AXOLOTL && mechanism.requireEnum(Axolotl.Variant.class)) {
215216
as(Axolotl.class).setVariant(color.asEnum(Axolotl.Variant.class));
216217
}
218+
else if (type == EntityType.AREA_EFFECT_CLOUD && mechanism.requireObject(ColorTag.class)) {
219+
as(AreaEffectCloud.class).setColor(BukkitColorExtensions.getColor(mechanism.valueAsType(ColorTag.class)));
220+
}
217221
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && MultiVersionHelper1_19.colorIsApplicable(type)) {
218222
MultiVersionHelper1_19.setColor(getEntity(), mechanism);
219223
}
@@ -274,6 +278,7 @@ public String getColor(boolean includeDeprecated) {
274278
}
275279
case GOAT -> as(Goat.class).isScreaming() ? "screaming" : "normal";
276280
case AXOLOTL -> as(Axolotl.class).getVariant().name();
281+
case AREA_EFFECT_CLOUD -> BukkitColorExtensions.fromColor(as(AreaEffectCloud.class).getColor()).identify();
277282
default -> null;
278283
};
279284
}
@@ -313,7 +318,7 @@ public ListTag getAllowedColors() {
313318
yield result;
314319
}
315320
case AXOLOTL -> Utilities.listTypes(Axolotl.Variant.class);
316-
default -> null; // includes Ocelot (deprecated) and arrow (ColorTag)
321+
default -> null; // includes Ocelot (deprecated) and arrow/area effect cloud (ColorTag)
317322
};
318323
}
319324

@@ -340,7 +345,7 @@ public ListTag getAllowedColors() {
340345
// For tropical_fish, the input is PATTERN|BODYCOLOR|PATTERNCOLOR, where BodyColor and PatterenColor are both DyeColor (see below),
341346
// and PATTERN is KOB, SUNSTREAK, SNOOPER, DASHER, BRINELY, SPOTTY, FLOPPER, STRIPEY, GLITTER, BLOCKFISH, BETTY, is CLAYFISH.
342347
// For sheep, wolf, and shulker entities, the input is a Dye Color.
343-
// For Tipped Arrow entities, the input is a ColorTag.
348+
// For Tipped Arrow and Area effect cloud entities, the input is a ColorTag.
344349
// For goats, the input is SCREAMING or NORMAL.
345350
// For axolotl, the types are BLUE, CYAN, GOLD, LUCY, or WILD.
346351
// For frogs, the types are TEMPERATE, WARM, or COLD.

0 commit comments

Comments
 (0)