Class EnchantmentModifier
java.lang.Object
io.github.projectunified.craftitem.spigot.modifier.EnchantmentModifier
- All Implemented Interfaces:
ItemModifier,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 Summary
ConstructorsConstructorDescriptionEnchantmentModifier(List<String> enchantments) Creates an EnchantmentModifier from a list of enchantment strings.EnchantmentModifier(Map<org.bukkit.enchantments.Enchantment, Integer> enchantments) Creates an EnchantmentModifier from a map of Enchantment objects. -
Method Summary
Modifier and TypeMethodDescriptionvoidmodify(SpigotItem item, UnaryOperator<String> translator) Applies enchantments to the item.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.projectunified.craftitem.spigot.core.SpigotItemModifier
modify
-
Constructor Details
-
EnchantmentModifier
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
Creates an EnchantmentModifier from a map of Enchantment objects.- Parameters:
enchantments- map of enchantments to their levels
-
-
Method Details
-
modify
Applies enchantments to the item. For enchanted books (EnchantmentStorageMeta), uses stored enchantments. For other items, applies enchantments directly.- Specified by:
modifyin interfaceSpigotItemModifier- Parameters:
item- the SpigotItem to modifytranslator- the string translator for variable substitution
-