package de.hessj.betterhoppers;

import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.ChatColor;

public class App extends JavaPlugin {
    public static App main;
    public de.hessj.helper.Helper helper= new de.hessj.helper.Helper();
    public PluginManager pM = Bukkit.getPluginManager();
    NamespacedKey nskHopper = new NamespacedKey(this, "R3SFILTERHOPPER");
    String name = "Trichterfilter";
    
    @Override
    public void onEnable() {
        main = this;
        getLogger().info("Plugin enabled!");
        listenerRegistration();

        ItemStack hopper = new ItemStack(Material.HOPPER);
        ItemMeta im = hopper.getItemMeta();
        im.displayName(Component.text(ChatColor.WHITE + name));
        im.lore(Arrays.asList(Component.text(ChatColor.GRAY + "STRG + Rechtsklick auf den platzierten Filter"),
                Component.text(ChatColor.GRAY + "ohne Item in der Hand, um den Filter zu öffnen")));
                im.setCustomModelData(1000021);


                CustomModelDataComponent cmdc = im.getCustomModelDataComponent();
        List<String> list = Arrays.asList("filter_hopper");
        cmdc.setStrings(list);
        im.setCustomModelDataComponent(cmdc);



        hopper.setItemMeta(im);

        ShapelessRecipe srHopper = new ShapelessRecipe(nskHopper, hopper);
        srHopper.addIngredient(Material.HOPPER);
        srHopper.addIngredient(Material.COMPARATOR);
        getServer().addRecipe(srHopper);
        if (getServer().getRecipe(nskHopper) == null) {
            getServer().addRecipe(srHopper);
        }

    }






    @Override
    public void onDisable() {
        getLogger().info("Plugin disabled!");
    }

    private void listenerRegistration() {
        pM.registerEvents(new BetterHopperListener(), this);
        pM.registerEvents(new LoginListener(), this);
    }

    public Boolean checkFilterHopper(ItemStack is) {

        if (is.displayName().toString().contains(name)) {
            return true;
        }

        return false;
    }
}