package de.hessj.chestex;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
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 NamespacedKey nskLockedChest = new NamespacedKey(this, "R3SLockedChest");
    public NamespacedKey nskLockedChestRecipe = new NamespacedKey(this, "R3SLockedChestRecipe");
    public ItemStack lockedChest;

    @Override
    public void onEnable() {
        getLogger().info("Plugin enabled!");
        main = this;
        
        
        lockedChest = new ItemStack(Material.CHEST);
        ItemMeta imlockedChest = lockedChest.getItemMeta();
        imlockedChest.displayName(Component.translatable(ChatColor.AQUA + "Verschlossene Truhe"));
        imlockedChest.getPersistentDataContainer().set(nskLockedChest, PersistentDataType.STRING, "R3S_LockedChest");
        lockedChest.setItemMeta(imlockedChest);
        ShapedRecipe safechestRecipe = new ShapedRecipe(nskLockedChestRecipe, lockedChest);
        RecipeChoice rc = new RecipeChoice.MaterialChoice(Material.OAK_LOG, Material.SPRUCE_LOG, Material.BIRCH_LOG,
                Material.JUNGLE_LOG, Material.ACACIA_LOG, Material.DARK_OAK_LOG);
        safechestRecipe.shape("LLL", "LKL", "III");
        safechestRecipe.setIngredient('L', rc);
        safechestRecipe.setIngredient('K', Material.TRIPWIRE_HOOK);
        safechestRecipe.setIngredient('I', Material.IRON_INGOT);
		if (getServer().getRecipe(nskLockedChestRecipe) == null) {
        App.main.getServer().addRecipe(safechestRecipe);
		}
        listenerRegistration();
    }

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

    private void listenerRegistration() {
        PluginManager pM = Bukkit.getPluginManager();
        pM.registerEvents(new SafeChestListener(), this);
    }
}