aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0058-PlayerAttemptPickupItemEvent.patch
blob: e688f9297669f2065f115daba36184299b5d138f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sun, 11 Jun 2017 16:30:37 -0500
Subject: [PATCH] PlayerAttemptPickupItemEvent


diff --git a/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..13e4b1309ea9965a07fc8b276d5a7e606e205824
--- /dev/null
+++ b/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java
@@ -0,0 +1,96 @@
+package org.bukkit.event.player;
+
+import org.bukkit.entity.Item;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Thrown when a player attempts to pick an item up from the ground
+ */
+public class PlayerAttemptPickupItemEvent extends PlayerEvent implements Cancellable {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    @NotNull private final Item item;
+    private final int remaining;
+    private boolean flyAtPlayer = true;
+
+    private boolean cancelled;
+
+    @Deprecated // Remove in 1.13 // Remove in 1.14?
+    @ApiStatus.Internal
+    public PlayerAttemptPickupItemEvent(@NotNull final Player player, @NotNull final Item item) {
+        this(player, item, 0);
+    }
+
+    @ApiStatus.Internal
+    public PlayerAttemptPickupItemEvent(@NotNull final Player player, @NotNull final Item item, final int remaining) {
+        super(player);
+        this.item = item;
+        this.remaining = remaining;
+    }
+
+    /**
+     * Gets the Item attempted by the player.
+     *
+     * @return Item
+     */
+    @NotNull
+    public Item getItem() {
+        return this.item;
+    }
+
+    /**
+     * Gets the amount that will remain on the ground, if any
+     *
+     * @return amount that will remain on the ground
+     */
+    public int getRemaining() {
+        return this.remaining;
+    }
+
+    /**
+     * Set if the item will fly at the player
+     * <p>Cancelling the event will set this value to false.</p>
+     *
+     * @param flyAtPlayer {@code true} for item to fly at player
+     */
+    public void setFlyAtPlayer(boolean flyAtPlayer) {
+        this.flyAtPlayer = flyAtPlayer;
+    }
+
+    /**
+     * Gets if the item will fly at the player
+     *
+     * @return {@code true} if the item will fly at the player
+     */
+    public boolean getFlyAtPlayer() {
+        return this.flyAtPlayer;
+    }
+
+
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+        this.flyAtPlayer = !cancel;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}