package com.io.yutian.boxsimulate.listener;

import com.io.yutian.boxsimulate.gui.GuiHolder;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

public class GuiListener implements Listener {

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        Inventory inventory = event.getInventory();
        InventoryHolder holder = inventory.getHolder();
        if (holder != null && holder instanceof GuiHolder) {
            GuiHolder guiHolder = (GuiHolder) holder;
            guiHolder.onClick(event);
        }
    }

    @EventHandler
    public void onInventoryClose(InventoryCloseEvent event) {
        Inventory inventory = event.getInventory();
        InventoryHolder holder = inventory.getHolder();
        if (holder != null && holder instanceof GuiHolder) {
            GuiHolder guiHolder = (GuiHolder) holder;
            guiHolder.onClose(event);
        }
    }

}