aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0141-PlayerAttemptPickupItemEvent.patch
blob: c026ee987995a4c4e82deb66edf60e9cf256173d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
index 68fdfba22ebb35023299c776d4764d4f1555f435..db42d22f58df5daefc41720206405dda4f7ad633 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -36,6 +36,7 @@ import net.minecraft.util.Mth;
 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 {
 
@@ -380,6 +381,22 @@ public class ItemEntity extends Entity {
             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