Paper/patches/server/0139-PlayerAttemptPickupItemEvent.patch

42 lines
1.8 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sun, 11 Jun 2017 16:30:30 -0500
Subject: [PATCH] PlayerAttemptPickupItemEvent
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2022-12-07 19:52:24 +01:00
index 6a1bc0874ca0d07a2fcb98f3a8d1fff4625a35f0..42b056d58146991b86de0690fce595716ee5455b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2022-12-07 19:52:24 +01:00
@@ -34,6 +34,7 @@ import net.minecraft.util.Mth;
2021-06-11 14:02:28 +02:00
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
// CraftBukkit end
+import org.bukkit.event.player.PlayerAttemptPickupItemEvent; // Paper
public class ItemEntity extends Entity {
2022-12-07 19:52:24 +01:00
@@ -388,6 +389,22 @@ public class ItemEntity extends Entity {
2021-06-11 14:02:28 +02:00
int remaining = i - canHold;
boolean flyAtPlayer = false; // Paper
+ // Paper start
+ if (this.pickupDelay <= 0) {
+ PlayerAttemptPickupItemEvent attemptEvent = new PlayerAttemptPickupItemEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
+ this.level.getCraftServer().getPluginManager().callEvent(attemptEvent);
+
+ flyAtPlayer = attemptEvent.getFlyAtPlayer();
+ if (attemptEvent.isCancelled()) {
+ if (flyAtPlayer) {
+ player.take(this, i);
+ }
+
+ return;
+ }
+ }
+ // Paper end
+
if (this.pickupDelay <= 0 && canHold > 0) {
itemstack.setCount(canHold);
// Call legacy event