Class ItemStackBuilder

java.lang.Object
de.maxbossing.maxapi.Builders.ItemStackBuilder

public class ItemStackBuilder extends Object
ItemStackBuilder
Author:
max
  • Constructor Details

    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.Material material)
      Constructs a new ItemStackBuilder with the specified material. If the material is null, it will default to Material.AIR.
      Parameters:
      material - the material for the ItemStack
    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.Material material, int amount)
      Constructs a new ItemStackBuilder with the specified material and amount. If the material is null, it will default to Material.AIR. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true.
      Parameters:
      material - the material for the ItemStack
      amount - the amount of the material for the ItemStack
    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.Material material, int amount, String displayname)
      Constructs a new ItemStackBuilder with the specified material, amount, and display name. If the material is null, it will default to Material.AIR. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true. The display name must not be null.
      Parameters:
      material - the material for the ItemStack
      amount - the amount of the material for the ItemStack
      displayname - the display name for the ItemStack
      Throws:
      NullPointerException - if the display name is null
    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.Material material, String displayname)
      Constructs a new ItemStackBuilder with the specified material and display name. If the material is null, it will default to Material.AIR. The display name must not be null.
      Parameters:
      material - the material for the ItemStack
      displayname - the display name for the ItemStack
      Throws:
      NullPointerException - if the display name is null
    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.inventory.ItemStack item)
      Constructs a new ItemStackBuilder with the specified ItemStack. The ItemStack must not be null. The new ItemStackBuilder will have the same material, amount, data, damage, enchantments, display name, lore, and flags as the original ItemStack.
      Parameters:
      item - the ItemStack to create a new ItemStackBuilder from
      Throws:
      NullPointerException - if the ItemStack is null
    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.configuration.file.FileConfiguration cfg, String path)
      Constructs a new ItemStackBuilder with the ItemStack from the specified path in the given FileConfiguration. The FileConfiguration must not be null. If the path is invalid or the ItemStack at the specified path is null, the ItemStackBuilder will default to a new ItemStack with Material.AIR.
      Parameters:
      cfg - the FileConfiguration to retrieve the ItemStack from
      path - the path in the FileConfiguration to the ItemStack
      Throws:
      NullPointerException - if the FileConfiguration is null
    • ItemStackBuilder

      @Deprecated public ItemStackBuilder(ItemStackBuilder builder)
      Deprecated.
      This constructor is deprecated and will be removed in a future version. Use the copy constructor instead.
      Constructs a new ItemStackBuilder with the properties of the specified ItemStackBuilder. The ItemStackBuilder must not be null.
      Parameters:
      builder - the ItemStackBuilder to copy the properties from
      Throws:
      NullPointerException - if the ItemStackBuilder is null
  • Method Details

    • amount

      public ItemStackBuilder amount(int amount)
      Sets the amount of the material for the ItemStack. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true.
      Parameters:
      amount - the amount of the material for the ItemStack
      Returns:
      the current ItemStackBuilder
    • data

      public ItemStackBuilder data(org.bukkit.material.MaterialData data)
      Sets the data for the ItemStack. The data must not be null.
      Parameters:
      data - the data for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the data is null
    • damage

      @Deprecated public ItemStackBuilder damage(short damage)
      Deprecated.
      This method is deprecated and will be removed in a future version. Use durability(short) instead.
      Sets the damage (durability) for the ItemStack.
      Parameters:
      damage - the damage for the ItemStack
      Returns:
      the current ItemStackBuilder
    • durability

      public ItemStackBuilder durability(short damage)
      Sets the durability (damage) for the ItemStack.
      Parameters:
      damage - the durability for the ItemStack
      Returns:
      the current ItemStackBuilder
    • material

      public ItemStackBuilder material(org.bukkit.Material material)
      Sets the material for the ItemStack. The material must not be null.
      Parameters:
      material - the material for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the material is null
    • meta

      public ItemStackBuilder meta(org.bukkit.inventory.meta.ItemMeta meta)
      Sets the meta data for the ItemStack. The meta data must not be null.
      Parameters:
      meta - the meta data for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the meta data is null
    • enchant

      public ItemStackBuilder enchant(org.bukkit.enchantments.Enchantment enchant, int level)
      Adds an Enchantment to the ItemStack.
      Parameters:
      enchant - the Enchantment to add to the ItemStack
      level - the level of the Enchantment
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the Enchantment is null
    • enchant

      public ItemStackBuilder enchant(Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
      Sets the Enchantments for the ItemStack. The enchantments must not be null.
      Parameters:
      enchantments - the enchantments for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the enchantments are null
    • displayname

      public ItemStackBuilder displayname(String displayname)
      Sets the display name for the ItemStack. The display name must not be null. If `andSymbol` is set to true, the display name will be formatted
      Parameters:
      displayname - the display name for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the display name is null
    • lore

      public ItemStackBuilder lore(String line)
      Adds a line of lore to the ItemStack. The line of lore must not be null. If `andSymbol` is set to true, the line of lore will be formatted.
      Parameters:
      line - the line of lore to add to the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the line of lore is null
    • lore

      public ItemStackBuilder lore(List<String> lore)
      Sets the lore for the ItemStack. The lore must not be null. If `andSymbol` is set to true, the lines of lore will be formatted.
      Parameters:
      lore - the lore for the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the lore is null
    • lores

      @Deprecated public ItemStackBuilder lores(String... lines)
      Deprecated.
      Use ItemBuilder#lore
      Adds one or more Lines to the Lore of the ItemStack
      Parameters:
      lines - One or more Strings for the ItemStack Lore
      Returns:
      the current ItemStackBuilder
    • lore

      public ItemStackBuilder lore(String... lines)
      Deprecated.
      use lore(String) instead
      Adds lines of lore to the ItemStack. The lines of lore must not be null. If `andSymbol` is set to true, the lines of lore will be formatted.
      Parameters:
      lines - the lines of lore to add to the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the lines of lore are null
    • lore

      public ItemStackBuilder lore(String line, int index)
      Sets a line of lore at a specific index in the ItemStack. The line of lore must not be null. If `andSymbol` is set to true, the line of lore will be formatted.
      Parameters:
      line - the line of lore to set in the ItemStack
      index - the index in the lore list to set the line of lore
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the line of lore is null
      IndexOutOfBoundsException - if the index is out of range
    • flag

      public ItemStackBuilder flag(org.bukkit.inventory.ItemFlag flag)
      Adds an ItemFlag to the ItemStack. The item flag must not be null.
      Parameters:
      flag - the item flag to add to the ItemStack
      Returns:
      the current ItemStackBuilder
      Throws:
      NullPointerException - if the item flag is null
    • flag

      public ItemStackBuilder flag(List<org.bukkit.inventory.ItemFlag> flags)
      Sets the flags for the item stack.
      Parameters:
      flags - the flags to set for the item stack
      Returns:
      the current ItemStackBuilder instance
      Throws:
      NullPointerException - if the flags list is null
    • unbreakable

      public ItemStackBuilder unbreakable(boolean unbreakable)
      Sets the unbreakable status for the item stack.
      Parameters:
      unbreakable - whether the item stack should be unbreakable or not
      Returns:
      the current ItemStackBuilder instance
    • glow

      public ItemStackBuilder glow()
      Adds a glowing effect to the item stack.
      Returns:
      the current ItemStackBuilder instance
    • unsafe

      public ItemStackBuilder.Unsafe unsafe()
      Returns an Unsafe instance for the item stack builder, which contains the nbt methods.
      Returns:
      an Unsafe instance for the item stack builder
    • replaceAndSymbol

      @Deprecated public ItemStackBuilder replaceAndSymbol()
      Deprecated.
      Deprecated. Use replaceAndSymbol(boolean) instead.
      Returns:
      the current ItemStackBuilder instance
    • replaceAndSymbol

      public ItemStackBuilder replaceAndSymbol(boolean replace)
      Sets whether to replace the and symbol with the section symbol (§).
      Parameters:
      replace - whether to replace the and symbol or not
      Returns:
      the current ItemStackBuilder instance
    • toggleReplaceAndSymbol

      public ItemStackBuilder toggleReplaceAndSymbol()
      Toggles the replacement of the and symbol with the section symbol (§).
      Returns:
      the current ItemStackBuilder instance
    • unsafeStackSize

      public ItemStackBuilder unsafeStackSize(boolean allow)
      Enables or disables the use of stack sizes larger than the maximum stack size for the item.
      Parameters:
      allow - whether to allow unsafe stack sizes or not
      Returns:
      the current ItemStackBuilder instance
    • toggleUnsafeStackSize

      public ItemStackBuilder toggleUnsafeStackSize()
      Toggles the use of stack sizes larger than the maximum stack size for the item.
      Returns:
      the current ItemStackBuilder instance
    • getDisplayname

      public String getDisplayname()
      Returns the display name of the item stack.
      Returns:
      the display name of the item stack
    • getAmount

      public int getAmount()
      Returns the stack size of the item stack.
      Returns:
      the stack size of the item stack
    • getEnchantments

      public Map<org.bukkit.enchantments.Enchantment,Integer> getEnchantments()
      Returns the enchantments and their levels for the item stack.
      Returns:
      the enchantments and their levels for the item stack
    • getDamage

      @Deprecated public short getDamage()
      Deprecated.
      Deprecated. Use getDurability() instead.
      Returns:
      the durability of the item stack
    • getDurability

      public short getDurability()
      Returns the durability of the item stack.
      Returns:
      the durability of the item stack
    • getLores

      public List<String> getLores()
      Returns the lore lines for the item stack.
      Returns:
      the lore lines for the item stack
    • getAndSymbol

      public boolean getAndSymbol()
      Returns whether the and symbol is replaced with the section symbol (§).
      Returns:
      true if the and symbol is replaced, false otherwise
    • getFlags

      public List<org.bukkit.inventory.ItemFlag> getFlags()
      Returns the flags for the item stack.
      Returns:
      the flags for the item stack
    • getMaterial

      public org.bukkit.Material getMaterial()
      Returns the material of the item stack.
      Returns:
      the material of the item stack
    • getMeta

      public org.bukkit.inventory.meta.ItemMeta getMeta()
      Returns the item meta of the item stack.
      Returns:
      the item meta of the item stack
    • getData

      @Deprecated public org.bukkit.material.MaterialData getData()
      Deprecated.
      Deprecated. MaterialData is subject to removal instead.
      Returns:
      the material data of the item stack
    • getLore

      @Deprecated public List<String> getLore()
      Deprecated.
      Deprecated. Use getLores() instead.
      Returns:
      the lore lines for the item stack
    • toConfig

      public ItemStackBuilder toConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path)
      Saves the item stack to a configuration file at the specified path.
      Parameters:
      cfg - the configuration file to save to
      path - the path to save the item stack at
      Returns:
      the current ItemStackBuilder instance
    • fromConfig

      public ItemStackBuilder fromConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path)
      Loads the item stack from a configuration file at the specified path.
      Parameters:
      cfg - the configuration file to load from
      path - the path to load the item stack from
      Returns:
      a new ItemStackBuilder instance with the loaded item stack
    • toConfig

      public static void toConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path, ItemStackBuilder builder)
      Saves the item stack to a configuration file at the specified path.
      Parameters:
      cfg - the configuration file to save to
      path - the path to save the item stack at
      builder - the item stack builder to save
    • toJson

      public String toJson()
      Returns the item stack as a JSON string.
      Returns:
      the item stack as a JSON string
    • toJson

      public static String toJson(ItemStackBuilder builder)
      Returns the item stack as a JSON string.
      Parameters:
      builder - the item stack builder to convert to a JSON string
      Returns:
      the item stack as a JSON string
    • fromJson

      public static ItemStackBuilder fromJson(String json)
      Returns an item stack builder from a JSON string.
      Parameters:
      json - the JSON string to convert to an item stack builder
      Returns:
      an item stack builder from the JSON string
    • applyJson

      public ItemStackBuilder applyJson(String json, boolean overwrite)
      Applies the properties of an item stack builder from a JSON string to the current builder.
      Parameters:
      json - the JSON string to apply to the current builder
      overwrite - whether to overwrite the current builder's properties or not
      Returns:
      the current ItemStackBuilder instance
    • build

      public org.bukkit.inventory.ItemStack build()
      Builds the item stack using the current builder's properties.
      Returns:
      the built item stack