2019-06-14 04:27:40 +02:00
|
|
|
From d60393114fb97bde04cb6af64cabac268418f296 Mon Sep 17 00:00:00 2001
|
2018-07-04 03:57:33 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
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
|
2019-06-06 17:36:57 +02:00
|
|
|
index cdbac95bb..f25c73155 100644
|
2018-07-04 03:57:33 +02:00
|
|
|
--- a/src/main/java/org/bukkit/entity/HumanEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/entity/HumanEntity.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -152,6 +152,15 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
|
2018-07-04 03:57:33 +02:00
|
|
|
*/
|
|
|
|
public void closeInventory();
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * Force-closes the currently open inventory view for this player, if any.
|
2018-08-16 13:20:58 +02:00
|
|
|
+ *
|
|
|
|
+ * @param reason why the inventory is closing
|
2018-07-04 03:57:33 +02:00
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public void closeInventory(@NotNull org.bukkit.event.inventory.InventoryCloseEvent.Reason reason);
|
2018-07-04 03:57:33 +02:00
|
|
|
+ // 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
|
2019-06-06 17:36:57 +02:00
|
|
|
index 5861247c1..21ad8888c 100644
|
2018-07-04 03:57:33 +02:00
|
|
|
--- a/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java
|
|
|
|
+++ b/src/main/java/org/bukkit/event/inventory/InventoryCloseEvent.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -11,9 +11,60 @@ import org.jetbrains.annotations.NotNull;
|
|
|
|
*/
|
2018-07-04 03:57:33 +02:00
|
|
|
public class InventoryCloseEvent extends InventoryEvent {
|
|
|
|
private static final HandlerList handlers = new HandlerList();
|
|
|
|
+ // Paper start
|
|
|
|
+ private final Reason reason;
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-07-04 03:57:33 +02:00
|
|
|
+ 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,
|
|
|
|
+ }
|
2019-03-20 01:28:15 +01:00
|
|
|
|
|
|
|
public InventoryCloseEvent(@NotNull InventoryView transaction) {
|
2018-07-04 03:57:33 +02:00
|
|
|
+ this(transaction, Reason.UNKNOWN);
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public InventoryCloseEvent(@NotNull InventoryView transaction, @NotNull Reason reason) {
|
2018-07-04 03:57:33 +02:00
|
|
|
super(transaction);
|
|
|
|
+ this.reason = reason;
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
--
|
2019-03-20 01:28:15 +01:00
|
|
|
2.21.0
|
2018-07-04 03:57:33 +02:00
|
|
|
|