Class EnchantmentHolder
- java.lang.Object
-
- me.boboballoon.enhancedenchantments.enchantment.EnchantmentHolder
-
public class EnchantmentHolder extends Object
Class that represents an enchantment holder on an itemstack
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<ActiveEnchantment>
COMPARATOR
static NamespacedKey
KEY
-
Constructor Summary
Constructors Constructor Description EnchantmentHolder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addEnchantment(ActiveEnchantment enchantment, ItemStack item)
Adds an enchantment from the holdervoid
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)static EnchantmentHolder
fromString(String string)
Converts a serialized string into an enchantment holder objectActiveEnchantment
getEnchantment(Enchantment enchantment)
Returns the specified enchantment inside the holderList<ActiveEnchantment>
getEnchantments()
Returns a copy of all enchantments inside the holderboolean
hasEnchantment(Enchantment enchantment)
Returns a boolean that states whether this holder already contains a type of enchantmentboolean
isEmpty()
Returns a boolean that is true if there are no elements present in the listboolean
removeEnchantment(Enchantment enchantment, ItemStack item)
Removes an enchantment from the holderint
size()
Returns an int that is the amount of elements present in the listString
toString()
Converts this object into a serialized stringvoid
updateItem(ItemStack item)
Updates the lore on the item based on the enchantments
-
-
-
Field Detail
-
KEY
public static final NamespacedKey KEY
-
COMPARATOR
public static final Comparator<ActiveEnchantment> COMPARATOR
-
-
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 removeitem
- 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 additem
- 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
-
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
-
-