package de.steamwar.lobby.special.easter;

import de.steamwar.lobby.listener.BasicListener;
import de.steamwar.lobby.util.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;

public class EggHuntListener extends BasicListener {

    public static final int EASTER_EGG_SLOT = 8;
    public static final ItemStack EASTER_HUNT = new ItemBuilder(Material.DRAGON_EGG, 1).setDisplayName("§fEaster Hunt").build();

    @EventHandler(priority = EventPriority.LOWEST)
    public void handlePlayerInteract(PlayerInteractEvent event) {
        ItemStack item = event.getItem();
        if(item == null)
            return;

        if (item.getType() == Material.DRAGON_EGG && item.getItemMeta() != null && item.getItemMeta().getDisplayName().equals("§fEaster Hunt")) {
            event.getPlayer().performCommand("egg");
        }
    }

    @EventHandler(priority = EventPriority.HIGH)
    public void onJoin(PlayerJoinEvent e) {
        e.getPlayer().getInventory().setItem(EASTER_EGG_SLOT, EASTER_HUNT);
    }
}
