From 4400eb660071e1b8fb829b63add4b93e363d94d5 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) --- patches/api/PlayerLaunchProjectileEvent.patch | 6 +++- .../server/PlayerLaunchProjectileEvent.patch | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/patches/api/PlayerLaunchProjectileEvent.patch b/patches/api/PlayerLaunchProjectileEvent.patch index 1479d4e1d1..1affff198b 100644 --- a/patches/api/PlayerLaunchProjectileEvent.patch +++ b/patches/api/PlayerLaunchProjectileEvent.patch @@ -21,7 +21,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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/PlayerLaunchProjectileEvent.patch b/patches/server/PlayerLaunchProjectileEvent.patch index 15d76391d9..a8914014f5 100644 --- a/patches/server/PlayerLaunchProjectileEvent.patch +++ b/patches/server/PlayerLaunchProjectileEvent.patch @@ -274,3 +274,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/item/TridentItem.java ++++ b/src/main/java/net/minecraft/world/item/TridentItem.java +@@ -0,0 +0,0 @@ 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 :(