Class Enchantment

java.lang.Object
org.bukkit.enchantments.Enchantment
All Implemented Interfaces:
Keyed
Direct Known Subclasses:
EnchantmentWrapper

public abstract class Enchantment
extends Object
implements Keyed
The various type of enchantments that may be added to armour or weapons
  • Field Details

  • Constructor Details

  • Method Details

    • getKey

      @NotNull public NamespacedKey getKey()
      Description copied from interface: Keyed
      Return the namespaced identifier for this object.
      Specified by:
      getKey in interface Keyed
      Returns:
      this object's key
    • getName

      @NotNull @Deprecated public abstract String getName()
      Deprecated.
      enchantments are badly named, use getKey().
      Gets the unique name of this enchantment
      Returns:
      Unique name
    • getMaxLevel

      public abstract int getMaxLevel()
      Gets the maximum level that this Enchantment may become.
      Returns:
      Maximum level of the Enchantment
    • getStartLevel

      public abstract int getStartLevel()
      Gets the level that this Enchantment should start at
      Returns:
      Starting level of the Enchantment
    • getItemTarget

      @NotNull public abstract EnchantmentTarget getItemTarget()
      Gets the type of ItemStack that may fit this Enchantment.
      Returns:
      Target type of the Enchantment
    • isTreasure

      public abstract boolean isTreasure()
      Checks if this enchantment is a treasure enchantment.
      Treasure enchantments can only be received via looting, trading, or fishing.
      Returns:
      true if the enchantment is a treasure enchantment
    • isCursed

      @Deprecated public abstract boolean isCursed()
      Deprecated.
      cursed enchantments are no longer special. Will return true only for BINDING_CURSE and VANISHING_CURSE.
      Checks if this enchantment is a cursed enchantment
      Cursed enchantments are found the same way treasure enchantments are
      Returns:
      true if the enchantment is cursed
    • conflictsWith

      public abstract boolean conflictsWith​(@NotNull Enchantment other)
      Check if this enchantment conflicts with another enchantment.
      Parameters:
      other - The enchantment to check against
      Returns:
      True if there is a conflict.
    • canEnchantItem

      public abstract boolean canEnchantItem​(@NotNull ItemStack item)
      Checks if this Enchantment may be applied to the given ItemStack.

      This does not check if it conflicts with any enchantments already applied to the item.

      Parameters:
      item - Item to test
      Returns:
      True if the enchantment may be applied, otherwise False
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • registerEnchantment

      public static void registerEnchantment​(@NotNull Enchantment enchantment)
      Registers an enchantment with the given ID and object.

      Generally not to be used from within a plugin.

      Parameters:
      enchantment - Enchantment to register
    • isAcceptingRegistrations

      public static boolean isAcceptingRegistrations()
      Checks if this is accepting Enchantment registrations.
      Returns:
      True if the server Implementation may add enchantments
    • stopAcceptingRegistrations

      public static void stopAcceptingRegistrations()
      Stops accepting any enchantment registrations
    • getByKey

      @Contract("null -> null") @Nullable public static Enchantment getByKey​(@Nullable NamespacedKey key)
      Gets the Enchantment at the specified key
      Parameters:
      key - key to fetch
      Returns:
      Resulting Enchantment, or null if not found
    • getByName

      @Deprecated @Contract("null -> null") @Nullable public static Enchantment getByName​(@Nullable String name)
      Deprecated.
      enchantments are badly named, use getByKey(org.bukkit.NamespacedKey).
      Gets the Enchantment at the specified name
      Parameters:
      name - Name to fetch
      Returns:
      Resulting Enchantment, or null if not found
    • values

      @NotNull public static Enchantment[] values()
      Gets an array of all the registered Enchantments
      Returns:
      Array of enchantments