Call PlayerLaunchProjectileEvent for trident (#8027)

This commit is contained in:
Lulu13022002 2022-11-03 19:43:50 +01:00 committed by GitHub
parent e30b082262
commit ebc0f6bfb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -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.
+ * <p>
+ * 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();

View File

@ -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 :(