Class ItemBuilder

java.lang.Object
net.apartium.cocoabeans.spigot.inventory.ItemBuilder

public abstract class ItemBuilder extends Object
Chained class used to modify and create item stacks. via the building structure and allows easy and flexible ways to create ItemStacks.
  • Method Details

    • builder

      public static ItemBuilder builder(org.bukkit.inventory.ItemStack itemStack)
      Create a new item builder instance from given item stack. Clones given item stack to avoid problems.
      Parameters:
      itemStack - item stack to copy into new builder instance
      Returns:
      new builder instance
    • builder

      public static ItemBuilder builder(org.bukkit.Material material)
      Create a new item builder instance based on given material
      Parameters:
      material - material to use
      Returns:
      new builder instance
    • skullBuilder

      @Blocking public static ItemBuilder skullBuilder(org.bukkit.OfflinePlayer offlinePlayer)
      Create a new item builder instance constituting of given player's skull
      Parameters:
      offlinePlayer - offline player to make skull of
      Returns:
      new builder instance
    • skullBuilder

      public static ItemBuilder skullBuilder(com.destroystokyo.paper.profile.PlayerProfile playerProfile)
      Create a new item builder instance constituting of given player's skull
      Parameters:
      playerProfile - profile containing player's textures
      Returns:
      new builder instance
    • skullBuilder

      public static ItemBuilder skullBuilder(URL url)
      Create a new item builder instance constituting of skull from given url
      Parameters:
      url - skull url
      Returns:
      new builder instance
    • skullBuilder

      public static ItemBuilder skullBuilder(String base64)
      Create a new item builder instance constituting of skull by given base64 encoded string
      Parameters:
      base64 - head value
      Returns:
      new builder instance
    • setSkullTextureBase64

      public ItemBuilder setSkullTextureBase64(String base64) throws MalformedURLException
      Parameters:
      base64 - set skull texture with base64
      Returns:
      current instance
      Throws:
      MalformedURLException
    • setOwningPlayer

      @Blocking public abstract ItemBuilder setOwningPlayer(org.bukkit.OfflinePlayer offlinePlayer)
      Applicable for skulls.
      Parameters:
      offlinePlayer - player
      Returns:
      current instance
      See Also:
    • setSkullProfile

      public ItemBuilder setSkullProfile(com.destroystokyo.paper.profile.PlayerProfile profile)
      Set profile associated with a skull
      Parameters:
      profile - profile with textures
      Returns:
      current instance
    • setSkullTextureURL

      public ItemBuilder setSkullTextureURL(URL url)
      Parameters:
      url - set skull texture with url to the texture
      Returns:
      current instance
    • setLore

      public ItemBuilder setLore(String... texts)
      Parameters:
      texts - set lore with texts
      Returns:
      current instance
    • setLore

      public ItemBuilder setLore(List<net.kyori.adventure.text.Component> lore)
      Parameters:
      lore - set lore
      Returns:
      current instance
    • setLore

      @AvailableSince("0.0.36") public ItemBuilder setLore(net.kyori.adventure.text.Component lore)
      Parameters:
      lore - set lore
      Returns:
      current instance
    • setLoreAsText

      public ItemBuilder setLoreAsText(List<String> lore)
      Parameters:
      lore - set lore
      Returns:
      current instance
    • setDurability

      public abstract ItemBuilder setDurability(short durability)
      Parameters:
      durability - set durability to the item
      Returns:
      current instance
    • setDisplayName

      public ItemBuilder setDisplayName(net.kyori.adventure.text.Component component)
      Parameters:
      component - set item name to component name
      Returns:
      current instance
    • setDisplayName

      public ItemBuilder setDisplayName(String name)
      Parameters:
      name - set item name to name
      Returns:
      current instance
    • setNBT

      public ItemBuilder setNBT(org.bukkit.NamespacedKey namespacedKey, Object persistentDataType, Object object)
      set nbt with key type and value
      Parameters:
      namespacedKey - nbt key
      persistentDataType - data type
      object - object as value
      Returns:
      current instance
    • setAttributeModifiers

      public ItemBuilder setAttributeModifiers(com.google.common.collect.Multimap<org.bukkit.attribute.Attribute,org.bukkit.attribute.AttributeModifier> map)
      Set attribute modifiers of the item.
      Parameters:
      map - attribute modifiers
      Returns:
      current instance
      See Also:
      • ItemMeta.setAttributeModifiers(Multimap)
    • addAttributeModifiers

      public ItemBuilder addAttributeModifiers(org.bukkit.attribute.Attribute attribute, org.bukkit.attribute.AttributeModifier attributeModifier)
      Add attribute modifier the the item.
      Parameters:
      attribute - attribute
      attributeModifier - modifier
      Returns:
      current instance
      See Also:
      • ItemMeta.addAttributeModifier(Attribute, AttributeModifier)
    • setAmount

      public ItemBuilder setAmount(int amount)
      Set the amount of the item in the stack
      Parameters:
      amount - new amount to set
      Returns:
      current instance
    • addLoreLines

      @AvailableSince("0.0.36") public ItemBuilder addLoreLines(String... lines)
      Add lines to lore of the item
      Parameters:
      lines - add lines to lore
      Returns:
      current instance
    • addLoreLine

      @AvailableSince("0.0.36") public ItemBuilder addLoreLine(String line)
      Add line to lore of the item
      Parameters:
      line - add lines to lore
      Returns:
      current instance
    • addLoreLines

      @AvailableSince("0.0.36") public ItemBuilder addLoreLines(net.kyori.adventure.text.Component... components)
      Add lines to lore of the item
      Parameters:
      components - add lines to lore
      Returns:
      current instance
    • addLoreLine

      @AvailableSince("0.0.36") public ItemBuilder addLoreLine(net.kyori.adventure.text.Component component)
      Add line to lore of the item
      Parameters:
      component - add lines to lore
      Returns:
      current instance
    • removeLine

      public ItemBuilder removeLine(String text)
      Parameters:
      text - remove line by text
      Returns:
      current instance
    • removeLine

      public ItemBuilder removeLine(int index)
      Parameters:
      index - remove line by index
      Returns:
      current instance
    • setCustomModelData

      public ItemBuilder setCustomModelData(int data)
      Set custom model data of the item.
      Parameters:
      data - custom model data
      Returns:
      current instance
      See Also:
      • ItemMeta.setCustomModelData(Integer)
    • setColor

      public ItemBuilder setColor(org.bukkit.Color color)
      Set item color if item meta supports it
      Parameters:
      color - color to set
      Returns:
      current instance
      See Also:
      • LeatherArmorMeta.setColor(Color)
      • PotionMeta.setColor(Color)
      • FireworkEffect.getColors()
      • FireworkEffect.getFadeColors()
    • addEnchantment

      public ItemBuilder addEnchantment(org.bukkit.enchantments.Enchantment enchantment, int level)
      Adds an enchantment to the map list to finally enchant the item when is constructed.
      Parameters:
      enchantment - The enchantment to use
      level - The level to set the enchantment to (is allowing unsafe.)
    • removeEnchantment

      public ItemBuilder removeEnchantment(org.bukkit.enchantments.Enchantment enchantment)
      Removes an enchantment from the map list to finally enchant the item when is constructed.
      Parameters:
      enchantment - The enchantment to remove
    • setEnchantment

      public ItemBuilder setEnchantment(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
      Sets an enchantment to the map list to finally enchant the item when is constructed.
      Parameters:
      enchantments - The enchantments to use
    • setGlowing

      public ItemBuilder setGlowing(boolean isGlowing)
      This method requires to include the EnchantGlow class. Makes the item glow like its enchanted, but does not actually register the enchantment as anything, simply commits that the item is enchanted.
      Parameters:
      isGlowing - Set the item to glow, if false this will revoke glow.
    • setType

      public ItemBuilder setType(org.bukkit.Material material)
      Set type of the item.
      Parameters:
      material - type to set
      Returns:
      current instance
    • setUnbreakable

      public abstract ItemBuilder setUnbreakable(boolean value)
      Set this item as unbreakable or not
      Parameters:
      value - true for unbreakable, else false
      Returns:
      current instance
      See Also:
      • ItemMeta.setUnbreakable(boolean)
    • addItemFlags

      public ItemBuilder addItemFlags(org.bukkit.inventory.ItemFlag... itemFlags)
      Add item flags to the item.
      Parameters:
      itemFlags - item flags to add
      Returns:
      current instance
    • setPotionData

      public ItemBuilder setPotionData(org.bukkit.potion.PotionData potionData)
      Set potion data if this item stack is a potion, otherwise do nothing
      Parameters:
      potionData - potion data to set
      Returns:
      current instance
    • addPotionEffect

      public ItemBuilder addPotionEffect(org.bukkit.potion.PotionEffect potionEffect)
      Add potion effect to this item if potion, otherwise do nothing
      Parameters:
      potionEffect - potion effect to add
      Returns:
      current instance
    • addCanDestroy

      @Experimental public ItemBuilder addCanDestroy(String... ids)
      Add can destroy flag to the current item
      Parameters:
      ids - ids
      Returns:
      current instance
    • addCanPlaceOn

      @Experimental public ItemBuilder addCanPlaceOn(String... ids)
      Add can place on flag to the current item
      Parameters:
      ids - ids
      Returns:
      current instance
    • build

      public org.bukkit.inventory.ItemStack build()
      Build current item builder instance and return a copy of produced item
      Returns:
      cloned item stack instance