From 4ec29f51dc419aa4f238a8ee1327ed9dd926072f Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 8 Jul 2013 14:59:17 +1000 Subject: [PATCH] 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. --- ...entoryClickEvent-getClickedInventory.patch | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Bukkit-Patches/0014-InventoryClickEvent-getClickedInventory.patch diff --git a/Bukkit-Patches/0014-InventoryClickEvent-getClickedInventory.patch b/Bukkit-Patches/0014-InventoryClickEvent-getClickedInventory.patch new file mode 100644 index 0000000000..54f976b157 --- /dev/null +++ b/Bukkit-Patches/0014-InventoryClickEvent-getClickedInventory.patch @@ -0,0 +1,54 @@ +From 87b85aeb82022fe819ac1605e9c7fa4ea48d3c11 Mon Sep 17 00:00:00 2001 +From: Aikar +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 +index 28198b8..3313d91 100644 +--- 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; +@@ -62,6 +63,13 @@ public class InventoryClickEvent extends InventoryInteractEvent { + 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; +@@ -73,6 +81,14 @@ public class InventoryClickEvent extends InventoryInteractEvent { + } + + /** ++ * Gets the inventory that was clicked, or null if outside of window ++ * @return The clicked inventory ++ */ ++ public Inventory getClickedInventory() { ++ return clickedInventory; ++ } ++ ++ /** + * Gets the type of slot that was clicked. + * + * @return the slot type +-- +1.8.1.2 +