java.lang.Object
net.pottercraft.ollivanders2.item.enchantment.Enchantment
Direct Known Subclasses:
CELATUM, FLAGRANTE, GEMINO, PORTUS, VOLATUS

public abstract class Enchantment extends Object
Abstract base class for all item enchantments.

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

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Optional configuration arguments for enchantment behavior.
    Utility functions for common operations.
    The type of enchantment.
    protected String
    Optional custom lore to display on the enchanted item.
    protected int
    The power level of this enchantment.
    protected Ollivanders2
    A reference to the plugin.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Enchantment(@NotNull Ollivanders2 plugin, int mag, @Nullable String args, @Nullable String itemLore)
    Constructor for creating a new enchantment instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    doEntityPickupItem(@NotNull org.bukkit.event.entity.EntityPickupItemEvent event)
    Handle entity item pickup events.
    abstract void
    doInventoryPickupItem(@NotNull org.bukkit.event.inventory.InventoryPickupItemEvent event)
    Handle inventory item pickup events.
    void
    doItemDespawn(@NotNull org.bukkit.event.entity.ItemDespawnEvent event)
    Handle item despawn events.
    abstract void
    doItemDrop(@NotNull org.bukkit.event.player.PlayerDropItemEvent event)
    Handle item drop events.
    abstract void
    doItemHeld(@NotNull org.bukkit.event.player.PlayerItemHeldEvent event)
    Handle item held events.
    @Nullable String
    Get the optional configuration arguments for this enchantment.
    int
    Get the magnitude (power level) of this enchantment.
    @NotNull String
    Get the name of this enchantment.
    Get the type of this enchantment.
    boolean
    isHoldingEnchantedItem(org.bukkit.entity.Player player)
    Check if the player is holding an item enchanted with this enchantment type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • enchantmentType

      protected ItemEnchantmentType 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

      protected Ollivanders2 p
      A reference to the plugin.

      Provides access to the Ollivanders2 plugin instance for server and logging operations.

    • magnitude

      protected int magnitude
      The 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

      protected String 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

      protected String 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

      protected Ollivanders2Common 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 enchantmentType to their specific type.

      Parameters:
      plugin - the Ollivanders2 plugin instance
      mag - the magnitude (power level) of this enchantment instance
      args - optional configuration arguments specific to this enchantment instance
      itemLore - optional custom lore to display on the enchanted item
  • Method Details

    • getName

      @NotNull public @NotNull String 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

      @NotNull public @NotNull ItemEnchantmentType 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

      @Nullable public @Nullable String 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