aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch
diff options
context:
space:
mode:
Diffstat (limited to 'Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch')
-rw-r--r--Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch93
1 files changed, 93 insertions, 0 deletions
diff --git a/Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch b/Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch
new file mode 100644
index 0000000000..c03581bf2f
--- /dev/null
+++ b/Spigot-API-Patches-Unmapped/0117-InventoryCloseEvent-Reason-API.patch
@@ -0,0 +1,93 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Tue, 3 Jul 2018 21:52:52 -0400
+Subject: [PATCH] InventoryCloseEvent Reason API
+
+Allows you to determine why an inventory was closed, enabling plugin developers
+to "confirm" things based on if it was player triggered close or not.
+
+diff --git a/src/main/java/org/bukkit/entity/HumanEntity.java b/src/main/java/org/bukkit/entity/HumanEntity.java
+index 7430bc85301d0fcb34c6035fbe08ae245c76e043..3418133d07250a7fd50caad8d97924b86fb30bad 100644
+--- a/src/main/java/org/bukkit/entity/HumanEntity.java
++++ b/src/main/java/org/bukkit/entity/HumanEntity.java
+@@ -153,6 +153,15 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
+ */
+ public void closeInventory();
+
++ // Paper start
++ /**
++ * Force-closes the currently open inventory view for this player, if any.
++ *
++ * @param reason why the inventory is closing
++ */
++ public void closeInventory(@NotNull org.bukkit.event.inventory.InventoryCloseEvent.Reason reason);
++ // Paper end
++
+ /**
+ * Returns the ItemStack currently in your hand, can be empty.
+ *
+diff --git a/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java b/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java
+index 5861247c1b8ee4fe2736fd5098e05a2ca9ab78ea..21ad8888c0e403bfc63518502577d651c02dda05 100644
+--- a/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java
++++ b/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java
+@@ -11,9 +11,60 @@ import org.jetbrains.annotations.NotNull;
+ */
+ public class InventoryCloseEvent extends InventoryEvent {
+ private static final HandlerList handlers = new HandlerList();
++ // Paper start
++ private final Reason reason;
++ @NotNull
++ public Reason getReason() {
++ return reason;
++ }
++
++ public enum Reason {
++ /**
++ * Unknown reason
++ */
++ UNKNOWN,
++ /**
++ * Player is teleporting
++ */
++ TELEPORT,
++ /**
++ * Player is no longer permitted to use this inventory
++ */
++ CANT_USE,
++ /**
++ * The chunk the inventory was in was unloaded
++ */
++ UNLOADED,
++ /**
++ * Opening new inventory instead
++ */
++ OPEN_NEW,
++ /**
++ * Closed
++ */
++ PLAYER,
++ /**
++ * Closed due to disconnect
++ */
++ DISCONNECT,
++ /**
++ * The player died
++ */
++ DEATH,
++ /**
++ * Closed by Bukkit API
++ */
++ PLUGIN,
++ }
+
+ public InventoryCloseEvent(@NotNull InventoryView transaction) {
++ this(transaction, Reason.UNKNOWN);
++ }
++
++ public InventoryCloseEvent(@NotNull InventoryView transaction, @NotNull Reason reason) {
+ super(transaction);
++ this.reason = reason;
++ // Paper end
+ }
+
+ /**