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; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; 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 static me.youhavetrouble.enchantio.EnchantioConfig.ENCHANTS; @SuppressWarnings("UnstableApiUsage") public class VolleyEnchant implements EnchantioEnchant { public static final Key KEY = Key.key("enchantio:volley"); private final int anvilCost, weight, maxLevel, additionalArrowsPerLevel; private final EnchantmentRegistryEntry.EnchantmentCost minimumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; private final Set> supportedItemTags; private final Set> enchantTagKeys = new HashSet<>(); private final Set activeSlots = new HashSet<>(); private final double spread; public VolleyEnchant( int anvilCost, int weight, EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, Set> supportedItemTags, Set activeSlots, int maxLevel, int additionalArrowsPerLevel, double spread ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; this.supportedItemTags = supportedItemTags; this.maxLevel = maxLevel; this.activeSlots.addAll(activeSlots); this.additionalArrowsPerLevel = additionalArrowsPerLevel; this.spread = spread; if (canGetFromEnchantingTable) { enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); } } @Override public @NotNull Key getKey() { return KEY; } @Override public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.volley","Volley"); } @Override public int getAnvilCost() { return anvilCost; } @Override public int getMaxLevel() { return maxLevel; } public int getAdditionalArrowsPerLevel() { return additionalArrowsPerLevel; } public double getSpread() { return spread; } @Override public int getWeight() { return weight; } @Override public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override public @NotNull Iterable getActiveSlots() { return activeSlots; } @Override public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } public static VolleyEnchant create(ConfigurationSection configurationSection) { VolleyEnchant executionerEnchant = new VolleyEnchant( EnchantioConfig.getInt(configurationSection, "anvilCost", 1), EnchantioConfig.getInt(configurationSection, "weight", 10), EnchantmentRegistryEntry.EnchantmentCost.of( EnchantioConfig.getInt(configurationSection, "minimumCost.base", 40), EnchantioConfig.getInt(configurationSection, "minimumCost.additionalPerLevel", 3) ), EnchantmentRegistryEntry.EnchantmentCost.of( EnchantioConfig.getInt(configurationSection, "maximumCost.base", 65), EnchantioConfig.getInt(configurationSection, "maximumCost.additionalPerLevel", 1) ), EnchantioConfig.getBoolean(configurationSection, "canGetFromEnchantingTable", true), EnchantioConfig.getTagsFromList(EnchantioConfig.getStringList( configurationSection, "supportedItemTags", List.of( "minecraft:bow" ) )), EnchantioConfig.getEquipmentSlotGroups(EnchantioConfig.getStringList( configurationSection, "activeSlots", List.of( "MAINHAND" ) )), EnchantioConfig.getInt(configurationSection, "maxLevel", 3), EnchantioConfig.getInt(configurationSection, "additionalArrowsPerLevel", 1), EnchantioConfig.getDouble(configurationSection, "spread", 0.5) ); if (EnchantioConfig.getBoolean(configurationSection, "enabled", true)) { ENCHANTS.put(VolleyEnchant.KEY, executionerEnchant); } return executionerEnchant; } }