Package redempt.redlib.itemutils
Class ItemBuilder
java.lang.Object
org.bukkit.inventory.ItemStack
redempt.redlib.itemutils.ItemBuilder
- All Implemented Interfaces:
Cloneable
,org.bukkit.configuration.serialization.ConfigurationSerializable
public class ItemBuilder
extends org.bukkit.inventory.ItemStack
A utility class to easily create items
-
Constructor Summary
ConstructorDescriptionItemBuilder
(org.bukkit.inventory.ItemStack item) Constructs an ItemBuilder using a pre-existing itemItemBuilder
(org.bukkit.Material material) Constructs a new ItemBuilder.ItemBuilder
(org.bukkit.Material material, int amount) Constructs a new ItemBuilder. -
Method Summary
Modifier and TypeMethodDescriptionaddAttribute
(org.bukkit.attribute.Attribute attribute, double amount, org.bukkit.attribute.AttributeModifier.Operation operation) Adds an attribute to this ItemBuilderaddAttribute
(org.bukkit.attribute.Attribute attribute, double amount, org.bukkit.attribute.AttributeModifier.Operation operation, org.bukkit.inventory.EquipmentSlot slot) Adds an attribute to this ItemBuilderaddAttribute
(org.bukkit.attribute.Attribute attribute, org.bukkit.attribute.AttributeModifier modifier) Adds an attribute to this ItemBuilderaddDamage
(int damage) Adds damage to this ItemBuilderaddEnchant
(org.bukkit.enchantments.Enchantment enchant, int level) Adds an enchantment to this ItemBuilderaddItemFlags
(org.bukkit.inventory.ItemFlag... flags) Adds ItemFlags to this ItemBuilderAdd multiple lines of lore to this ItemBuilderAdd a line of lore to this ItemBuilder<T,
Z> ItemBuilder addPersistentTag
(org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T, Z> type, Z data) Add persistent tags to this ItemBuilderremoveLore
(int index) Remove a line of lore if present from this ItemBuilderremoveLore
(String line) Remove a String of lore if present from this ItemBuildersetCount
(int amount) Sets the stack size of this ItemBuildersetCustomModelData
(int customModelData) Sets the custom model data of this ItemBuildersetDurability
(int durability) Set the durability (damage) of the ItemBuilderSet the lore of this ItemBuilderRenames this ItemBuilderorg.bukkit.inventory.ItemStack
Converts this ItemBuilder to a normal ItemStack.Sets this ItemBuilder to be unbreakableMethods inherited from class org.bukkit.inventory.ItemStack
addEnchantment, addEnchantments, addUnsafeEnchantment, addUnsafeEnchantments, clone, containsEnchantment, deserialize, equals, getAmount, getData, getDurability, getEnchantmentLevel, getEnchantments, getItemMeta, getMaxStackSize, getType, hashCode, hasItemMeta, isSimilar, removeEnchantment, serialize, setAmount, setData, setDurability, setItemMeta, setType, toString
-
Constructor Details
-
ItemBuilder
public ItemBuilder(org.bukkit.Material material, int amount) Constructs a new ItemBuilder. An ItemBuilder extends ItemStack, an can be used as such.- Parameters:
material
- The type of the itemamount
- The amount of the item
-
ItemBuilder
public ItemBuilder(org.bukkit.Material material) Constructs a new ItemBuilder. An ItemBuilder extends ItemStack, an can be used as such.- Parameters:
material
- The type of the item
-
ItemBuilder
public ItemBuilder(org.bukkit.inventory.ItemStack item) Constructs an ItemBuilder using a pre-existing item- Parameters:
item
- The item to copy
-
-
Method Details
-
setCount
Sets the stack size of this ItemBuilder- Parameters:
amount
- The number of items in the stack- Returns:
- The ItemBuilder with the new stack size
-
addEnchant
Adds an enchantment to this ItemBuilder- Parameters:
enchant
- The enchantment to addlevel
- The level of the enchantment- Returns:
- The enchanted ItemBuilder
-
toItemStack
public org.bukkit.inventory.ItemStack toItemStack()Converts this ItemBuilder to a normal ItemStack. Useful because there are some inconsistencies within Spigot using this class.- Returns:
- An ItemStack copy of this ItemBuilder
-
setLore
Set the lore of this ItemBuilder- Parameters:
lore
- The lines of lore- Returns:
- The ItemBuilder with lore added
-
addLore
Add a line of lore to this ItemBuilder- Parameters:
line
- The line of lore- Returns:
- The ItemBuilder with lore added
-
addLore
Add multiple lines of lore to this ItemBuilder- Parameters:
lines
- The lines of lore- Returns:
- The ItemBuilder with lore added
-
removeLore
Remove a String of lore if present from this ItemBuilder- Parameters:
line
- The line of lore to remove- Returns:
- The ItemBuilder with lore removed if present
-
removeLore
Remove a line of lore if present from this ItemBuilder- Parameters:
index
- The index of the line of lore to remove- Returns:
- The ItemBuilder with lore removed if present
-
setName
Renames this ItemBuilder- Parameters:
name
- The name to set- Returns:
- The renamed ItemBuilder
-
setDurability
Set the durability (damage) of the ItemBuilder- Parameters:
durability
- The durability to set- Returns:
- The ItemBuilder with its durability changed
-
addAttribute
public ItemBuilder addAttribute(org.bukkit.attribute.Attribute attribute, org.bukkit.attribute.AttributeModifier modifier) Adds an attribute to this ItemBuilder- Parameters:
attribute
- The Attribute to be addedmodifier
- The AttributeModifier to be added- Returns:
- The ItemBuilder with the attribute added
-
addAttribute
public ItemBuilder addAttribute(org.bukkit.attribute.Attribute attribute, double amount, org.bukkit.attribute.AttributeModifier.Operation operation) Adds an attribute to this ItemBuilder- Parameters:
attribute
- The attribute to be addedamount
- The amount of the modifieroperation
- The operation of the modifier- Returns:
- The ItemBuilder with the attribute added
-
addAttribute
public ItemBuilder addAttribute(org.bukkit.attribute.Attribute attribute, double amount, org.bukkit.attribute.AttributeModifier.Operation operation, org.bukkit.inventory.EquipmentSlot slot) Adds an attribute to this ItemBuilder- Parameters:
attribute
- The attribute to be addedamount
- The amount of the modifieroperation
- The operation of the modifierslot
- The slot the modifier affects- Returns:
- The ItemBuilder with the attribute added
-
addItemFlags
Adds ItemFlags to this ItemBuilder- Parameters:
flags
- The ItemFlags to add- Returns:
- The ItemBuilder with the flags added
-
addDamage
Adds damage to this ItemBuilder- Parameters:
damage
- The amount of damage to apply- Returns:
- The ItemBuilder with the damage applied
-
setCustomModelData
Sets the custom model data of this ItemBuilder- Parameters:
customModelData
- The custom model data to set- Returns:
- The ItemBuilder with the custom model data set
-
addPersistentTag
public <T,Z> ItemBuilder addPersistentTag(org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<T, Z> type, Z data) Add persistent tags to this ItemBuilder- Type Parameters:
T
- The primary object typeZ
- The retrieved object type- Parameters:
key
- The key to add the data undertype
- The type of the datadata
- The data to store- Returns:
- The ItemBuilder with the persistent data added
-
unbreakable
Sets this ItemBuilder to be unbreakable- Returns:
- The ItemBuilder with the unbreakable tag added
-