// Path: src/main/java/edu/self/startux/craftBay/item/ItemManager.java
// public interface ItemManager {
//     /**
//      * Does this manager manage this item exclusively?
//      */
//     boolean isManaged(ItemStack itemStack);
// 
//     /**
//      * Produce the item display name.
//      */
//     Component getDisplayName(ItemStack itemStack);
// 
//     /**
//      * Detailed item info.
//      */
//     Component getItemInfo(ItemStack itemStack);
// 
//     static List<ItemManager> getList(CraftBayPlugin plugin) {
//         List<ItemManager> result = new ArrayList<>();
//         try {
//             if (Bukkit.getPluginManager().isPluginEnabled("Mytems")) {
//                 if (Bukkit.getPluginManager().getPlugin("Mytems").getClass().getName().equals("com.cavetale.mytems.MytemsPlugin")) {
//                     result.add(new MytemsItemManager());
//                     plugin.getLogger().info("Mytems plugin found!");
//                 }
//             }
//         } catch (Throwable t) {
//             t.printStackTrace();
//         }
//         return result;
//     }
// }


import edu.self.startux.craftBay.item.ItemManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;
    }

    @Override
    public Map<String, Object> serialize() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("stack", stack);
        result.put("amount", amount);
        return result;
    }

    @SuppressWarnings("unchecked")
    public static RealItem deserialize(Map<String, Object> map) {
        ItemStack stack = (ItemStack) map.get("stack");
        Object ao = map.get("amount");
        if (ao == null) {
            return new RealItem(stack);
        } else {
            int amount = (Integer) ao;
            return new RealItem(stack, amount);
        }
    }

    @Override
    public Component toComponent() {
        return getDisplayName(stack)
            .hoverEvent(stack.asHoverEvent())
            .clickEvent(ClickEvent.runCommand("/auc preview"));
    }

    public static Component getDisplayName(ItemStack itemStack) {
// Path: src/main/java/edu/self/startux/craftBay/item/ItemManager.java
// public interface ItemManager {
//     /**
//      * Does this manager manage this item exclusively?
//      */
//     boolean isManaged(ItemStack itemStack);
// 
//     /**
//      * Produce the item display name.
//      */
//     Component getDisplayName(ItemStack itemStack);
// 
//     /**
//      * Detailed item info.
//      */
//     Component getItemInfo(ItemStack itemStack);
// 
//     static List<ItemManager> getList(CraftBayPlugin plugin) {
//         List<ItemManager> result = new ArrayList<>();
//         try {
//             if (Bukkit.getPluginManager().isPluginEnabled("Mytems")) {
//                 if (Bukkit.getPluginManager().getPlugin("Mytems").getClass().getName().equals("com.cavetale.mytems.MytemsPlugin")) {
//                     result.add(new MytemsItemManager());
//                     plugin.getLogger().info("Mytems plugin found!");
//                 }
//             }
//         } catch (Throwable t) {
//             t.printStackTrace();
//         }
//         return result;
//     }
// }


// Path: src/main/java/edu/self/startux/craftBay/RealItem.java
import edu.self.startux.craftBay.item.ItemManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionType;

    }

    @Override
    public Map<String, Object> serialize() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("stack", stack);
        result.put("amount", amount);
        return result;
    }

    @SuppressWarnings("unchecked")
    public static RealItem deserialize(Map<String, Object> map) {
        ItemStack stack = (ItemStack) map.get("stack");
        Object ao = map.get("amount");
        if (ao == null) {
            return new RealItem(stack);
        } else {
            int amount = (Integer) ao;
            return new RealItem(stack, amount);
        }
    }

    @Override
    public Component toComponent() {
        return getDisplayName(stack)
            .hoverEvent(stack.asHoverEvent())
            .clickEvent(ClickEvent.runCommand("/auc preview"));
    }

    public static Component getDisplayName(ItemStack itemStack) {
        for (ItemManager itemManager : CraftBayPlugin.getInstance().getItemManagers()) {