add ability to configure active slots for the enchant

This commit is contained in:
2024-10-30 16:19:48 +01:00
parent 5ff3821cb3
commit 536c074439
10 changed files with 149 additions and 68 deletions
@@ -11,7 +11,9 @@ 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;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -98,6 +100,13 @@ public class EnchantioConfig {
List.of( List.of(
"#minecraft:enchantable/mining" "#minecraft:enchantable/mining"
) )
)),
getEquipmentSlotGroups(getStringList(
telepathySection,
"activeSlots",
List.of(
"MAINHAND"
)
)) ))
); );
@@ -159,6 +168,13 @@ public class EnchantioConfig {
"#minecraft:enchantable/weapon" "#minecraft:enchantable/weapon"
) )
)), )),
getEquipmentSlotGroups(getStringList(
executionerSection,
"activeSlots",
List.of(
"MAINHAND"
)
)),
getInt(executionerSection, "maxLevel", 5), getInt(executionerSection, "maxLevel", 5),
getDouble(executionerSection, "damageMultiplierPerLevel", 0.05), getDouble(executionerSection, "damageMultiplierPerLevel", 0.05),
getDouble(executionerSection, "maxDamageHpThreshold", 0.25) getDouble(executionerSection, "maxDamageHpThreshold", 0.25)
@@ -192,6 +208,13 @@ public class EnchantioConfig {
"#minecraft:axes" "#minecraft:axes"
) )
)), )),
getEquipmentSlotGroups(getStringList(
beheadingSection,
"activeSlots",
List.of(
"MAINHAND"
)
)),
getInt(beheadingSection, "maxLevel", 5), getInt(beheadingSection, "maxLevel", 5),
getDouble(beheadingSection, "chanceToDropHeadPerLevel", 0.02) getDouble(beheadingSection, "chanceToDropHeadPerLevel", 0.02)
); );
@@ -254,6 +277,13 @@ public class EnchantioConfig {
"minecraft:elytra" "minecraft:elytra"
) )
)), )),
getEquipmentSlotGroups(getStringList(
airbagSection,
"activeSlots",
List.of(
"CHEST"
)
)),
getInt(airbagSection, "maxLevel", 4), getInt(airbagSection, "maxLevel", 4),
getDouble(airbagSection, "damageReductionPerLevel", 0.2) getDouble(airbagSection, "damageReductionPerLevel", 0.2)
); );
@@ -291,6 +321,13 @@ public class EnchantioConfig {
"#minecraft:enchantable/armor" "#minecraft:enchantable/armor"
) )
)), )),
getEquipmentSlotGroups(getStringList(
panicSection,
"activeSlots",
List.of(
"ARMOR"
)
)),
getInt(panicSection, "maxLevel", 1), getInt(panicSection, "maxLevel", 1),
getDouble(panicSection, "panicChancePerLevel", 0.025) getDouble(panicSection, "panicChancePerLevel", 0.025)
); );
@@ -338,7 +375,20 @@ public class EnchantioConfig {
return true; return true;
} }
private Set<TagEntry<ItemType>> getTagsFromList(List<String> tags) { private Set<EquipmentSlotGroup> getEquipmentSlotGroups(@NotNull List<String> slots) {
Set<EquipmentSlotGroup> 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<TagEntry<ItemType>> getTagsFromList(@NotNull List<String> tags) {
Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>(); Set<TagEntry<ItemType>> supportedItemTags = new HashSet<>();
for (String itemTag : tags) { for (String itemTag : tags) {
if (itemTag == null) continue; if (itemTag == null) continue;
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -24,6 +25,7 @@ public class AirbagEnchant implements EnchantioEnchant {
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
private final Set<TagEntry<ItemType>> supportedItemTags; private final Set<TagEntry<ItemType>> supportedItemTags;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>(); private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
private final double damageReductionPerLevel; private final double damageReductionPerLevel;
public AirbagEnchant( public AirbagEnchant(
@@ -33,6 +35,7 @@ public class AirbagEnchant implements EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost maximumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable, boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags, Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots,
int maxLevel, int maxLevel,
double damageReductionPerLevel double damageReductionPerLevel
) { ) {
@@ -43,18 +46,19 @@ public class AirbagEnchant implements EnchantioEnchant {
this.maximumCost = maximumCost; this.maximumCost = maximumCost;
this.supportedItemTags = supportedItemTags; this.supportedItemTags = supportedItemTags;
this.damageReductionPerLevel = damageReductionPerLevel; this.damageReductionPerLevel = damageReductionPerLevel;
this.activeSlots.addAll(activeSlots);
if (canGetFromEnchantingTable) { if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
} }
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.airbag", "Airbag"); return Component.translatable("enchantio.enchant.airbag", "Airbag");
} }
@@ -74,27 +78,27 @@ public class AirbagEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.ARMOR); return activeSlots;
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -10,6 +10,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -26,6 +27,7 @@ public class BeheadingEnchant implements EnchantioEnchant {
private final Set<TagEntry<ItemType>> supportedItemTags; private final Set<TagEntry<ItemType>> supportedItemTags;
private final double chanceToDropHeadPerLevel; private final double chanceToDropHeadPerLevel;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>(); private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
public BeheadingEnchant( public BeheadingEnchant(
int anvilCost, int anvilCost,
@@ -34,6 +36,7 @@ public class BeheadingEnchant implements EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost maximumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable, boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags, Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots,
int maxLevel, int maxLevel,
double chanceToDropHeadPerLevel double chanceToDropHeadPerLevel
) { ) {
@@ -44,19 +47,19 @@ public class BeheadingEnchant implements EnchantioEnchant {
this.supportedItemTags = supportedItemTags; this.supportedItemTags = supportedItemTags;
this.maxLevel = maxLevel; this.maxLevel = maxLevel;
this.chanceToDropHeadPerLevel = chanceToDropHeadPerLevel; this.chanceToDropHeadPerLevel = chanceToDropHeadPerLevel;
this.activeSlots.addAll(activeSlots);
if (canGetFromEnchantingTable) { if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
} }
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.beheading", "Beheading"); return Component.translatable("enchantio.enchant.beheading", "Beheading");
} }
@@ -80,32 +83,32 @@ public class BeheadingEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.ANY); return activeSlots;
} }
@Override @Override
public TagKey<ItemType> getTagForSupportedItems() { public @NotNull TagKey<ItemType> getTagForSupportedItems() {
return TagKey.create(RegistryKey.ITEM, Key.key("enchantio:beheading_enchantable")); return TagKey.create(RegistryKey.ITEM, Key.key("enchantio:beheading_enchantable"));
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -10,14 +10,17 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public interface EnchantioEnchant { public interface EnchantioEnchant {
@NotNull
Key getKey(); Key getKey();
@NotNull
Component getDescription(); Component getDescription();
int getAnvilCost(); int getAnvilCost();
@@ -26,20 +29,27 @@ public interface EnchantioEnchant {
int getWeight(); int getWeight();
@NotNull
EnchantmentRegistryEntry.EnchantmentCost getMinimumCost(); EnchantmentRegistryEntry.EnchantmentCost getMinimumCost();
@NotNull
EnchantmentRegistryEntry.EnchantmentCost getMaximumCost(); EnchantmentRegistryEntry.EnchantmentCost getMaximumCost();
@NotNull
Iterable<EquipmentSlotGroup> getActiveSlots(); Iterable<EquipmentSlotGroup> getActiveSlots();
@NotNull
Set<TagEntry<ItemType>> getSupportedItems(); Set<TagEntry<ItemType>> getSupportedItems();
@NotNull
Set<TagKey<Enchantment>> getEnchantTagKeys(); Set<TagKey<Enchantment>> getEnchantTagKeys();
@NotNull
default TagKey<ItemType> getTagForSupportedItems() { default TagKey<ItemType> getTagForSupportedItems() {
return TagKey.create(RegistryKey.ITEM, Key.key( getKey().asString() + "_enchantable")); return TagKey.create(RegistryKey.ITEM, Key.key( getKey().asString() + "_enchantable"));
} }
@NotNull
default TagEntry<Enchantment> getTagEntry() { default TagEntry<Enchantment> getTagEntry() {
return TagEntry.valueEntry(TypedKey.create(RegistryKey.ENCHANTMENT, getKey())); return TagEntry.valueEntry(TypedKey.create(RegistryKey.ENCHANTMENT, getKey()));
} }
@@ -1,6 +1,5 @@
package me.youhavetrouble.enchantio.enchants; package me.youhavetrouble.enchantio.enchants;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry; import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys; import io.papermc.paper.registry.keys.tags.EnchantmentTagKeys;
import io.papermc.paper.registry.tag.TagKey; 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.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -26,6 +26,7 @@ public class ExecutionerEnchant implements EnchantioEnchant {
private final Set<TagEntry<ItemType>> supportedItemTags; private final Set<TagEntry<ItemType>> supportedItemTags;
private final double damageMultiplierPerLevel, maxDamageHpThreshold; private final double damageMultiplierPerLevel, maxDamageHpThreshold;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>(); private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
public ExecutionerEnchant( public ExecutionerEnchant(
@@ -35,6 +36,7 @@ public class ExecutionerEnchant implements EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost maximumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable, boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags, Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots,
int maxLevel, int maxLevel,
double damageMultiplierPerLevel, double damageMultiplierPerLevel,
double maxDamageHpThreshold double maxDamageHpThreshold
@@ -45,6 +47,7 @@ public class ExecutionerEnchant implements EnchantioEnchant {
this.maximumCost = maximumCost; this.maximumCost = maximumCost;
this.supportedItemTags = supportedItemTags; this.supportedItemTags = supportedItemTags;
this.maxLevel = maxLevel; this.maxLevel = maxLevel;
this.activeSlots.addAll(activeSlots);
this.damageMultiplierPerLevel = damageMultiplierPerLevel; this.damageMultiplierPerLevel = damageMultiplierPerLevel;
this.maxDamageHpThreshold = maxDamageHpThreshold; this.maxDamageHpThreshold = maxDamageHpThreshold;
if (canGetFromEnchantingTable) { if (canGetFromEnchantingTable) {
@@ -53,12 +56,12 @@ public class ExecutionerEnchant implements EnchantioEnchant {
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.executioner","Executioner"); return Component.translatable("enchantio.enchant.executioner","Executioner");
} }
@@ -86,27 +89,27 @@ public class ExecutionerEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.HAND); return activeSlots;
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -25,6 +26,7 @@ public class PanicEnchant implements EnchantioEnchant {
private final double panicChancePerLevel; private final double panicChancePerLevel;
private final Set<TagEntry<ItemType>> supportedItemTags; private final Set<TagEntry<ItemType>> supportedItemTags;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>(); private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
public PanicEnchant( public PanicEnchant(
int anvilCost, int anvilCost,
@@ -33,6 +35,7 @@ public class PanicEnchant implements EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost maximumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable, boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags, Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots,
int maxLevel, int maxLevel,
double panicChancePerLevel double panicChancePerLevel
) { ) {
@@ -43,6 +46,7 @@ public class PanicEnchant implements EnchantioEnchant {
this.maximumCost = maximumCost; this.maximumCost = maximumCost;
this.supportedItemTags = supportedItemTags; this.supportedItemTags = supportedItemTags;
this.panicChancePerLevel = panicChancePerLevel; this.panicChancePerLevel = panicChancePerLevel;
this.activeSlots.addAll(activeSlots);
if (canGetFromEnchantingTable) { if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
} }
@@ -50,12 +54,12 @@ public class PanicEnchant implements EnchantioEnchant {
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.panic_curse", "Curse of Panic"); return Component.translatable("enchantio.enchant.panic_curse", "Curse of Panic");
} }
@@ -75,27 +79,27 @@ public class PanicEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.ARMOR); return activeSlots;
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -44,12 +45,12 @@ public class ReplantingEnchant implements EnchantioEnchant {
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.replanting", "Replanting"); return Component.translatable("enchantio.enchant.replanting", "Replanting");
} }
@@ -69,27 +70,27 @@ public class ReplantingEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.HAND); return Set.of(EquipmentSlotGroup.MAINHAND);
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -44,12 +45,12 @@ public class SmeltingEnchant implements EnchantioEnchant {
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.smelting", "Smelting"); return Component.translatable("enchantio.enchant.smelting", "Smelting");
} }
@@ -69,27 +70,27 @@ public class SmeltingEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.ANY); return Set.of(EquipmentSlotGroup.MAINHAND);
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -44,12 +45,12 @@ public class SoulboundEnchant implements EnchantioEnchant {
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.soulbound", "Soulbound"); return Component.translatable("enchantio.enchant.soulbound", "Soulbound");
} }
@@ -69,27 +70,27 @@ public class SoulboundEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.ANY); return Set.of(EquipmentSlotGroup.ANY);
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.Component;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@@ -24,6 +25,7 @@ public class TelepathyEnchant implements EnchantioEnchant {
private final EnchantmentRegistryEntry.EnchantmentCost maximumCost; private final EnchantmentRegistryEntry.EnchantmentCost maximumCost;
private final Set<TagEntry<ItemType>> supportedItemTags; private final Set<TagEntry<ItemType>> supportedItemTags;
private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>(); private final Set<TagKey<Enchantment>> enchantTagKeys = new HashSet<>();
private final Set<EquipmentSlotGroup> activeSlots = new HashSet<>();
public TelepathyEnchant( public TelepathyEnchant(
int anvilCost, int anvilCost,
@@ -31,25 +33,27 @@ public class TelepathyEnchant implements EnchantioEnchant {
EnchantmentRegistryEntry.EnchantmentCost minimumCost, EnchantmentRegistryEntry.EnchantmentCost minimumCost,
EnchantmentRegistryEntry.EnchantmentCost maximumCost, EnchantmentRegistryEntry.EnchantmentCost maximumCost,
boolean canGetFromEnchantingTable, boolean canGetFromEnchantingTable,
Set<TagEntry<ItemType>> supportedItemTags Set<TagEntry<ItemType>> supportedItemTags,
Set<EquipmentSlotGroup> activeSlots
) { ) {
this.anvilCost = anvilCost; this.anvilCost = anvilCost;
this.weight = weight; this.weight = weight;
this.minimumCost = minimumCost; this.minimumCost = minimumCost;
this.maximumCost = maximumCost; this.maximumCost = maximumCost;
this.supportedItemTags = supportedItemTags; this.supportedItemTags = supportedItemTags;
this.activeSlots.addAll(activeSlots);
if (canGetFromEnchantingTable) { if (canGetFromEnchantingTable) {
enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE); enchantTagKeys.add(EnchantmentTagKeys.IN_ENCHANTING_TABLE);
} }
} }
@Override @Override
public Key getKey() { public @NotNull Key getKey() {
return KEY; return KEY;
} }
@Override @Override
public Component getDescription() { public @NotNull Component getDescription() {
return Component.translatable("enchantio.enchant.telepathy","Telepathy"); return Component.translatable("enchantio.enchant.telepathy","Telepathy");
} }
@@ -69,27 +73,27 @@ public class TelepathyEnchant implements EnchantioEnchant {
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMinimumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMinimumCost() {
return minimumCost; return minimumCost;
} }
@Override @Override
public EnchantmentRegistryEntry.EnchantmentCost getMaximumCost() { public EnchantmentRegistryEntry.@NotNull EnchantmentCost getMaximumCost() {
return maximumCost; return maximumCost;
} }
@Override @Override
public Iterable<EquipmentSlotGroup> getActiveSlots() { public @NotNull Iterable<EquipmentSlotGroup> getActiveSlots() {
return Set.of(EquipmentSlotGroup.HAND); return activeSlots;
} }
@Override @Override
public Set<TagEntry<ItemType>> getSupportedItems() { public @NotNull Set<TagEntry<ItemType>> getSupportedItems() {
return supportedItemTags; return supportedItemTags;
} }
@Override @Override
public Set<TagKey<Enchantment>> getEnchantTagKeys() { public @NotNull Set<TagKey<Enchantment>> getEnchantTagKeys() {
return Collections.unmodifiableSet(enchantTagKeys); return Collections.unmodifiableSet(enchantTagKeys);
} }