Fixup PlayerPickItemEvent docs more

This commit is contained in:
Nassim Jahnke 2024-12-05 18:50:00 +01:00
parent 77afb9aa78
commit 346b9b8d2d
No known key found for this signature in database
GPG key ID: EF6771C01F6EF02F

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Add PlayerPickItemEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..e9b968ebd771b9d4c94d7b219ea2b68c1f871733 index 0000000000000000000000000000000000000000..7de240399f3ae069c496add9f0d437a41ed8f58d
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java +++ b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
@@ -0,0 +1,97 @@ @@ -0,0 +1,95 @@
+package io.papermc.paper.event.player; +package io.papermc.paper.event.player;
+ +
+import com.google.common.base.Preconditions; +import com.google.common.base.Preconditions;
@ -22,12 +22,9 @@ index 0000000000000000000000000000000000000000..e9b968ebd771b9d4c94d7b219ea2b68c
+import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullMarked;
+ +
+/** +/**
+ * Event that is fired when a player uses the pick item functionality (middle-clicking a block to get the appropriate + * Event that is fired when a player uses the pick item functionality (middle-clicking a block or entity to get the
+ * item). However, note that this event will only trigger if an item has to be moved from the inventory to the hotbar. + * appropriate item). After the handling of this event, the contents of the source and the target slot will be swapped
+ * After the handling of this event, the contents of the source and the target slot will be swapped and the currently + * and the currently selected hotbar slot of the player will be set to the target slot.
+ * selected hotbar slot of the player will be set to the target slot.
+ * <p>
+ * Note: This event will not be fired for players in creative mode.
+ */ + */
+@NullMarked +@NullMarked
+public class PlayerPickItemEvent extends PlayerEvent implements Cancellable { +public class PlayerPickItemEvent extends PlayerEvent implements Cancellable {
@ -68,9 +65,10 @@ index 0000000000000000000000000000000000000000..e9b968ebd771b9d4c94d7b219ea2b68c
+ /** + /**
+ * Returns the slot in which the item that will be put into the players hotbar is located. + * Returns the slot in which the item that will be put into the players hotbar is located.
+ * <p> + * <p>
+ * Returns {@code -1} if the item is not in the player's inventory and should be spawned in if in creative mode. + * Returns {@code -1} if the item is not in the player's inventory.
+ * If this is the case and the player is in creative mode, the item will be spawned in.
+ * + *
+ * @return player inventory slot (0-35 inclusive, or {@code -1} not taken from the inventory) + * @return player inventory slot (0-35 inclusive, or {@code -1} if not in the player inventory)
+ */ + */
+ public @Range(from = -1, to = 35) int getSourceSlot() { + public @Range(from = -1, to = 35) int getSourceSlot() {
+ return this.sourceSlot; + return this.sourceSlot;
@ -81,10 +79,10 @@ index 0000000000000000000000000000000000000000..e9b968ebd771b9d4c94d7b219ea2b68c
+ * <p> + * <p>
+ * If set to {@code -1} and the player is in creative mode, the item will be spawned in. + * If set to {@code -1} and the player is in creative mode, the item will be spawned in.
+ * + *
+ * @param sourceSlot player inventory slot (0-35 inclusive, or {@code -1} not taken from the inventory) + * @param sourceSlot player inventory slot (0-35 inclusive, or {@code -1} if not in the player inventory)
+ */ + */
+ public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) { + public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) {
+ Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot"); + Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot, or -1");
+ this.sourceSlot = sourceSlot; + this.sourceSlot = sourceSlot;
+ } + }
+ +