mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-12 06:06:55 +00:00
make enchants accessible by their key at any point after bootstrap
This commit is contained in:
@@ -14,6 +14,7 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -32,7 +33,7 @@ public class EnchantioBootstrap implements PluginBootstrap {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<EnchantioEnchant> enchantioEnchants = config.enchants;
|
Collection<EnchantioEnchant> enchantioEnchants = EnchantioConfig.ENCHANTS.values();
|
||||||
|
|
||||||
logger.info("Registering supported item tags");
|
logger.info("Registering supported item tags");
|
||||||
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> {
|
context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM).newHandler((event) -> {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
|
|||||||
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
|
||||||
import io.papermc.paper.registry.tag.TagKey;
|
import io.papermc.paper.registry.tag.TagKey;
|
||||||
import io.papermc.paper.tag.TagEntry;
|
import io.papermc.paper.tag.TagEntry;
|
||||||
import me.youhavetrouble.enchantio.enchants.EnchantioEnchant;
|
import me.youhavetrouble.enchantio.enchants.*;
|
||||||
import me.youhavetrouble.enchantio.enchants.ReplantingEnchant;
|
|
||||||
import me.youhavetrouble.enchantio.enchants.SoulboundEnchant;
|
|
||||||
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@@ -19,15 +16,13 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class EnchantioConfig {
|
public class EnchantioConfig {
|
||||||
|
|
||||||
public final Set<EnchantioEnchant> enchants = new HashSet<>();
|
public static final Map<Key, EnchantioEnchant> ENCHANTS = new HashMap<>();
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
protected EnchantioConfig(Path filePath, Logger logger) throws IOException {
|
protected EnchantioConfig(Path filePath, Logger logger) throws IOException {
|
||||||
@@ -67,7 +62,7 @@ public class EnchantioConfig {
|
|||||||
if (soulboundSection == null) {
|
if (soulboundSection == null) {
|
||||||
soulboundSection = enchantsSection.createSection("soulbound");
|
soulboundSection = enchantsSection.createSection("soulbound");
|
||||||
}
|
}
|
||||||
enchants.add(new SoulboundEnchant(
|
ENCHANTS.put(SoulboundEnchant.KEY, new SoulboundEnchant(
|
||||||
soulboundSection.getInt("anvilCost", 1),
|
soulboundSection.getInt("anvilCost", 1),
|
||||||
soulboundSection.getInt("weight", 10),
|
soulboundSection.getInt("weight", 10),
|
||||||
EnchantmentRegistryEntry.EnchantmentCost.of(
|
EnchantmentRegistryEntry.EnchantmentCost.of(
|
||||||
@@ -94,7 +89,7 @@ public class EnchantioConfig {
|
|||||||
if (telepathySection == null) {
|
if (telepathySection == null) {
|
||||||
telepathySection = enchantsSection.createSection("telepathy");
|
telepathySection = enchantsSection.createSection("telepathy");
|
||||||
}
|
}
|
||||||
enchants.add(new TelepathyEnchant(
|
ENCHANTS.put(TelepathyEnchant.KEY, new TelepathyEnchant(
|
||||||
telepathySection.getInt("anvilCost", 1),
|
telepathySection.getInt("anvilCost", 1),
|
||||||
telepathySection.getInt("weight", 5),
|
telepathySection.getInt("weight", 5),
|
||||||
EnchantmentRegistryEntry.EnchantmentCost.of(
|
EnchantmentRegistryEntry.EnchantmentCost.of(
|
||||||
@@ -119,7 +114,7 @@ public class EnchantioConfig {
|
|||||||
if (replantingSection == null) {
|
if (replantingSection == null) {
|
||||||
replantingSection = enchantsSection.createSection("replanting");
|
replantingSection = enchantsSection.createSection("replanting");
|
||||||
}
|
}
|
||||||
enchants.add(new ReplantingEnchant(
|
ENCHANTS.put(ReplantingEnchant.KEY, new ReplantingEnchant(
|
||||||
replantingSection.getInt("anvilCost", 1),
|
replantingSection.getInt("anvilCost", 1),
|
||||||
replantingSection.getInt("weight", 10),
|
replantingSection.getInt("weight", 10),
|
||||||
EnchantmentRegistryEntry.EnchantmentCost.of(
|
EnchantmentRegistryEntry.EnchantmentCost.of(
|
||||||
|
|||||||
Reference in New Issue
Block a user