Привет, у меня есть 3 класса, сделай их проще и компактнее, но функционал должен остаться как был.
package dev.okenote.items;

import dev.okenote.entities.player.Faction;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.tag.Tag;

import java.util.*;

@Getter
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class JediItem {

    Map<String, ItemStack> serverItems = new HashMap<>();

    public MetaData applyJediItem(ItemStack itemStack, String techName, Category category, Rare rare) {
        ItemStack newItemStack = itemStack.with(metaBuilder -> {
            metaBuilder.set(Tag.String("techName"), techName);
            metaBuilder.set(Tag.String("category"), category.getNamespace());
            metaBuilder.set(Tag.String("rare"), rare.getRarity());
        });

        return new MetaData(newItemStack, techName, this);
    }

    public String itemStackToString(ItemStack itemStack) {
        String techName = itemStack.getTag(Tag.String("techName"));
        if (techName == null) return null;

        int amount = itemStack.amount();

        List<String> metaValues = new ArrayList<>();

        for (JediItemComponent component : JediItemComponent.values()) {
            if (component.isSaveMetaData()) {
                Tag<?> tag = getTagForComponent(component);
                if (tag != null) {
                    Object value = null;
                    if (component.getTypeClass() == Integer.class) {
                        value = itemStack.getTag((Tag<Integer>) tag);
                    } else if (component.getTypeClass() == String.class) {
                        value = itemStack.getTag((Tag<String>) tag);
                    }
                    metaValues.add(value != null ? value.toString() : "0");
                }
            }
        }

        return techName + ":" + amount + ":" + String.join(",", metaValues);
    }

    public ItemStack convertStringFromItemStack(String data) {
        String[] parts = data.split(":");

        if (parts.length < 3) return null;

        String techName = parts[0];
        int amount = Integer.parseInt(parts[1]);
        String[] metaValues = parts[2].split(",");

        ItemStack itemStack = serverItems.get(techName);

        if (itemStack == null) return null;

        itemStack = itemStack.withAmount(amount);

        ItemStack newItemStack = itemStack;

        int metaIndex = 0;
        for (JediItemComponent component : JediItemComponent.values()) {
            if (component.isSaveMetaData() && metaIndex < metaValues.length) {
                String value = metaValues[metaIndex];
                Tag<?> tag = getTagForComponent(component);
                if (tag != null && value != null) {
                    newItemStack = newItemStack.with(metaBuilder -> {
                        if (component.getTypeClass() == Integer.class) {
                            metaBuilder.set((Tag<Integer>) tag, Integer.parseInt(value));
                        } else if (component.getTypeClass() == String.class) {
                            metaBuilder.set((Tag<String>) tag, value);
                        }
                    });
                }
                metaIndex++;
            }
        }

        return newItemStack;
    }

    private Tag<?> getTagForComponent(JediItemComponent component) {
        if (component.getTypeClass() == Integer.class) {
            return Tag.Integer(component.getNamespace());
        } else if (component.getTypeClass() == String.class) {
            return Tag.String(component.getNamespace());
        } else if (component.getTypeClass() == Double.class) {
            return Tag.Double(component.getNamespace());
        } else if (component.getTypeClass() == Boolean.class) {
            return Tag.Boolean(component.getNamespace());
        }
        return null;
    }

    @Getter
    @FieldDefaults(level = AccessLevel.PRIVATE)
    public static class MetaData {

        ItemStack itemStack;
        final String techName;
        final JediItem jediItem;

        public MetaData(ItemStack itemStack, String techName, JediItem jediItem) {
            this.techName = techName;
            this.jediItem = jediItem;

            this.itemStack = itemStack.with(metaBuilder -> {
                if (itemStack.getTag(Tag.String("category")).equals(Category.SWORD.getNamespace()) ||
                        itemStack.getTag(Tag.String("category")).equals(Category.ABILITY.getNamespace()) ||
                        itemStack.getTag(Tag.String("category")).equals(Category.SPECIAL_ITEM.getNamespace()) ||
                        itemStack.getTag(Tag.String("category")).equals(Category.OTHER.getNamespace()))
                    metaBuilder.set(Tag.Integer(JediItemComponent.UID.getNamespace()), 1);
                if (itemStack.getTag(Tag.String("category")).equals(Category.SWORD.getNamespace()) ||
                        itemStack.getTag(Tag.String("category")).equals(Category.ABILITY.getNamespace()) ||
                        (itemStack.getTag(Tag.String("category")).equals(Category.SPECIAL_ITEM.getNamespace()) && itemStack.getTag(Tag.String("rare")).equals(Rare.getMaxRareByWeight(40))) ||
                        (itemStack.getTag(Tag.String("category")).equals(Category.OTHER.getNamespace()) && itemStack.getTag(Tag.String("rare")).equals(Rare.getMaxRareByWeight(35))))
                    metaBuilder.set(Tag.String(JediItemComponent.OWNER.getNamespace()), "null");
                if (itemStack.getTag(Tag.String("category")).equals(Category.SWORD.getNamespace()))
                    metaBuilder.set(Tag.Integer(JediItemComponent.MOB_KILLS.getNamespace()), 0);
                if (itemStack.getTag(Tag.String("category")).equals(Category.SWORD.getNamespace()))
                    metaBuilder.set(Tag.Integer(JediItemComponent.PLAYER_KILLS.getNamespace()), 0);
            });
            /*
        UID -> SWORD, ABILITY, SPECIAL_ITEM, OTHER
        OWNER -> SWORD, ABILITY, SPECIAL_ITEM && EXTRAORDINARY(>40), && OTHER LEGENDARY(>35)
        MOB_KILL -> SWORD
        PLAYER_KILL -> SWORD
            */
        }

        public MetaData nodrop() {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.Boolean(JediItemComponent.NODROP.getNamespace()), true);
            });
            return this;
        }

        public MetaData uid() {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.Integer(JediItemComponent.UID.getNamespace()), 1);
            });
            return this;
        }

        public MetaData level(int level) {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.Integer(JediItemComponent.LEVEL.getNamespace()), level);
            });
            return this;
        }

        public MetaData faction(Faction faction) {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.String(JediItemComponent.FACTION.getNamespace()), faction.name().toLowerCase());
            });
            return this;
        }

        public MetaData owner() {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.String(JediItemComponent.OWNER.getNamespace()), "null");
            });
            return this;
        }

        public MetaData starTrack() {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(Tag.Integer(JediItemComponent.MOB_KILLS.getNamespace()), 0);
                metaBuilder.set(Tag.Integer(JediItemComponent.PLAYER_KILLS.getNamespace()), 0);
            });
            return this;
        }

        public MetaData damage(int damage, double criticalDamage, double criticalChance) {
            itemStack = itemStack.with(metaBuilder -> {
                metaBuilder.set(ItemComponent.DAMAGE, damage);
                metaBuilder.set(Tag.Double(JediItemComponent.CRITICAL_DAMAGE.getNamespace()), criticalDamage);
                metaBuilder.set(Tag.Double(JediItemComponent.CRITICAL_CHANCE.getNamespace()), criticalChance);
            });
            return this;
        }

        public void build() {
            jediItem.serverItems.put(techName, itemStack);
        }
    }

    @Getter
    @AllArgsConstructor
    @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
    public enum Rare {

        DEFAULT(NamedTextColor.WHITE, "Обычный", 1),
        RARE(NamedTextColor.RED, "Редкий", 10),
        EPIC(NamedTextColor.DARK_PURPLE, "Эпический", 20),
        SECRET(NamedTextColor.RED, "Тайный", 25),
        MYTHICAL(NamedTextColor.LIGHT_PURPLE, "Мифический", 30),
        LEGENDARY(NamedTextColor.GOLD, "Легендарный", 35),
        EXTRAORDINARY(NamedTextColor.YELLOW, "Экстраординарный", 40),
        SMUGGLED(NamedTextColor.GOLD, "Контрабандный", 45),
        RARITY(NamedTextColor.GOLD, "Раритетный", 50);

        NamedTextColor color;
        String rarity;
        int weight;

        public Component getName() {
            return Component.text(rarity, color);
        }

        public static Rare getWeight(int weight) {
            return Arrays.stream(Rare.values()).filter(rare -> rare.getWeight() == weight).findFirst().orElse(DEFAULT);
        }

        public static Rare getMaxRareByWeight(int weight) {
            return Arrays.stream(Rare.values())
                    .filter(rare -> rare.getWeight() >= weight)
                    .max(Comparator.comparingInt(Rare::getWeight))
                    .orElse(Rare.DEFAULT);
        }
    }

    @Getter
    @AllArgsConstructor
    @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
    public enum Category {

        SWORD(NamedTextColor.RED, "Оружие ближнего боя", "sword"),
        EAT(NamedTextColor.GREEN, "Еда", "eat"),
        ABILITY(NamedTextColor.AQUA, "Способность", "ability"),
        ARMOR(NamedTextColor.DARK_RED, "Броня", "armor"),
        GUN(NamedTextColor.RED, "Оружие дальнего боя", "gun"),
        ITEM(NamedTextColor.WHITE, "Обычный предмет", "item"),
        SPECIAL_ITEM(NamedTextColor.RED, "Особый предмет", "special_item"),
        OTHER(NamedTextColor.LIGHT_PURPLE, "Прочее", "other");

        NamedTextColor color;
        String typeName;
        String namespace;

        public Component getName() {
            return Component.text(typeName, color);
        }
    }
}

package dev.okenote.items;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.FieldDefaults;

@Getter
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public enum JediItemComponent {

    CATEGORY("category", false, String.class),
    RARE("rare", false, String.class),
    UID("uid", true, Integer.class),
    LEVEL("level", false, Integer.class),
    OWNER("owner", true, String.class),
    DAMAGE("damage", false, Double.class),
    NODROP("nodrop", false, Boolean.class),
    FACTION("faction", false, String.class),
    MOB_KILLS("mob_kills", true, Integer.class),
    PLAYER_KILLS("player_kills", true, Integer.class),
    CRITICAL_DAMAGE("critical_damage", false, Double.class),
    CRITICAL_CHANCE("critical_chance", false, Double.class),;

    String namespace;
    boolean saveMetaData;
    Class<?> typeClass;
}

package dev.okenote.items;

import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;

public class JediItemManager {

    public void init() {
        JediItem jediItem = new JediItem();

        jediItem.applyJediItem(ItemStack.builder(Material.LADDER).build(), "test3", JediItem.Category.ITEM, JediItem.Rare.RARITY);
        jediItem.applyJediItem(ItemStack.builder(Material.LADDER).build(), "test4", JediItem.Category.ITEM, JediItem.Rare.RARITY)
                .level(1).build();

        // Пример сохранения предмета в строку
        ItemStack itemStack = jediItem.getServerItems().get("test4");
        String itemData = jediItem.itemStackToString(itemStack);
        System.out.println("Item data: " + itemData);

        // Пример восстановления предмета из строки
        ItemStack restoredItem = jediItem.convertStringFromItemStack(itemData);
        System.out.println("Restored item: " + restoredItem);
    }
}