From 13c6dbb099132f4a4262a433c45a422a49de79a3 Mon Sep 17 00:00:00 2001 From: Christopher White <18whitechristop@gmail.com> Date: Sat, 9 Sep 2023 22:51:27 -0700 Subject: [PATCH] Add yield attribute for projectiles Signed-off-by: Christopher White <18whitechristop@gmail.com> --- .../main/java/tc/oc/pgm/projectile/ProjectileDefinition.java | 3 +++ .../main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java | 4 ++++ core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java index 5925152643..24fe7d4e27 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java @@ -11,6 +11,7 @@ public class ProjectileDefinition extends SelfIdentifyingFeatureDefinition { protected @Nullable String name; protected @Nullable Double damage; + protected @Nullable Float power; protected double velocity; protected ClickAction clickAction; protected Class projectile; @@ -24,6 +25,7 @@ public ProjectileDefinition( @Nullable String id, @Nullable String name, @Nullable Double damage, + @Nullable Float power, double velocity, ClickAction clickAction, Class entity, @@ -35,6 +37,7 @@ public ProjectileDefinition( super(id); this.name = name; this.damage = damage; + this.power = power; this.velocity = velocity; this.clickAction = clickAction; this.projectile = entity; diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java index 4cdfad6af2..c2657de3d4 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java @@ -8,6 +8,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.Explosive; import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -105,6 +106,9 @@ && isValidProjectileAction(event.getAction(), projectileDefinition.clickAction)) player.getWorld().spawn(player.getEyeLocation(), projectileDefinition.projectile); projectile.setVelocity(velocity); } + if (projectileDefinition.power != null && projectile instanceof Explosive) { + ((Explosive) projectile).setYield(projectileDefinition.power); + } projectile.setMetadata( "projectileDefinition", new FixedMetadataValue(PGM.get(), projectileDefinition)); } finally { diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java index 80f3ddbefd..4e1308466b 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java @@ -65,6 +65,9 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc) Node.fromAttr(projectileElement, "click"), ClickAction.class, ClickAction.BOTH); Class entity = XMLUtils.parseEntityTypeAttribute(projectileElement, "projectile", Arrow.class); + Float power = + XMLUtils.parseNumber( + Node.fromChildOrAttr(projectileElement, "power"), Float.class, (Float) null); List potionKit = kitParser.parsePotions(projectileElement); Filter destroyFilter = filterParser.parseFilterProperty(projectileElement, "destroy-filter"); @@ -78,6 +81,7 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc) id, name, damage, + power, velocity, clickAction, entity,