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 9d9b27f21c1d62dac7dd63e8af44601691e656be..f19ebe71b46d31772b486cae5d96535f28c86824 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -509,8 +509,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, java.util.function.Consumer function) { + // Paper end - launchProjectile consumer Preconditions.checkState(!this.getHandle().generation, "Cannot launch projectile during world generation"); net.minecraft.world.level.Level world = ((CraftWorld) this.getWorld()).getHandle(); @@ -593,6 +600,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 7f9a716ea65f98d1c8487438949f1d5bc8becc4a..f880b0def6ee12d1e88a732ade348ac062f8ab69 100644 --- a/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +++ b/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java @@ -56,6 +56,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, java.util.function.Consumer function) { + // Paper end - launchProjectile consumer Preconditions.checkArgument(this.getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser"); // Copied from BlockDispenser.dispense() BlockSource sourceblock = new BlockSource((ServerLevel) this.dispenserBlock.getLevel(), this.dispenserBlock.getBlockPos(), this.dispenserBlock.getBlockState(), this.dispenserBlock); @@ -146,6 +153,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();