Class ItemBuilder

java.lang.Object
com.bencodez.advancedcore.api.item.ItemBuilder

public class ItemBuilder extends Object
Easily create itemstacks, without messing your hands. Credit to NonameSL for creating this Modified by Ben12345rocks
  • Constructor Details

    • ItemBuilder

      public ItemBuilder(org.bukkit.configuration.ConfigurationSection data)
      Create ItemBuilder from a ConfigurationSection
      Parameters:
      data - ConfigurationSection
    • ItemBuilder

      public ItemBuilder(org.bukkit.inventory.ItemStack is)
      Create a new ItemBuilder over an existing itemstack.
      Parameters:
      is - The itemstack to create the ItemBuilder over.
    • ItemBuilder

      public ItemBuilder(org.bukkit.Material m)
      Create a new ItemBuilder from scratch.
      Parameters:
      m - The material to create the ItemBuilder with.
    • ItemBuilder

      public ItemBuilder(org.bukkit.Material material, int amount)
      Create a new ItemBuilder from scratch.
      Parameters:
      material - The material of the item.
      amount - The amount of the item.
    • ItemBuilder

      public ItemBuilder(String material)
      Constructs an ItemBuilder from a material string.
      Parameters:
      material - the material name
  • Method Details

    • setHideTooltipCompat

      public void setHideTooltipCompat(org.bukkit.inventory.ItemStack item, boolean hide)
      Hides (or shows) the item tooltip. On 1.20.5+ this uses the native ItemMeta#setHideTooltip method; on older versions it simply adds all available ItemFlags (so at least most tooltip lines are hidden).
      Parameters:
      item - the ItemStack to modify
      hide - true to hide, false to show
    • addAttributeModifier

      public ItemBuilder addAttributeModifier(org.bukkit.attribute.Attribute att, org.bukkit.attribute.AttributeModifier modifier)
      Adds an attribute modifier to the item.
      Parameters:
      att - the attribute
      modifier - the attribute modifier
      Returns:
      this ItemBuilder
    • addEnchant

      public ItemBuilder addEnchant(org.bukkit.enchantments.Enchantment ench, int level)
      Add an enchant to the item.
      Parameters:
      ench - The enchant to add
      level - The level
      Returns:
      ItemBuilder
    • addEnchantments

      public ItemBuilder addEnchantments(HashMap<String,Integer> enchants)
      Add multiple enchants at once.
      Parameters:
      enchants - The enchants to add.
      Returns:
      ItemBuilder
    • addEnchantments

      public ItemBuilder addEnchantments(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
      Add multiple enchants at once.
      Parameters:
      enchantments - The enchants to add.
      Returns:
      ItemBuilder
    • addGlow

      public ItemBuilder addGlow()
      Adds a glow effect to the item.
      Returns:
      this ItemBuilder
    • addItemFlag

      public ItemBuilder addItemFlag(String flag)
      Adds an item flag to the item.
      Parameters:
      flag - the flag name
      Returns:
      this ItemBuilder
    • addLoreLine

      public ItemBuilder addLoreLine(String line)
      Add a lore line.
      Parameters:
      line - The lore line to add.
      Returns:
      ItemBuilder
    • addLoreLine

      public ItemBuilder addLoreLine(String line, int pos)
      Add a lore line.
      Parameters:
      line - The lore line to add.
      pos - The index of where to put it.
      Returns:
      ItemBuilder
    • addPlaceholder

      public ItemBuilder addPlaceholder(HashMap<String,String> placeholders)
      Adds a placeholder mapping.
      Parameters:
      placeholders - the map of placeholders
      Returns:
      this ItemBuilder
    • addPlaceholder

      public ItemBuilder addPlaceholder(String toReplace, String replaceWith)
      Adds a single placeholder.
      Parameters:
      toReplace - the text to replace
      replaceWith - the replacement text
      Returns:
      this ItemBuilder
    • addPotionEffect

      public ItemBuilder addPotionEffect(org.bukkit.potion.PotionEffectType type, int duration, int amplifier, org.bukkit.Color color)
      Adds a potion effect to the item.
      Parameters:
      type - the potion effect type
      duration - the duration
      amplifier - the amplifier
      color - the potion color
      Returns:
      this ItemBuilder
    • clone

      public ItemBuilder clone()
      Clone the ItemBuilder into a new one.
      Overrides:
      clone in class Object
      Returns:
      The cloned instance.
    • createConfigurationData

      public LinkedHashMap<String,Object> createConfigurationData()
      Creates configuration data from this ItemBuilder.
      Returns:
      the configuration data map
    • dontCheckLoreLength

      public ItemBuilder dontCheckLoreLength()
      Disables lore length checking.
      Returns:
      this ItemBuilder
    • equals

      public boolean equals(Object ob)
      Overrides:
      equals in class Object
    • getAttributeModifiers

      public com.google.common.collect.Multimap<org.bukkit.attribute.Attribute,org.bukkit.attribute.AttributeModifier> getAttributeModifiers()
      Gets the attribute modifiers multimap.
      Returns:
      the attribute modifiers
    • getAttributeModifiers

      public Collection<org.bukkit.attribute.AttributeModifier> getAttributeModifiers(org.bukkit.attribute.Attribute att)
      Gets the attribute modifiers for a specific attribute.
      Parameters:
      att - the attribute
      Returns:
      the collection of attribute modifiers
    • getConditionItemBuilder

      public ItemBuilder getConditionItemBuilder(org.bukkit.OfflinePlayer player)
      Gets a conditional ItemBuilder based on player conditions.
      Parameters:
      player - the player
      Returns:
      the conditional ItemBuilder or this if no conditions match
    • getConfiguration

      public Map<String,Object> getConfiguration(boolean deseralize)
      Gets the configuration map.
      Parameters:
      deseralize - whether to deserialize the item
      Returns:
      the configuration map
    • hasGetItemModel

      public boolean hasGetItemModel(org.bukkit.inventory.meta.ItemMeta meta)
      Checks if the ItemMeta has getItemModel method.
      Parameters:
      meta - the item meta
      Returns:
      true if the method exists, false otherwise
    • getCustomData

      public String getCustomData(String key)
      Gets custom data from persistent data container.
      Parameters:
      key - the data key
      Returns:
      the custom data value
    • getLore

      public ArrayList<String> getLore()
      Gets the lore of the item.
      Returns:
      the lore list
    • getLoreLength

      public int getLoreLength()
      Gets the lore length setting.
      Returns:
      the lore length
    • getName

      public String getName()
      Gets the item name.
      Returns:
      the item name
    • getRewardsPath

      public String getRewardsPath(org.bukkit.entity.Player player)
      Gets the rewards path for the player.
      Parameters:
      player - the player
      Returns:
      the rewards path
    • getSkull

      @Deprecated public String getSkull()
      Deprecated.
      Returns:
      the skull
    • getSkullOwner

      public org.bukkit.OfflinePlayer getSkullOwner()
      Gets the skull owner.
      Returns:
      the skull owner
    • getType

      public org.bukkit.Material getType()
      Gets the item material type.
      Returns:
      the material
    • hasAttributes

      public boolean hasAttributes()
      Checks if the item has attributes.
      Returns:
      true if the item has attributes, false otherwise
    • hasCustomDisplayName

      public boolean hasCustomDisplayName()
      Checks if the item has a custom display name.
      Returns:
      true if the item has a custom display name, false otherwise
    • hasCustomLore

      public boolean hasCustomLore()
      Checks if the item has custom lore.
      Returns:
      true if the item has lore, false otherwise
    • hasItemMeta

      public boolean hasItemMeta()
      Checks if the item has item meta.
      Returns:
      true if the item has meta, false otherwise
    • parsePlaceholders

      public org.bukkit.inventory.ItemStack parsePlaceholders(org.bukkit.OfflinePlayer player)
      Parses placeholders in the item for the player.
      Parameters:
      player - the player
      Returns:
      the itemstack with parsed placeholders
    • removeEnchantment

      public ItemBuilder removeEnchantment(org.bukkit.enchantments.Enchantment ench)
      Remove a certain enchant from the item.
      Parameters:
      ench - The enchantment to remove
      Returns:
      ItemBuilder
    • removeLore

      public ItemBuilder removeLore()
      Removes all lore from the item.
      Returns:
      this ItemBuilder
    • removeLoreLine

      public ItemBuilder removeLoreLine(int index)
      Remove a lore line.
      Parameters:
      index - The index of the lore line to remove.
      Returns:
      ItemBuilder
    • removeLoreLine

      public ItemBuilder removeLoreLine(String line)
      Remove a lore line.
      Parameters:
      line - The lore to remove.
      Returns:
      ItemBuilder
    • setAmount

      public ItemBuilder setAmount(int amount)
      Sets the amount of items.
      Parameters:
      amount - the amount to set
      Returns:
      this ItemBuilder
    • setAmountNone

      public ItemBuilder setAmountNone(int i)
      Sets the amount only if current amount is zero.
      Parameters:
      i - the amount to set
      Returns:
      this ItemBuilder
    • setCustomData

      public ItemBuilder setCustomData(String key, String value)
      Sets custom data in the persistent data container.
      Parameters:
      key - the data key
      value - the data value
      Returns:
      this ItemBuilder
    • setCustomModelData

      public ItemBuilder setCustomModelData(int data)
      Sets the custom model data.
      Parameters:
      data - the custom model data
      Returns:
      this ItemBuilder
    • setDurability

      @Deprecated public ItemBuilder setDurability(short dur)
      Deprecated.
      Change the durability of the item.
      Parameters:
      dur - The durability to set it to.
      Returns:
      ItemBuilder
    • setDyeColor

      @Deprecated public ItemBuilder setDyeColor(org.bukkit.DyeColor color)
      Deprecated.
      Sets the dye color on an item. * Notice that this doesn't check for item type, sets the literal data of the dyecolor as durability.
      Parameters:
      color - The color to put.
      Returns:
      ItemBuilder
    • setFireworkPower

      public ItemBuilder setFireworkPower(int power)
      Sets the firework power.
      Parameters:
      power - the power level
      Returns:
      this ItemBuilder
    • setHeadFromBase64

      public ItemBuilder setHeadFromBase64(String value)
      Sets the skull head from base64 texture.
      Parameters:
      value - the base64 texture value
      Returns:
      this ItemBuilder
    • setInfinityDurability

      public ItemBuilder setInfinityDurability()
      Sets infinity durability on the item by setting the durability to Short.MAX_VALUE.
      Returns:
      ItemBuilder
    • setLeatherArmorColor

      public ItemBuilder setLeatherArmorColor(org.bukkit.Color color)
      Sets the armor color of a leather armor piece. Works only on leather armor pieces.
      Parameters:
      color - The color to set it to.
      Returns:
      ItemBuilder
    • setLore

      public ItemBuilder setLore(List<String> lore)
      Re-sets the lore.
      Parameters:
      lore - The lore to set it to.
      Returns:
      ItemBuilder
    • setLore

      public ItemBuilder setLore(String... lore)
      Re-sets the lore.
      Parameters:
      lore - The lore to set it to.
      Returns:
      ItemBuilder
    • setLoreLength

      public ItemBuilder setLoreLength(int length)
      Sets the lore length for wrapping.
      Parameters:
      length - the lore length
      Returns:
      this ItemBuilder
    • setName

      public ItemBuilder setName(String name)
      Set the displayname of the item.
      Parameters:
      name - The name to change it to.
      Returns:
      ItemBuilder
    • setNameIfNotExist

      public ItemBuilder setNameIfNotExist(String name)
      Sets the item name only if it doesn't already have a custom display name.
      Parameters:
      name - the name to set
      Returns:
      this ItemBuilder
    • setPlaceholders

      public ItemBuilder setPlaceholders(HashMap<String,String> placeholders)
      Sets the placeholder mappings.
      Parameters:
      placeholders - the placeholders map
      Returns:
      this ItemBuilder
    • setSkullOwner

      public ItemBuilder setSkullOwner(org.bukkit.OfflinePlayer offlinePlayer)
      Sets the skull owner by offline player.
      Parameters:
      offlinePlayer - the offline player
      Returns:
      this ItemBuilder
    • setSkullOwner

      @Deprecated public ItemBuilder setSkullOwner(String owner)
      Deprecated.
      Set the skull owner for the item. Works on skulls only.
      Parameters:
      owner - The name of the skull's owner.
      Returns:
      ItemBuilder
    • setSlot

      public ItemBuilder setSlot(int slot)
      Sets the slot for the item in an inventory.
      Parameters:
      slot - the slot number
      Returns:
      this ItemBuilder
    • setUnbreakable

      public ItemBuilder setUnbreakable(boolean unbreakable)
      Sets whether the item is unbreakable.
      Parameters:
      unbreakable - whether the item should be unbreakable
      Returns:
      this ItemBuilder
    • toItemStack

      @Deprecated public org.bukkit.inventory.ItemStack toItemStack()
      Deprecated.
      Use toItemStack(Player player)
      Retrieves the itemstack from the ItemBuilder.
      Returns:
      The itemstack created/modified by the ItemBuilder instance.
    • toItemStack

      public org.bukkit.inventory.ItemStack toItemStack(org.bukkit.OfflinePlayer player)
      Converts the ItemBuilder to an ItemStack with player-specific placeholders.
      Parameters:
      player - the offline player for placeholder replacement
      Returns:
      the final itemstack
    • toItemStack

      public org.bukkit.inventory.ItemStack toItemStack(org.bukkit.entity.Player player)
      Converts the ItemBuilder to an ItemStack with player-specific placeholders.
      Parameters:
      player - the player for placeholder replacement
      Returns:
      the final itemstack
    • toString

      public String toString()
      Overrides:
      toString in class Object