1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2024-12-23 15:00:30 +01:00
PaperMC/patches/api/0055-PlayerAttemptPickupItemEvent.patch

107 lines
2.9 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: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..eff29875f6282d8bd04a33cb572c90090742d3b2
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java
@@ -0,0 +1,94 @@
2021-06-11 14:02:28 +02:00
+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;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Thrown when a player attempts to pick an item up from the ground
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class PlayerAttemptPickupItemEvent extends PlayerEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Item item;
2021-06-11 14:02:28 +02:00
+ private final int remaining;
+ private boolean flyAtPlayer = true;
2024-02-01 10:15:57 +01:00
+
+ private boolean cancelled;
2021-06-11 14:02:28 +02:00
+
+ @Deprecated // Remove in 1.13 // Remove in 1.14?
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public PlayerAttemptPickupItemEvent(final Player player, final Item item) {
2021-06-11 14:02:28 +02:00
+ this(player, item, 0);
+ }
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public PlayerAttemptPickupItemEvent(final Player player, final Item item, final int remaining) {
2021-06-11 14:02:28 +02:00
+ super(player);
+ this.item = item;
+ this.remaining = remaining;
+ }
+
+ /**
+ * Gets the Item attempted by the player.
+ *
+ * @return Item
+ */
+ public Item getItem() {
2024-02-01 10:15:57 +01:00
+ return this.item;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Gets the amount that will remain on the ground, if any
+ *
+ * @return amount that will remain on the ground
+ */
+ public int getRemaining() {
2024-02-01 10:15:57 +01:00
+ return this.remaining;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Set if the item will fly at the player
+ * <p>Cancelling the event will set this value to false.</p>
+ *
2024-02-01 10:15:57 +01:00
+ * @param flyAtPlayer {@code true} for item to fly at player
2021-06-11 14:02:28 +02:00
+ */
+ public void setFlyAtPlayer(boolean flyAtPlayer) {
+ this.flyAtPlayer = flyAtPlayer;
+ }
+
+ /**
+ * Gets if the item will fly at the player
+ *
2024-02-01 10:15:57 +01:00
+ * @return {@code true} if the item will fly at the player
2021-06-11 14:02:28 +02:00
+ */
+ public boolean getFlyAtPlayer() {
+ return this.flyAtPlayer;
+ }
+
+
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
2021-06-11 14:02:28 +02:00
+ this.flyAtPlayer = !cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}