refactor to allow adding enchantment tags freely

This commit is contained in:
2025-05-16 19:22:10 +02:00
parent 6c64ab87c2
commit ef16d1cb28
15 changed files with 218 additions and 210 deletions
@@ -1,7 +1,6 @@
package me.youhavetrouble.enchantio.enchants;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
import io.papermc.paper.registry.tag.TagKey;
import io.papermc.paper.tag.TagEntry;
import me.youhavetrouble.enchantio.EnchantioConfig;
@@ -13,10 +12,7 @@ import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import static me.youhavetrouble.enchantio.EnchantioConfig.ENCHANTS;
@@ -29,7 +25,7 @@ public class PanicEnchant implements EnchantioEnchant {
private final EnchantmentRegistryEntry.EnchantmentCost minimumCost;
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
private final double panicChancePerLevel;
private final Set<TagEntry<ItemType>> supportedItemTags;
private final Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
@@ -38,9 +34,9 @@ public class PanicEnchant implements EnchantioEnchant {
int weight,
EnchantmentRegistryEntry.EnchantmentCost minimumCost,
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots,
Collection<TagKey<Enchantment>> enchantTagKeys,
Collection<TagEntry<ItemType>> supportedItemTags,
Collection<EquipmentSlotGroup> activeSlots,
int maxLevel,
double panicChancePerLevel
) {
@@ -49,13 +45,10 @@ public class PanicEnchant implements EnchantioEnchant {
this.maxLevel = maxLevel;
this.minimumCost = minimumCost;
this.maximumCost = maximumCost;
this.supportedItemTags = supportedItemTags;
this.supportedItemTags.addAll(supportedItemTags);
this.panicChancePerLevel = panicChancePerLevel;
this.activeSlots.addAll(activeSlots);
if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
}
enchantTagKeys.add(EnchantmentTagKeys.CURSE);
this.enchantTagKeys.addAll(enchantTagKeys);
}
@Override
@@ -124,8 +117,12 @@ public class PanicEnchant implements EnchantioEnchant {
EnchantioConfig.getInt(configurationSection, "maximumCost.base", 20),
EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1)
),
EnchantioConfig.getBoolean(configurationSection, "canGetFromEnchantingTable", true),
EnchantioConfig.getTagsFromList(EnchantioConfig.getStringList(
EnchantioConfig.getEnchantmentTagKeysFromList(EnchantioConfig.getStringList(
configurationSection,
"enchantmentTags",
List.of("#in_enchanting_table", "#curse")
)),
EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList(
configurationSection,
"supportedItemTags",
List.of(