Added the InventoryCloseEvent event

This commit is contained in:
Felix Cravic 2020-04-29 12:11:13 +02:00
parent db1e108464
commit 0782ee7fe5
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package net.minestom.server.event;
import net.minestom.server.inventory.Inventory;
public class InventoryCloseEvent extends Event {
private Inventory inventory;
public InventoryCloseEvent(Inventory inventory) {
this.inventory = inventory;
}
/**
* @return the closed inventory, null if this is the player inventory
*/
public Inventory getInventory() {
return inventory;
}
}

View File

@ -1,6 +1,7 @@
package net.minestom.server.listener;
import net.minestom.server.entity.Player;
import net.minestom.server.event.InventoryCloseEvent;
import net.minestom.server.inventory.Inventory;
import net.minestom.server.inventory.InventoryClickHandler;
import net.minestom.server.inventory.PlayerInventory;
@ -88,6 +89,8 @@ public class WindowListener {
public static void closeWindowListener(ClientCloseWindow packet, Player player) {
// if windowId == 0 then it is player's inventory, meaning that they hadn't been any open inventory packet
InventoryCloseEvent inventoryCloseEvent = new InventoryCloseEvent(player.getOpenInventory());
player.callEvent(InventoryCloseEvent.class, inventoryCloseEvent);
player.closeInventory();
}