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

    Constructors
    Constructor
    Description
    ItemBuilder(org.bukkit.inventory.ItemStack item)
    Constructs an ItemBuilder using a pre-existing item
    ItemBuilder(org.bukkit.Material material)
    Constructs a new ItemBuilder.
    ItemBuilder(org.bukkit.Material material, int amount)
    Constructs a new ItemBuilder.
  • Method Summary

    Modifier and Type
    Method
    Description
    addAttribute(org.bukkit.attribute.Attribute attribute, double amount, org.bukkit.attribute.AttributeModifier.Operation operation)
    Adds an attribute to this 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
    addAttribute(org.bukkit.attribute.Attribute attribute, org.bukkit.attribute.AttributeModifier modifier)
    Adds an attribute to this ItemBuilder
    addDamage(int damage)
    Adds damage to this ItemBuilder
    addEnchant(org.bukkit.enchantments.Enchantment enchant, int level)
    Adds an enchantment to this ItemBuilder
    addItemFlags(org.bukkit.inventory.ItemFlag... flags)
    Adds ItemFlags to this ItemBuilder
    Add multiple lines of lore to this ItemBuilder
    Add 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 ItemBuilder
    removeLore(int index)
    Remove a line of lore if present from this ItemBuilder
    Remove a String of lore if present from this ItemBuilder
    setCount(int amount)
    Sets the stack size of this ItemBuilder
    setCustomModelData(int customModelData)
    Sets the custom model data of this ItemBuilder
    setDurability(int durability)
    Set the durability (damage) of the ItemBuilder
    setLore(String... lore)
    Set the lore of this ItemBuilder
    Renames this ItemBuilder
    org.bukkit.inventory.ItemStack
    Converts this ItemBuilder to a normal ItemStack.
    Sets this ItemBuilder to be unbreakable

    Methods 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

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 item
      amount - 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

      public ItemBuilder setCount(int amount)
      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

      public ItemBuilder addEnchant(org.bukkit.enchantments.Enchantment enchant, int level)
      Adds an enchantment to this ItemBuilder
      Parameters:
      enchant - The enchantment to add
      level - 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

      public ItemBuilder setLore(String... lore)
      Set the lore of this ItemBuilder
      Parameters:
      lore - The lines of lore
      Returns:
      The ItemBuilder with lore added
    • addLore

      public ItemBuilder addLore(String line)
      Add a line of lore to this ItemBuilder
      Parameters:
      line - The line of lore
      Returns:
      The ItemBuilder with lore added
    • addLore

      public ItemBuilder addLore(Iterable<String> lines)
      Add multiple lines of lore to this ItemBuilder
      Parameters:
      lines - The lines of lore
      Returns:
      The ItemBuilder with lore added
    • removeLore

      public ItemBuilder removeLore(String line)
      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

      public ItemBuilder removeLore(int index)
      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

      public ItemBuilder setName(String name)
      Renames this ItemBuilder
      Parameters:
      name - The name to set
      Returns:
      The renamed ItemBuilder
    • setDurability

      public ItemBuilder setDurability(int durability)
      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 added
      modifier - 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 added
      amount - The amount of the modifier
      operation - 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 added
      amount - The amount of the modifier
      operation - The operation of the modifier
      slot - The slot the modifier affects
      Returns:
      The ItemBuilder with the attribute added
    • addItemFlags

      public ItemBuilder addItemFlags(org.bukkit.inventory.ItemFlag... flags)
      Adds ItemFlags to this ItemBuilder
      Parameters:
      flags - The ItemFlags to add
      Returns:
      The ItemBuilder with the flags added
    • addDamage

      public ItemBuilder addDamage(int damage)
      Adds damage to this ItemBuilder
      Parameters:
      damage - The amount of damage to apply
      Returns:
      The ItemBuilder with the damage applied
    • setCustomModelData

      public ItemBuilder setCustomModelData(int customModelData)
      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 type
      Z - The retrieved object type
      Parameters:
      key - The key to add the data under
      type - The type of the data
      data - The data to store
      Returns:
      The ItemBuilder with the persistent data added
    • unbreakable

      public ItemBuilder unbreakable()
      Sets this ItemBuilder to be unbreakable
      Returns:
      The ItemBuilder with the unbreakable tag added