spigot/Bukkit-Patches/0010-InventoryClickEvent-getClickedInventory.patch

55 lines
2.1 KiB
Diff
Raw Normal View History

2018-01-22 01:19:57 +11:00
From ecb2594a04abc80c4af6fff64eca95e9be52f0a8 Mon Sep 17 00:00:00 2001
2013-07-09 10:31:10 +10:00
From: Aikar <aikar@aikar.co>
Date: Sun, 7 Jul 2013 10:32:05 -0400
Subject: [PATCH] InventoryClickEvent getClickedInventory
Add InventoryClickEvent.getClickedInventory. Adds BUKKIT-4495
Plugins currently have to do the logic themselves on the raw slot ID
in order to determine the inventory clicked. This provides the logic for plugins to
readily identify which inventory was clicked.
diff --git a/src/main/java/org/bukkit/event/inventory/InventoryClickEvent.java b/src/main/java/org/bukkit/event/inventory/InventoryClickEvent.java
2017-04-30 09:32:32 +10:00
index 55527652..60feaf3b 100644
2013-07-09 10:31:10 +10:00
--- a/src/main/java/org/bukkit/event/inventory/InventoryClickEvent.java
+++ b/src/main/java/org/bukkit/event/inventory/InventoryClickEvent.java
@@ -47,6 +47,7 @@ public class InventoryClickEvent extends InventoryInteractEvent {
private static final HandlerList handlers = new HandlerList();
private final ClickType click;
private final InventoryAction action;
+ private final Inventory clickedInventory;
private SlotType slot_type;
private int whichSlot;
private int rawSlot;
2016-11-17 12:41:12 +11:00
@@ -57,6 +58,13 @@ public class InventoryClickEvent extends InventoryInteractEvent {
2013-07-09 10:31:10 +10:00
super(view);
this.slot_type = type;
this.rawSlot = slot;
+ if (slot < 0) {
+ this.clickedInventory = null;
+ } else if (view.getTopInventory() != null && slot < view.getTopInventory().getSize()) {
+ this.clickedInventory = view.getTopInventory();
+ } else {
+ this.clickedInventory = view.getBottomInventory();
+ }
this.whichSlot = view.convertSlot(slot);
this.click = click;
this.action = action;
2017-11-07 17:30:57 +11:00
@@ -67,6 +75,14 @@ public class InventoryClickEvent extends InventoryInteractEvent {
this.hotbarKey = key;
2013-07-09 10:31:10 +10:00
}
2017-11-07 17:30:57 +11:00
+ /**
2013-07-09 10:31:10 +10:00
+ * Gets the inventory that was clicked, or null if outside of window
+ * @return The clicked inventory
+ */
+ public Inventory getClickedInventory() {
+ return clickedInventory;
+ }
+
2017-11-07 17:30:57 +11:00
/**
2013-07-09 10:31:10 +10:00
* Gets the type of slot that was clicked.
*
--
2017-11-07 17:30:57 +11:00
2.14.1
2013-07-09 10:31:10 +10:00