Skip to content

Commit

Permalink
Add power attribute for projectiles (#1237)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 authored Sep 16, 2023
1 parent 129c2b5 commit d3e8c4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Entity> projectile;
Expand All @@ -24,6 +25,7 @@ public ProjectileDefinition(
@Nullable String id,
@Nullable String name,
@Nullable Double damage,
@Nullable Float power,
double velocity,
ClickAction clickAction,
Class<? extends Entity> entity,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc)
Node.fromAttr(projectileElement, "click"), ClickAction.class, ClickAction.BOTH);
Class<? extends Entity> entity =
XMLUtils.parseEntityTypeAttribute(projectileElement, "projectile", Arrow.class);
Float power =
XMLUtils.parseNumber(
Node.fromChildOrAttr(projectileElement, "power"), Float.class, (Float) null);
List<PotionEffect> potionKit = kitParser.parsePotions(projectileElement);
Filter destroyFilter =
filterParser.parseFilterProperty(projectileElement, "destroy-filter");
Expand All @@ -78,6 +81,7 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc)
id,
name,
damage,
power,
velocity,
clickAction,
entity,
Expand Down

0 comments on commit d3e8c4e

Please sign in to comment.