From ef16d1cb28b4310b6e9328484d18ca4637fee3cc Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Fri, 16 May 2025 19:22:10 +0200 Subject: [PATCH] refactor to allow adding enchantment tags freely --- .../enchantio/EnchantioConfig.java | 41 ++++++++++++++++++- .../enchantio/enchants/AirbagEnchant.java | 28 ++++++------- .../enchantio/enchants/BeheadingEnchant.java | 28 ++++++------- .../enchantio/enchants/CloakingEnchant.java | 28 ++++++------- .../enchants/ExecutionerEnchant.java | 28 ++++++------- .../enchantio/enchants/HomecomingEnchant.java | 26 ++++++------ .../enchantio/enchants/InsomniaEnchant.java | 29 ++++++------- .../enchantio/enchants/PanicEnchant.java | 29 ++++++------- .../enchantio/enchants/ReplantingEnchant.java | 26 ++++++------ .../enchantio/enchants/SmeltingEnchant.java | 26 ++++++------ .../enchantio/enchants/SoulboundEnchant.java | 26 ++++++------ .../enchantio/enchants/TelepathyEnchant.java | 28 ++++++------- .../enchantio/enchants/VampirismEnchant.java | 29 ++++++------- .../enchantio/enchants/VolleyEnchant.java | 28 ++++++------- .../enchantio/enchants/WardEnchant.java | 28 ++++++------- 15 files changed, 218 insertions(+), 210 deletions(-) diff --git a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java index 5cd7e92..391c819 100644 --- a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java +++ b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java @@ -2,6 +2,7 @@ package me.youhavetrouble.enchantio; import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys; import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; import io.papermc.paper.registry.tag.TagKey; import io.papermc.paper.tag.TagEntry; @@ -10,6 +11,7 @@ import net.kyori.adventure.key.Key; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemType; import org.jetbrains.annotations.NotNull; @@ -41,6 +43,7 @@ public class EnchantioConfig { FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); ConfigurationSection enchantsSection = getConfigSection(configuration, "enchants"); + migrateEnchantTags(enchantsSection); ConfigurationSection soulboundSection = getConfigSection(enchantsSection, "soulbound"); SoulboundEnchant.create(soulboundSection); @@ -76,6 +79,7 @@ public class EnchantioConfig { WardEnchant.create(wardSection); ConfigurationSection cursesSection = getConfigSection(configuration, "curses"); + migrateEnchantTags(cursesSection); ConfigurationSection panicSection = getConfigSection(cursesSection, "panic"); PanicEnchant.create(panicSection); @@ -134,6 +138,16 @@ public class EnchantioConfig { return true; } + public static void migrateEnchantTags(@NotNull ConfigurationSection section) { + for (String sectionKey : section.getKeys(false)) { + ConfigurationSection enchantSection = section.getConfigurationSection(sectionKey); + if (enchantSection == null) continue; + if (!enchantSection.isSet("canGetFromEnchantingTable") || enchantSection.isSet("enchantmentTags")) return; + boolean canGetFromEnchantingTable = section.getBoolean("canGetFromEnchantingTable", true); + section.set("enchantmentTags", canGetFromEnchantingTable ? List.of("#in_enchanting_table") : List.of()); + } + } + public static Set getEquipmentSlotGroups(@NotNull List slots) { Set equipmentSlotGroups = new HashSet<>(); for (String slot : slots) { @@ -146,7 +160,7 @@ public class EnchantioConfig { return equipmentSlotGroups; } - public static Set> getTagsFromList(@NotNull List tags) { + public static Set> getItemTagEntriesFromList(@NotNull List tags) { Set> supportedItemTags = new HashSet<>(); for (String itemTag : tags) { if (itemTag == null) continue; @@ -172,6 +186,31 @@ public class EnchantioConfig { return supportedItemTags; } + public static Set> getEnchantmentTagKeysFromList(@NotNull List tags) { + Set> enchantTagKeys = new HashSet<>(); + for (String enchantmentTag : tags) { + if (enchantmentTag == null) continue; + if (enchantmentTag.startsWith("#")) { + enchantmentTag = enchantmentTag.substring(1); + try { + Key key = Key.key(enchantmentTag); + TagKey tagKey = EnchantmentTagKeys.create(key); + enchantTagKeys.add(tagKey); + } catch (IllegalArgumentException ignored) { + } + continue; + } + try { + Key key = Key.key(enchantmentTag); + TypedKey typedKey = TypedKey.create(RegistryKey.ENCHANTMENT, key); + TagKey tagKey = EnchantmentTagKeys.create(key); + enchantTagKeys.add(tagKey); + } catch (IllegalArgumentException | NullPointerException ignored) { + } + } + return enchantTagKeys; + } + public static ConfigurationSection getConfigSection(ConfigurationSection section, String key) { ConfigurationSection value = section.getConfigurationSection(key); if (value == null) { diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java index 7a688ea..92e9610 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java @@ -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.*; @SuppressWarnings("UnstableApiUsage") public class AirbagEnchant implements EnchantioEnchant { @@ -26,7 +22,7 @@ public class AirbagEnchant implements EnchantioEnchant { private final int anvilCost, weight, maxLevel; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); private final double damageReductionPerLevel; @@ -36,9 +32,9 @@ public class AirbagEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int maxLevel, double damageReductionPerLevel ) { @@ -47,12 +43,10 @@ public class AirbagEnchant implements EnchantioEnchant { this.maxLevel = maxLevel; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.damageReductionPerLevel = damageReductionPerLevel; this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -121,8 +115,12 @@ public class AirbagEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java index a8779b8..5eb350c 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java @@ -2,7 +2,6 @@ package me.youhavetrouble.enchantio.enchants; import io.papermc.paper.registry.RegistryKey; 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; @@ -14,10 +13,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 BeheadingEnchant implements EnchantioEnchant { private final int anvilCost, weight, maxLevel; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final double chanceToDropHeadPerLevel; private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -39,9 +35,9 @@ public class BeheadingEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int maxLevel, double chanceToDropHeadPerLevel ) { @@ -49,13 +45,11 @@ public class BeheadingEnchant implements EnchantioEnchant { this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.maxLevel = maxLevel; this.chanceToDropHeadPerLevel = chanceToDropHeadPerLevel; this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -129,8 +123,12 @@ public class BeheadingEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1) ), - configurationSection.getBoolean("canGetFromEnchantingTable", true), - EnchantioConfig.getTagsFromList(EnchantioConfig.getStringList( + EnchantioConfig.getEnchantmentTagKeysFromList(EnchantioConfig.getStringList( + configurationSection, + "enchantmentTags", + List.of("#in_enchanting_table") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/CloakingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/CloakingEnchant.java index 3f35f78..2add851 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/CloakingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/CloakingEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class CloakingEnchant implements EnchantioEnchant { private final int anvilCost, weight, ticksToActivate; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -37,21 +33,19 @@ public class CloakingEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int ticksToActivate ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.ticksToActivate = ticksToActivate; this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -120,8 +114,12 @@ public class CloakingEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java index fe17cb7..d0fee33 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class ExecutionerEnchant implements EnchantioEnchant { private final int anvilCost, weight, maxLevel; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final double damageMultiplierPerLevel, maxDamageHpThreshold; private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -39,9 +35,9 @@ public class ExecutionerEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int maxLevel, double damageMultiplierPerLevel, double maxDamageHpThreshold @@ -50,14 +46,12 @@ public class ExecutionerEnchant implements EnchantioEnchant { this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.maxLevel = maxLevel; this.activeSlots.addAll(activeSlots); this.damageMultiplierPerLevel = damageMultiplierPerLevel; this.maxDamageHpThreshold = maxDamageHpThreshold; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -130,8 +124,12 @@ public class ExecutionerEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/HomecomingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/HomecomingEnchant.java index 67dc0a2..41dbf95 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/HomecomingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/HomecomingEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class HomecomingEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); public HomecomingEnchant( @@ -36,17 +32,15 @@ public class HomecomingEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags + Collection> enchantTagKeys, + Collection> supportedItemTags ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.supportedItemTags.addAll(supportedItemTags); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -111,8 +105,12 @@ public class HomecomingEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/InsomniaEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/InsomniaEnchant.java index 6396eac..719509e 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/InsomniaEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/InsomniaEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class InsomniaEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -37,20 +33,17 @@ public class InsomniaEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } - enchantTagKeys.add(EnchantmentTagKeys.CURSE); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -115,8 +108,12 @@ public class InsomniaEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 30), 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( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java index 0251ec8..ade8e6d 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java @@ -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> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -38,9 +34,9 @@ public class PanicEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection 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( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java index 37db438..a422808 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class ReplantingEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); public ReplantingEnchant( @@ -36,17 +32,15 @@ public class ReplantingEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags + Collection> enchantTagKeys, + Collection> supportedItemTags ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.supportedItemTags.addAll(supportedItemTags); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -111,8 +105,12 @@ public class ReplantingEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java index 000f578..5c02e5d 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class SmeltingEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); public SmeltingEnchant( @@ -36,17 +32,15 @@ public class SmeltingEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags + Collection> enchantTagKeys, + Collection> supportedItemTags ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.supportedItemTags.addAll(supportedItemTags); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -111,8 +105,12 @@ public class SmeltingEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java index b446c79..c803429 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class SoulboundEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); public SoulboundEnchant( @@ -36,17 +32,15 @@ public class SoulboundEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags + Collection> enchantTagKeys, + Collection> supportedItemTags ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.supportedItemTags.addAll(supportedItemTags); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -111,8 +105,12 @@ public class SoulboundEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java index 2b54e67..e02cb2d 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class TelepathyEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -37,19 +33,17 @@ public class TelepathyEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -114,8 +108,12 @@ public class TelepathyEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/VampirismEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/VampirismEnchant.java index 6e41e66..693009e 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/VampirismEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/VampirismEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class VampirismEnchant implements EnchantioEnchant { private final int anvilCost, weight; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); @@ -37,20 +33,17 @@ public class VampirismEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.activeSlots.addAll(activeSlots); - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } - enchantTagKeys.add(EnchantmentTagKeys.CURSE); + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -115,8 +108,12 @@ public class VampirismEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 30), 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( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/VolleyEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/VolleyEnchant.java index 2871324..bddab51 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/VolleyEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/VolleyEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class VolleyEnchant implements EnchantioEnchant { private final int anvilCost, weight, maxLevel, additionalArrowsPerLevel; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); private final double spread; @@ -38,9 +34,9 @@ public class VolleyEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int maxLevel, int additionalArrowsPerLevel, double spread @@ -49,14 +45,12 @@ public class VolleyEnchant implements EnchantioEnchant { this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.maxLevel = maxLevel; this.activeSlots.addAll(activeSlots); this.additionalArrowsPerLevel = additionalArrowsPerLevel; this.spread = spread; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -129,8 +123,12 @@ public class VolleyEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/WardEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/WardEnchant.java index 0938a3d..b8f1e5e 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/WardEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/WardEnchant.java @@ -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; @@ -28,7 +24,7 @@ public class WardEnchant implements EnchantioEnchant { private final int anvilCost, weight, cooldownTicks; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; - private final Set> supportedItemTags; + private final Set> supportedItemTags = new HashSet<>(); private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); private final String blockSound; @@ -38,9 +34,9 @@ public class WardEnchant implements EnchantioEnchant { int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, - boolean canGetFromEnchantingTable, - Set> supportedItemTags, - Set activeSlots, + Collection> enchantTagKeys, + Collection> supportedItemTags, + Collection activeSlots, int cooldownTicks, String blockSound ) { @@ -48,13 +44,11 @@ public class WardEnchant implements EnchantioEnchant { this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; - this.supportedItemTags = supportedItemTags; + this.supportedItemTags.addAll(supportedItemTags); this.activeSlots.addAll(activeSlots); this.cooldownTicks = cooldownTicks; this.blockSound = blockSound; - if (canGetFromEnchantingTable) { - enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); - } + this.enchantTagKeys.addAll(enchantTagKeys); } @Override @@ -127,8 +121,12 @@ public class WardEnchant implements EnchantioEnchant { EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), 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") + )), + EnchantioConfig.getItemTagEntriesFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of(