Paper/Spigot-API-Patches/0117-InventoryCloseEvent-Reason-API.patch
Shane Freeder 0976d52bbd Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Please note that this build includes changes to meet upstreams
requirements for nullability annotations. While we aim for a level of
accuracy, these might not be 100% correct, if there are any issues,
please speak to us on discord, or open an issue on the tracker to
discuss.

Bukkit Changes:
9a6a1de3 Remove nullability annotations from enum constructors
3f0591ea SPIGOT-2540: Add nullability annotations to entire Bukkit API

CraftBukkit Changes:
8d8475fc SPIGOT-4666: Force parameter in HumanEntity#sleep
8b1588e2 Fix ExplosionPrimeEvent#setFire not working with EnderCrystals
39a287b7 Don't ignore newlines in PlayerListHeader/Footer

Spigot Changes:
cf694d87 Add nullability annotations
2019-03-20 00:31:18 +00:00

97 lines
2.8 KiB
Diff

From 67edac3ee5ed7a4ccc201a7fa1ce0380146edc36 Mon Sep 17 00:00:00 2001
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
index 04f0e08fd..a372c74b8 100644
--- a/src/main/java/org/bukkit/entity/HumanEntity.java
+++ b/src/main/java/org/bukkit/entity/HumanEntity.java
@@ -152,6 +152,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 5861247c1..21ad8888c 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
}
/**
--
2.21.0