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:52:52 -04:00
parent f8562d67ca
commit 6d3de60244
2 changed files with 60 additions and 0 deletions

View file

@ -187,6 +187,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.
*

View file

@ -30,9 +30,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
}
/**