package com.loganmagnan.eventcore.listeners;

import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.menusystem.Menu;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryHolder;

public class MenuListener implements Listener {

    private EventCore main = EventCore.getInstance();

    @EventHandler
    public void onMenuClick(InventoryClickEvent event) {
        InventoryHolder inventoryHolder = event.getInventory().getHolder();

        if (inventoryHolder instanceof Menu) {
            event.setCancelled(true);

            if (event.getCurrentItem() == null) {
                return;
            }

            Menu menu = (Menu) inventoryHolder;
            menu.handleMenu(event);
        }
    }
}
