From 6e8cdc7afb52abaa4bb2c8e8e230b3bed03bbeab Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Fri, 25 Oct 2024 13:35:01 +0200 Subject: [PATCH] make enchants accessible by their key at any point after bootstrap --- .../enchantio/EnchantioBootstrap.java | 3 ++- .../enchantio/EnchantioConfig.java | 17 ++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/youhavetrouble/enchantio/EnchantioBootstrap.java b/src/main/java/me/youhavetrouble/enchantio/EnchantioBootstrap.java index b7b7de8..eb3c5d5 100644 --- a/src/main/java/me/youhavetrouble/enchantio/EnchantioBootstrap.java +++ b/src/main/java/me/youhavetrouble/enchantio/EnchantioBootstrap.java @@ -14,6 +14,7 @@ import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import java.io.IOException; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.logging.Logger; @@ -32,7 +33,7 @@ public class EnchantioBootstrap implements PluginBootstrap { throw new RuntimeException(e); } - Set enchantioEnchants = config.enchants; + Collection enchantioEnchants = EnchantioConfig.ENCHANTS.values(); logger.info("Registering supported item tags"); context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> { diff --git a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java index d55e52a..65838a2 100644 --- a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java +++ b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java @@ -4,10 +4,7 @@ import io.papermc.paper.registry.data.EnchantmentRegistryEntry; import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; import io.papermc.paper.registry.tag.TagKey; import io.papermc.paper.tag.TagEntry; -import me.youhavetrouble.enchantio.enchants.EnchantioEnchant; -import me.youhavetrouble.enchantio.enchants.ReplantingEnchant; -import me.youhavetrouble.enchantio.enchants.SoulboundEnchant; -import me.youhavetrouble.enchantio.enchants.TelepathyEnchant; +import me.youhavetrouble.enchantio.enchants.*; import net.kyori.adventure.key.Key; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -19,15 +16,13 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.logging.Logger; @SuppressWarnings("UnstableApiUsage") public class EnchantioConfig { - public final Set enchants = new HashSet<>(); + public static final Map ENCHANTS = new HashMap<>(); private final Logger logger; protected EnchantioConfig(Path filePath, Logger logger) throws IOException { @@ -67,7 +62,7 @@ public class EnchantioConfig { if (soulboundSection == null) { soulboundSection = enchantsSection.createSection("soulbound"); } - enchants.add(new SoulboundEnchant( + ENCHANTS.put(SoulboundEnchant.KEY, new SoulboundEnchant( soulboundSection.getInt("anvilCost", 1), soulboundSection.getInt("weight", 10), EnchantmentRegistryEntry.EnchantmentCost.of( @@ -94,7 +89,7 @@ public class EnchantioConfig { if (telepathySection == null) { telepathySection = enchantsSection.createSection("telepathy"); } - enchants.add(new TelepathyEnchant( + ENCHANTS.put(TelepathyEnchant.KEY, new TelepathyEnchant( telepathySection.getInt("anvilCost", 1), telepathySection.getInt("weight", 5), EnchantmentRegistryEntry.EnchantmentCost.of( @@ -119,7 +114,7 @@ public class EnchantioConfig { if (replantingSection == null) { replantingSection = enchantsSection.createSection("replanting"); } - enchants.add(new ReplantingEnchant( + ENCHANTS.put(ReplantingEnchant.KEY, new ReplantingEnchant( replantingSection.getInt("anvilCost", 1), replantingSection.getInt("weight", 10), EnchantmentRegistryEntry.EnchantmentCost.of(