From ebc0f6bfb5874cbcc8c53aeee2377fbf9b7e03dd Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Thu, 3 Nov 2022 19:43:50 +0100 Subject: [PATCH] Call PlayerLaunchProjectileEvent for trident (#8027) --- .../0126-PlayerLaunchProjectileEvent.patch | 10 ++++-- .../0225-PlayerLaunchProjectileEvent.patch | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/patches/api/0126-PlayerLaunchProjectileEvent.patch b/patches/api/0126-PlayerLaunchProjectileEvent.patch index 7524daea9..d2c69beee 100644 --- a/patches/api/0126-PlayerLaunchProjectileEvent.patch +++ b/patches/api/0126-PlayerLaunchProjectileEvent.patch @@ -6,10 +6,10 @@ Subject: [PATCH] PlayerLaunchProjectileEvent diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerLaunchProjectileEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerLaunchProjectileEvent.java new file mode 100644 -index 0000000000000000000000000000000000000000..9074b2ede01f76c0560e5318246382163cc91591 +index 0000000000000000000000000000000000000000..5450575459f2d95be93db5a8c6d4d88c69deb2ec --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerLaunchProjectileEvent.java -@@ -0,0 +1,83 @@ +@@ -0,0 +1,87 @@ +package com.destroystokyo.paper.event.player; + +import org.bukkit.entity.Player; @@ -21,7 +21,11 @@ index 0000000000000000000000000000000000000000..9074b2ede01f76c0560e531824638216 +import org.jetbrains.annotations.NotNull; + +/** -+ * Called when a player shoots a projectile ++ * Called when a player shoots a projectile. ++ *
++ * Notably this event is not called for arrows as the player does not launch them, rather shoots them with the help ++ * of a bow or crossbow. A plugin may listen to {@link org.bukkit.event.entity.EntityShootBowEvent} for these actions ++ * instead. + */ +public class PlayerLaunchProjectileEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); diff --git a/patches/server/0225-PlayerLaunchProjectileEvent.patch b/patches/server/0225-PlayerLaunchProjectileEvent.patch index d732a1386..1eed95db4 100644 --- a/patches/server/0225-PlayerLaunchProjectileEvent.patch +++ b/patches/server/0225-PlayerLaunchProjectileEvent.patch @@ -274,3 +274,36 @@ index 0673f62f25532955f3552b64f122e644d42027e4..de5bdceb4c8578fb972a2fd5ee0dfdae return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide()); } +diff --git a/src/main/java/net/minecraft/world/item/TridentItem.java b/src/main/java/net/minecraft/world/item/TridentItem.java +index 998758be827efbcb7693ed36ab1dffc0ef0369bf..9365f886a23a71c41091b22d46896ff18a5a0635 100644 +--- a/src/main/java/net/minecraft/world/item/TridentItem.java ++++ b/src/main/java/net/minecraft/world/item/TridentItem.java +@@ -83,21 +83,25 @@ public class TridentItem extends Item implements Vanishable { + } + + // CraftBukkit start +- if (!world.addFreshEntity(entitythrowntrident)) { ++ // Paper start ++ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), (org.bukkit.entity.Projectile) entitythrowntrident.getBukkitEntity()); ++ if (!event.callEvent() || !world.addFreshEntity(entitythrowntrident)) { ++ // Paper end + if (entityhuman instanceof net.minecraft.server.level.ServerPlayer) { + ((net.minecraft.server.level.ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); + } + return; + } +- ++ if (event.shouldConsume()) { // Paper + stack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { + entityhuman1.broadcastBreakEvent(user.getUsedItemHand()); + }); ++ } // Paper + entitythrowntrident.tridentItem = stack.copy(); // SPIGOT-4511 update since damage call moved + // CraftBukkit end + + world.playSound((Player) null, (Entity) entitythrowntrident, SoundEvents.TRIDENT_THROW, SoundSource.PLAYERS, 1.0F, 1.0F); +- if (!entityhuman.getAbilities().instabuild) { ++ if (event.shouldConsume() && !entityhuman.getAbilities().instabuild) { // Paper + entityhuman.getInventory().removeItem(stack); + } + // CraftBukkit start - SPIGOT-5458 also need in this branch :(