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.
This commit is contained in:
Aikar
2018-07-03 21:56:23 -04:00
parent 7749dcdd84
commit 3430a002d1
8 changed files with 168 additions and 112 deletions

View File

@@ -387,7 +387,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
if (((ServerPlayer) this.getHandle()).connection == null) return;
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
// fire INVENTORY_CLOSE if one already open
((ServerPlayer) this.getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(this.getHandle().containerMenu.containerId));
((ServerPlayer) this.getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(this.getHandle().containerMenu.containerId), org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper - Inventory close reason
}
ServerPlayer player = (ServerPlayer) this.getHandle();
AbstractContainerMenu container;
@@ -457,8 +457,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
@Override
public void closeInventory() {
this.getHandle().closeContainer();
// Paper start - Inventory close reason
this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.PLUGIN);
}
@Override
public void closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
getHandle().closeContainer(reason);
}
// Paper end - Inventory close reason
@Override
public boolean isBlocking() {

View File

@@ -1278,7 +1278,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Close any foreign inventory
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
this.getHandle().closeContainer();
this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); // Paper - Inventory close reason
}
// Check if the fromWorld and toWorld are the same.