13
0
geforkt von Mirrors/Paper

Fixup PlayerPickItemEvent docs more

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-12-05 18:50:00 +01:00
Ursprung 1e7128544f
Commit 640db1bea9

Datei anzeigen

@ -22,12 +22,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+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
+ * item). However, note that this event will only trigger if an item has to be moved from the inventory to the hotbar.
+ * After the handling of this event, the contents of the source and the target slot will be swapped and the currently
+ * 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.
+ * Event that is fired when a player uses the pick item functionality (middle-clicking a block or entity to get the
+ * appropriate item). After the handling of this event, the contents of the source and the target slot will be swapped
+ * and the currently selected hotbar slot of the player will be set to the target slot.
+ */
+@NullMarked
+public class PlayerPickItemEvent extends PlayerEvent implements Cancellable {
@ -68,9 +65,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /**
+ * Returns the slot in which the item that will be put into the players hotbar is located.
+ * <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() {
+ return this.sourceSlot;
@ -81,10 +79,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * <p>
+ * 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) {
+ 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;
+ }
+