Class Enchantment
Provides a template for enchantment behavior using event handlers for item interactions
(pickup, drop, despawn, item held). Subclasses must implement all abstract event handler methods
and set the enchantmentType field to identify the specific enchantment type.
Enchantments are defined by their type (ItemEnchantmentType), magnitude (power level),
optional item lore, and optional arguments for custom behavior.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringOptional configuration arguments for enchantment behavior.protected Ollivanders2CommonUtility functions for common operations.protected ItemEnchantmentTypeThe type of enchantment.protected StringOptional custom lore to display on the enchanted item.protected intThe power level of this enchantment.protected Ollivanders2A reference to the plugin. -
Constructor Summary
ConstructorsConstructorDescriptionEnchantment(@NotNull Ollivanders2 plugin, int mag, @Nullable String args, @Nullable String itemLore) Constructor for creating a new enchantment instance. -
Method Summary
Modifier and TypeMethodDescriptionabstract voiddoEntityPickupItem(@NotNull org.bukkit.event.entity.EntityPickupItemEvent event) Handle entity item pickup events.abstract voiddoInventoryPickupItem(@NotNull org.bukkit.event.inventory.InventoryPickupItemEvent event) Handle inventory item pickup events.voiddoItemDespawn(@NotNull org.bukkit.event.entity.ItemDespawnEvent event) Handle item despawn events.abstract voiddoItemDrop(@NotNull org.bukkit.event.player.PlayerDropItemEvent event) Handle item drop events.abstract voiddoItemHeld(@NotNull org.bukkit.event.player.PlayerItemHeldEvent event) Handle item held events.@Nullable StringgetArgs()Get the optional configuration arguments for this enchantment.intGet the magnitude (power level) of this enchantment.@NotNull StringgetName()Get the name of this enchantment.@NotNull ItemEnchantmentTypegetType()Get the type of this enchantment.booleanisHoldingEnchantedItem(org.bukkit.entity.Player player) Check if the player is holding an item enchanted with this enchantment type.
-
Field Details
-
enchantmentType
The type of enchantment.Defaults to GEMINIO but should be set by subclasses to the appropriate
ItemEnchantmentType. Determines the enchantment's identity and is used for NBT tag identification and lookup. -
p
A reference to the plugin.Provides access to the Ollivanders2 plugin instance for server and logging operations.
-
magnitude
protected int magnitudeThe power level of this enchantment.Represents the magnitude or intensity of the enchantment effect. Higher values typically indicate stronger or more frequent enchantment behavior.
-
lore
Optional custom lore to display on the enchanted item.Can be used to add descriptive text to the item's lore, such as descriptions for enchanted broomsticks. Null if no custom lore is needed.
-
args
Optional configuration arguments for enchantment behavior.Allows enchantments to be configured with custom parameters without requiring subclass changes. Format and interpretation are enchantment-specific. Null if no arguments are provided.
-
common
Utility functions for common operations.Provides access to shared functionality such as debug logging and random number generation.
-
-
Constructor Details
-
Enchantment
public Enchantment(@NotNull @NotNull Ollivanders2 plugin, int mag, @Nullable @Nullable String args, @Nullable @Nullable String itemLore) Constructor for creating a new enchantment instance.Initializes the enchantment with a plugin reference, magnitude, and optional configuration. Subclasses should call this constructor and set
enchantmentTypeto their specific type.- Parameters:
plugin- the Ollivanders2 plugin instancemag- the magnitude (power level) of this enchantment instanceargs- optional configuration arguments specific to this enchantment instanceitemLore- optional custom lore to display on the enchanted item
-
-
Method Details
-
getName
Get the name of this enchantment.Retrieves the display name from the
enchantmentType, which identifies this enchantment for UI and logging purposes.- Returns:
- the enchantment name, never null
-
getMagnitude
public int getMagnitude()Get the magnitude (power level) of this enchantment.The magnitude determines the intensity or frequency of the enchantment effect.
- Returns:
- the magnitude value
-
getType
Get the type of this enchantment.The enchantment type is used for NBT tag identification and determines which enchantment behaviors are triggered.
- Returns:
- the enchantment type, never null
-
getArgs
Get the optional configuration arguments for this enchantment.Returns the custom arguments passed during enchantment creation, allowing enchantments to be configured with behavior parameters. The format is enchantment-specific.
- Returns:
- the arguments string, or null if no arguments were provided
-
isHoldingEnchantedItem
public boolean isHoldingEnchantedItem(org.bukkit.entity.Player player) Check if the player is holding an item enchanted with this enchantment type.Examines both the main hand and off-hand inventory slots to determine if either contains an item matching this enchantment type.
- Parameters:
player- the player to check- Returns:
- true if the player is holding an item with this enchantment type in either hand, false otherwise
-
doItemDespawn
public void doItemDespawn(@NotNull @NotNull org.bukkit.event.entity.ItemDespawnEvent event) Handle item despawn events.Called when an enchanted item despawns from the world. Prevent enchanted items from despawning.
- Parameters:
event- the item despawn event
-
doEntityPickupItem
public abstract void doEntityPickupItem(@NotNull @NotNull org.bukkit.event.entity.EntityPickupItemEvent event) Handle entity item pickup events.Called when a living entity (not a player) picks up an enchanted item. Implement to trigger enchantment effects specific to non-player entities.
- Parameters:
event- the entity item pickup event
-
doInventoryPickupItem
public abstract void doInventoryPickupItem(@NotNull @NotNull org.bukkit.event.inventory.InventoryPickupItemEvent event) Handle inventory item pickup events.Called when a hopper or other block inventory picks up an enchanted item. Implement to trigger enchantment effects related to block-based inventory interactions.
- Parameters:
event- the inventory item pickup event
-
doItemDrop
public abstract void doItemDrop(@NotNull @NotNull org.bukkit.event.player.PlayerDropItemEvent event) Handle item drop events.Called when a player drops an enchanted item. Implement to trigger enchantment effects related to item dropping.
- Parameters:
event- the item drop event
-
doItemHeld
public abstract void doItemHeld(@NotNull @NotNull org.bukkit.event.player.PlayerItemHeldEvent event) Handle item held events.Called when a player changes which item is held (switches slots in hotbar). Implement to trigger enchantment effects related to item selection.
- Parameters:
event- the item held event
-