Class EnchantmentHolder


  • public class EnchantmentHolder
    extends Object
    Class that represents an enchantment holder on an itemstack
    • Constructor Detail

      • EnchantmentHolder

        public EnchantmentHolder()
    • Method Detail

      • getEnchantments

        public List<ActiveEnchantment> getEnchantments()
        Returns a copy of all enchantments inside the holder
        Returns:
        a copy of all enchantments inside the holder
      • isEmpty

        public boolean isEmpty()
        Returns a boolean that is true if there are no elements present in the list
        Returns:
        true if there are no elements present in the list
      • size

        public int size()
        Returns an int that is the amount of elements present in the list
        Returns:
        an int that is the amount of elements present in the list
      • getEnchantment

        public ActiveEnchantment getEnchantment​(Enchantment enchantment)
        Returns the specified enchantment inside the holder
        Parameters:
        enchantment - the enchantment you wish to get
        Returns:
        the specified enchantment inside the holder, null if not present
      • hasEnchantment

        public boolean hasEnchantment​(Enchantment enchantment)
        Returns a boolean that states whether this holder already contains a type of enchantment
        Parameters:
        enchantment - the enchantment you are checking for
        Returns:
        a boolean that states whether this holder already contains a type of enchantment
      • removeEnchantment

        public boolean removeEnchantment​(Enchantment enchantment,
                                         ItemStack item)
        Removes an enchantment from the holder
        Parameters:
        enchantment - the enchantment you are attempting to remove
        item - the item that this holder is to be applied to
        Returns:
        a boolean that states whether this holder contains the enchantment you are trying to remove
      • addEnchantment

        public boolean addEnchantment​(ActiveEnchantment enchantment,
                                      ItemStack item)
        Adds an enchantment from the holder
        Parameters:
        enchantment - the enchantment you are attempting to add
        item - the item that this holder is to be applied to
        Returns:
        a boolean that states whether this type of enchantment can be added to said item
      • addEnchantmentUnsafe

        public void addEnchantmentUnsafe​(ActiveEnchantment enchantment)
        Adds an enchantment from the holder unsafely (only use if you do not need to update the item or check if an enchantment was already added)
        Parameters:
        enchantment - the enchantment you are attempting to remove
      • updateItem

        public void updateItem​(ItemStack item)
        Updates the lore on the item based on the enchantments
        Parameters:
        item - the item that this holder is to be applied to
      • toString

        public String toString()
        Converts this object into a serialized string
        Overrides:
        toString in class Object
        Returns:
        serialized string
      • fromString

        public static EnchantmentHolder fromString​(String string)
        Converts a serialized string into an enchantment holder object
        Parameters:
        string - serialized string
        Returns:
        enchantment holder object, null if invalid