From 536c07443927f7a7c4c06f049fdf635140d6379e Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Wed, 30 Oct 2024 16:19:48 +0100 Subject: [PATCH] add ability to configure active slots for the enchant --- .../enchantio/EnchantioConfig.java | 52 ++++++++++++++++++- .../enchantio/enchants/AirbagEnchant.java | 20 ++++--- .../enchantio/enchants/BeheadingEnchant.java | 23 ++++---- .../enchantio/enchants/EnchantioEnchant.java | 10 ++++ .../enchants/ExecutionerEnchant.java | 21 ++++---- .../enchantio/enchants/PanicEnchant.java | 20 ++++--- .../enchantio/enchants/ReplantingEnchant.java | 17 +++--- .../enchantio/enchants/SmeltingEnchant.java | 17 +++--- .../enchantio/enchants/SoulboundEnchant.java | 15 +++--- .../enchantio/enchants/TelepathyEnchant.java | 22 ++++---- 10 files changed, 149 insertions(+), 68 deletions(-) diff --git a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java index 5924c35..f13a37f 100644 --- a/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java +++ b/src/main/java/me/youhavetrouble/enchantio/EnchantioConfig.java @@ -11,7 +11,9 @@ 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.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemType; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -98,6 +100,13 @@ public class EnchantioConfig { List.of( "#minecraft:enchantable/mining" ) + )), + getEquipmentSlotGroups(getStringList( + telepathySection, + "activeSlots", + List.of( + "MAINHAND" + ) )) ); @@ -159,6 +168,13 @@ public class EnchantioConfig { "#minecraft:enchantable/weapon" ) )), + getEquipmentSlotGroups(getStringList( + executionerSection, + "activeSlots", + List.of( + "MAINHAND" + ) + )), getInt(executionerSection, "maxLevel", 5), getDouble(executionerSection, "damageMultiplierPerLevel", 0.05), getDouble(executionerSection, "maxDamageHpThreshold", 0.25) @@ -192,6 +208,13 @@ public class EnchantioConfig { "#minecraft:axes" ) )), + getEquipmentSlotGroups(getStringList( + beheadingSection, + "activeSlots", + List.of( + "MAINHAND" + ) + )), getInt(beheadingSection, "maxLevel", 5), getDouble(beheadingSection, "chanceToDropHeadPerLevel", 0.02) ); @@ -254,6 +277,13 @@ public class EnchantioConfig { "minecraft:elytra" ) )), + getEquipmentSlotGroups(getStringList( + airbagSection, + "activeSlots", + List.of( + "CHEST" + ) + )), getInt(airbagSection, "maxLevel", 4), getDouble(airbagSection, "damageReductionPerLevel", 0.2) ); @@ -291,6 +321,13 @@ public class EnchantioConfig { "#minecraft:enchantable/armor" ) )), + getEquipmentSlotGroups(getStringList( + panicSection, + "activeSlots", + List.of( + "ARMOR" + ) + )), getInt(panicSection, "maxLevel", 1), getDouble(panicSection, "panicChancePerLevel", 0.025) ); @@ -338,7 +375,20 @@ public class EnchantioConfig { return true; } - private Set> getTagsFromList(List tags) { + private Set getEquipmentSlotGroups(@NotNull List slots) { + Set equipmentSlotGroups = new HashSet<>(); + for (String slot : slots) { + try { + EquipmentSlotGroup equipmentSlotGroup = EquipmentSlotGroup.getByName(slot.toUpperCase(Locale.ENGLISH)); + equipmentSlotGroups.add(equipmentSlotGroup); + } catch (IllegalArgumentException e) { + logger.warning(slot + " is not a valid equipment slot group"); + } + } + return equipmentSlotGroups; + } + + private Set> getTagsFromList(@NotNull List tags) { Set> supportedItemTags = new HashSet<>(); for (String itemTag : tags) { if (itemTag == null) continue; diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java index f4a36d8..1ef4225 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/AirbagEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -24,6 +25,7 @@ public class AirbagEnchant implements EnchantioEnchant { private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; private final Set> supportedItemTags; private final Set> enchantTagKeys = new HashSet<>(); + private final Set activeSlots = new HashSet<>(); private final double damageReductionPerLevel; public AirbagEnchant( @@ -33,6 +35,7 @@ public class AirbagEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, Set> supportedItemTags, + Set activeSlots, int maxLevel, double damageReductionPerLevel ) { @@ -43,18 +46,19 @@ public class AirbagEnchant implements EnchantioEnchant { this.maximumCost = maximumCost; this.supportedItemTags = supportedItemTags; this.damageReductionPerLevel = damageReductionPerLevel; + this.activeSlots.addAll(activeSlots); if (canGetFromEnchantingTable) { enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); } } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.airbag", "Airbag"); } @@ -74,27 +78,27 @@ public class AirbagEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.ARMOR); + public @NotNull Iterable getActiveSlots() { + return activeSlots; } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java index 9cb5b1b..22e3b0b 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/BeheadingEnchant.java @@ -10,6 +10,7 @@ import net.kyori.adventure.text.Component; 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; @@ -26,6 +27,7 @@ public class BeheadingEnchant implements EnchantioEnchant { private final Set> supportedItemTags; private final double chanceToDropHeadPerLevel; private final Set> enchantTagKeys = new HashSet<>(); + private final Set activeSlots = new HashSet<>(); public BeheadingEnchant( int anvilCost, @@ -34,6 +36,7 @@ public class BeheadingEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, Set> supportedItemTags, + Set activeSlots, int maxLevel, double chanceToDropHeadPerLevel ) { @@ -44,19 +47,19 @@ public class BeheadingEnchant implements EnchantioEnchant { this.supportedItemTags = supportedItemTags; this.maxLevel = maxLevel; this.chanceToDropHeadPerLevel = chanceToDropHeadPerLevel; - + this.activeSlots.addAll(activeSlots); if (canGetFromEnchantingTable) { enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); } } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.beheading", "Beheading"); } @@ -80,32 +83,32 @@ public class BeheadingEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.ANY); + public @NotNull Iterable getActiveSlots() { + return activeSlots; } @Override - public TagKey getTagForSupportedItems() { + public @NotNull TagKey getTagForSupportedItems() { return TagKey.create(RegistryKey.ITEM, Key.key("enchantio:beheading_enchantable")); } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/EnchantioEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/EnchantioEnchant.java index d2c4e0c..d5a879d 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/EnchantioEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/EnchantioEnchant.java @@ -10,14 +10,17 @@ import net.kyori.adventure.text.Component; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemType; +import org.jetbrains.annotations.NotNull; import java.util.Set; @SuppressWarnings("UnstableApiUsage") public interface EnchantioEnchant { + @NotNull Key getKey(); + @NotNull Component getDescription(); int getAnvilCost(); @@ -26,20 +29,27 @@ public interface EnchantioEnchant { int getWeight(); + @NotNull EnchantmentRegistryEntry.EnchantmentCost getMinimumCost(); + @NotNull EnchantmentRegistryEntry.EnchantmentCost getMaximumCost(); + @NotNull Iterable getActiveSlots(); + @NotNull Set> getSupportedItems(); + @NotNull Set> getEnchantTagKeys(); + @NotNull default TagKey getTagForSupportedItems() { return TagKey.create(RegistryKey.ITEM, Key.key( getKey().asString() + "_enchantable")); } + @NotNull default TagEntry getTagEntry() { return TagEntry.valueEntry(TypedKey.create(RegistryKey.ENCHANTMENT, getKey())); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java index 405aa35..c81e638 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/ExecutionerEnchant.java @@ -1,6 +1,5 @@ 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; @@ -10,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -26,6 +26,7 @@ public class ExecutionerEnchant implements EnchantioEnchant { private final Set> supportedItemTags; private final double damageMultiplierPerLevel, maxDamageHpThreshold; private final Set> enchantTagKeys = new HashSet<>(); + private final Set activeSlots = new HashSet<>(); public ExecutionerEnchant( @@ -35,6 +36,7 @@ public class ExecutionerEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, Set> supportedItemTags, + Set activeSlots, int maxLevel, double damageMultiplierPerLevel, double maxDamageHpThreshold @@ -45,6 +47,7 @@ public class ExecutionerEnchant implements EnchantioEnchant { this.maximumCost = maximumCost; this.supportedItemTags = supportedItemTags; this.maxLevel = maxLevel; + this.activeSlots.addAll(activeSlots); this.damageMultiplierPerLevel = damageMultiplierPerLevel; this.maxDamageHpThreshold = maxDamageHpThreshold; if (canGetFromEnchantingTable) { @@ -53,12 +56,12 @@ public class ExecutionerEnchant implements EnchantioEnchant { } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.executioner","Executioner"); } @@ -86,27 +89,27 @@ public class ExecutionerEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.HAND); + public @NotNull Iterable getActiveSlots() { + return activeSlots; } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java index ac4ab30..f059e29 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/PanicEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -25,6 +26,7 @@ public class PanicEnchant implements EnchantioEnchant { private final double panicChancePerLevel; private final Set> supportedItemTags; private final Set> enchantTagKeys = new HashSet<>(); + private final Set activeSlots = new HashSet<>(); public PanicEnchant( int anvilCost, @@ -33,6 +35,7 @@ public class PanicEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, Set> supportedItemTags, + Set activeSlots, int maxLevel, double panicChancePerLevel ) { @@ -43,6 +46,7 @@ public class PanicEnchant implements EnchantioEnchant { this.maximumCost = maximumCost; this.supportedItemTags = supportedItemTags; this.panicChancePerLevel = panicChancePerLevel; + this.activeSlots.addAll(activeSlots); if (canGetFromEnchantingTable) { enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); } @@ -50,12 +54,12 @@ public class PanicEnchant implements EnchantioEnchant { } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.panic_curse", "Curse of Panic"); } @@ -75,27 +79,27 @@ public class PanicEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.ARMOR); + public @NotNull Iterable getActiveSlots() { + return activeSlots; } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java index d2e8da8..b344679 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/ReplantingEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -44,12 +45,12 @@ public class ReplantingEnchant implements EnchantioEnchant { } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.replanting", "Replanting"); } @@ -69,27 +70,27 @@ public class ReplantingEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.HAND); + public @NotNull Iterable getActiveSlots() { + return Set.of(EquipmentSlotGroup.MAINHAND); } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java index 00be93c..6934dd9 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/SmeltingEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -44,12 +45,12 @@ public class SmeltingEnchant implements EnchantioEnchant { } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.smelting", "Smelting"); } @@ -69,27 +70,27 @@ public class SmeltingEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.ANY); + public @NotNull Iterable getActiveSlots() { + return Set.of(EquipmentSlotGroup.MAINHAND); } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java index 66db140..f0f9a5b 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/SoulboundEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -44,12 +45,12 @@ public class SoulboundEnchant implements EnchantioEnchant { } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.soulbound", "Soulbound"); } @@ -69,27 +70,27 @@ public class SoulboundEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { + public @NotNull Iterable getActiveSlots() { return Set.of(EquipmentSlotGroup.ANY); } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); } diff --git a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java index c6ad886..09f99d2 100644 --- a/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java +++ b/src/main/java/me/youhavetrouble/enchantio/enchants/TelepathyEnchant.java @@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component; 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; @@ -24,6 +25,7 @@ public class TelepathyEnchant implements EnchantioEnchant { private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; private final Set> supportedItemTags; private final Set> enchantTagKeys = new HashSet<>(); + private final Set activeSlots = new HashSet<>(); public TelepathyEnchant( int anvilCost, @@ -31,25 +33,27 @@ public class TelepathyEnchant implements EnchantioEnchant { EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost, boolean canGetFromEnchantingTable, - Set> supportedItemTags + Set> supportedItemTags, + Set activeSlots ) { this.anvilCost = anvilCost; this.weight = weight; this.minimumCost = minimumCost; this.maximumCost = maximumCost; this.supportedItemTags = supportedItemTags; + this.activeSlots.addAll(activeSlots); if (canGetFromEnchantingTable) { enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); } } @Override - public Key getKey() { + public @NotNull Key getKey() { return KEY; } @Override - public Component getDescription() { + public @NotNull Component getDescription() { return Component.translatable("enchantio.enchant.telepathy","Telepathy"); } @@ -69,27 +73,27 @@ public class TelepathyEnchant implements EnchantioEnchant { } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() { return minimumCost; } @Override - public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { + public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() { return maximumCost; } @Override - public Iterable getActiveSlots() { - return Set.of(EquipmentSlotGroup.HAND); + public @NotNull Iterable getActiveSlots() { + return activeSlots; } @Override - public Set> getSupportedItems() { + public @NotNull Set> getSupportedItems() { return supportedItemTags; } @Override - public Set> getEnchantTagKeys() { + public @NotNull Set> getEnchantTagKeys() { return Collections.unmodifiableSet(enchantTagKeys); }