From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MelnCat Date: Mon, 19 Sep 2022 14:16:10 -0700 Subject: [PATCH] Add a consumer parameter to ProjectileSource#launchProjectile diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 1a41f371d9fc147ab0fd833d1bacb10096ec4f65..b0de36ed125a21d6f92f22351bb34040cdc42f53 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -499,8 +499,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { } @Override - @SuppressWarnings("unchecked") public T launchProjectile(Class projectile, Vector velocity) { + // Paper start - launchProjectile consumer + return this.launchProjectile(projectile, velocity, null); + } + + @Override + @SuppressWarnings("unchecked") + public T launchProjectile(Class projectile, Vector velocity, org.bukkit.util.Consumer function) { + // Paper end - launchProjectile consumer Preconditions.checkState(!this.getHandle().generation, "Cannot launch projectile during world generation"); net.minecraft.world.level.Level world = ((CraftWorld) getWorld()).getHandle(); @@ -583,6 +590,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { if (velocity != null) { ((T) launch.getBukkitEntity()).setVelocity(velocity); } + // Paper start - launchProjectile consumer + if (function != null) { + function.accept((T) launch.getBukkitEntity()); + } + // Paper end - launchProjectile consumer world.addFreshEntity(launch); return (T) launch.getBukkitEntity(); diff --git a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java index 01725215768e7340234987969bcf5386f0e1711b..26c0552735a4056db290cc9a5eb7814c2a79e7f0 100644 --- a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +++ b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java @@ -58,6 +58,13 @@ public class CraftBlockProjectileSource implements BlockProjectileSource { @Override public T launchProjectile(Class projectile, Vector velocity) { + // Paper start - launchProjectile consumer + return this.launchProjectile(projectile, velocity, null); + } + + @Override + public T launchProjectile(Class projectile, Vector velocity, org.bukkit.util.Consumer function) { + // Paper end - launchProjectile consumer Preconditions.checkArgument(this.getBlock().getType() == BlockType.DISPENSER, "Block is no longer dispenser"); // Copied from BlockDispenser.dispense() BlockSourceImpl isourceblock = new BlockSourceImpl((ServerLevel) this.dispenserBlock.getLevel(), this.dispenserBlock.getBlockPos()); @@ -148,6 +155,11 @@ public class CraftBlockProjectileSource implements BlockProjectileSource { if (velocity != null) { ((T) launch.getBukkitEntity()).setVelocity(velocity); } + // Paper start + if (function != null) { + function.accept((T) launch.getBukkitEntity()); + } + // Paper end world.addFreshEntity(launch); return (T) launch.getBukkitEntity();