Class EnchantmentModifier

java.lang.Object
io.github.projectunified.craftitem.spigot.modifier.EnchantmentModifier
All Implemented Interfaces:
ItemModifier, SpigotItemModifier

public class EnchantmentModifier extends Object implements SpigotItemModifier
Spigot modifier that applies enchantments to items.

Supports enchantment definition as either a list of strings or a map of Enchantment objects. String format: "ENCHANTMENT_NAME level" or "ENCHANTMENT_NAME,level" Handles both regular items and enchanted books.

Example Usage:


 // String list format
 ItemModifier mod1 = new EnchantmentModifier(List.of(
     "Sharpness 5",
     "Knockback, 2"
 ));

 // Direct Enchantment map
 Map<Enchantment, Integer> enchants = Map.of(
     Enchantment.DAMAGE_ALL, 5,
     Enchantment.KNOCKBACK, 2
 );
 ItemModifier mod2 = new EnchantmentModifier(enchants);
 
  • Constructor Details

    • EnchantmentModifier

      public EnchantmentModifier(List<String> enchantments)
      Creates an EnchantmentModifier from a list of enchantment strings. Format: "ENCHANTMENT_NAME level" or "ENCHANTMENT_NAME,level"
      Parameters:
      enchantments - the list of enchantment strings
    • EnchantmentModifier

      public EnchantmentModifier(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
      Creates an EnchantmentModifier from a map of Enchantment objects.
      Parameters:
      enchantments - map of enchantments to their levels
  • Method Details

    • modify

      public void modify(SpigotItem item, UnaryOperator<String> translator)
      Applies enchantments to the item. For enchanted books (EnchantmentStorageMeta), uses stored enchantments. For other items, applies enchantments directly.
      Specified by:
      modify in interface SpigotItemModifier
      Parameters:
      item - the SpigotItem to modify
      translator - the string translator for variable substitution