Class ItemCreator

java.lang.Object
com.github.pinont.singularitylib.api.items.ItemCreator
Direct Known Subclasses:
CrossbowCreator, ItemHeadCreator

public class ItemCreator extends Object
Builder class for creating and modifying ItemStacks with enhanced functionality. Provides a fluent API for setting item properties, adding enchantments, lore, tags, and interactions.
  • Constructor Details

    • ItemCreator

      public ItemCreator(org.bukkit.plugin.Plugin plugin, org.bukkit.Material type)
      Creates a new ItemCreator for the specified material type.
      Parameters:
      type - the material type for the item
    • ItemCreator

      public ItemCreator(org.bukkit.plugin.Plugin plugin, org.bukkit.Material type, int amount)
      Creates a new ItemCreator for the specified material type and amount.
      Parameters:
      type - the material type for the item
      amount - the amount of items in the stack
    • ItemCreator

      public ItemCreator(org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Creates a new ItemCreator from an existing ItemStack.
      Parameters:
      item - the ItemStack to create from
  • Method Details

    • getInteractions

      public static Set<ItemInteraction> getInteractions()
      Gets all registered item interactions.
      Returns:
      set of all item interactions
    • clone

      public ItemCreator clone()
      Overrides:
      clone in class Object
    • getName

      public String getName()
      Gets the display name of the item.
      Returns:
      the display name
    • getItemMeta

      public org.bukkit.inventory.meta.ItemMeta getItemMeta()
      Gets the ItemMeta of the item.
      Returns:
      the ItemMeta
    • getType

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

      public int getAmount()
      Gets the amount of items in the stack.
      Returns:
      the amount
    • create

      public org.bukkit.inventory.ItemStack create()
      Creates the final ItemStack with all applied properties.
      Returns:
      the created ItemStack
    • hasTag

      public Boolean hasTag(String tag)
      Checks if the item has a specific tag.
      Parameters:
      tag - the tag to check for
      Returns:
      true if the item has the tag, false otherwise
    • getKey

      public String getKey(String key)
      Gets the value of a specific key from the item's tags.
      Parameters:
      key - the key to get the value for
      Returns:
      the value associated with the key
    • addLore

      public ItemCreator addLore(String lore)
      Adds lore to the item.
      Parameters:
      lore - the lore text to add
      Returns:
      this ItemCreator for method chaining
    • setItemMeta

      public ItemCreator setItemMeta(org.bukkit.inventory.meta.ItemMeta meta)
      Sets the ItemMeta for the item.
      Parameters:
      meta - the ItemMeta to set
      Returns:
      this ItemCreator for method chaining
    • setType

      public ItemCreator setType(org.bukkit.Material type)
      Sets the material type of the item.
      Parameters:
      type - the material type to set
      Returns:
      this ItemCreator for method chaining
    • addItemFlag

      public ItemCreator addItemFlag(org.bukkit.inventory.ItemFlag... flags)
      Adds item flags to hide certain item properties.
      Parameters:
      flags - the item flags to add
      Returns:
      this ItemCreator for method chaining
    • setCannotMove

      public ItemCreator setCannotMove(boolean b)
      Sets whether the item can be moved in inventories.
      Parameters:
      b - true if the item cannot be moved, false otherwise
      Returns:
      this ItemCreator for method chaining
    • setAmount

      public ItemCreator setAmount(int amount)
      Sets the amount of items in the stack.
      Parameters:
      amount - the amount to set
      Returns:
      this ItemCreator for method chaining
    • setName

      public ItemCreator setName(@Nullable @Nullable String name)
      Sets the display name of the item.
      Parameters:
      name - the display name to set
      Returns:
      this ItemCreator for method chaining
    • setName

      public ItemCreator setName(@Nullable @Nullable net.kyori.adventure.text.Component name)
      Sets the display name of the item using a Component.
      Parameters:
      name - the Component display name to set
      Returns:
      this ItemCreator for method chaining
    • setDurability

      public ItemCreator setDurability(short durability)
      Sets the durability of the item.
      Parameters:
      durability - the durability value
      Returns:
      this ItemCreator for method chaining
    • setUnbreakable

      public ItemCreator setUnbreakable(boolean unbreakable)
      Sets whether the item is unbreakable.
      Parameters:
      unbreakable - true if the item should be unbreakable, false otherwise
      Returns:
      this ItemCreator for method chaining
    • addEnchant

      public ItemCreator addEnchant(org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelRestriction)
      Adds an enchantment to the item.
      Parameters:
      enchantment - the enchantment to add
      level - the level of the enchantment
      ignoreLevelRestriction - whether to ignore level restrictions
      Returns:
      this ItemCreator for method chaining
    • addLore

      public ItemCreator addLore(String... lores)
      Adds lore to the item.
      Parameters:
      lores - the lore texts to add
      Returns:
      this ItemCreator for method chaining
    • addLore

      public ItemCreator addLore(net.kyori.adventure.text.Component... lores)
      Adds lore to the item.
      Parameters:
      lores - the lore Components to add
      Returns:
      this ItemCreator for method chaining
    • addAttribute

      public ItemCreator addAttribute(AttributeType attributeType, double amount, org.bukkit.attribute.AttributeModifier.Operation operation, org.bukkit.inventory.EquipmentSlot slot)
      Adds an attribute modifier to the item.
      Parameters:
      attributeType - the type of the attribute to modify
      amount - the amount to modify the attribute by
      operation - the operation to perform (addition, multiplication, etc.)
      slot - the equipment slot this modifier applies to
      Returns:
      this ItemCreator for method chaining
    • setUnstackable

      public ItemCreator setUnstackable(boolean bool)
      Sets the item as unstackable.
      Parameters:
      bool - true to make the item unstackable, false otherwise
      Returns:
      this ItemCreator for method chaining
    • setModelData

      public ItemCreator setModelData(int data)
      Sets the custom model data for the item.
      Parameters:
      data - the custom model data value
      Returns:
      this ItemCreator for method chaining
    • addTags

      public ItemCreator addTags(String... tags)
      Adds tags to the item.
      Parameters:
      tags - the tags to add
      Returns:
      this ItemCreator for method chaining
    • addTag

      public ItemCreator addTag(String key)
      Adds a single tag to the item.
      Parameters:
      key - the key of the tag to add
      Returns:
      this ItemCreator for method chaining
    • addTag

      public ItemCreator addTag(String key, String value)
      Adds a tag with a specific value to the item.
      Parameters:
      key - the key of the tag to add
      value - the value of the tag
      Returns:
      this ItemCreator for method chaining
    • replaceTag

      public ItemCreator replaceTag(String oldKey, String newKey)
      Replaces an existing tag with a new key.
      Parameters:
      oldKey - the current key of the tag
      newKey - the new key to replace with
      Returns:
      this ItemCreator for method chaining
    • getTagValue

      public String getTagValue(String key)
      Gets the value of a specific tag.
      Parameters:
      key - the key of the tag to get the value from
      Returns:
      the value of the tag, or null if not present
    • setTagValue

      public ItemCreator setTagValue(String key, String newValue)
      Sets the value of a specific tag.
      Parameters:
      key - the key of the tag to set the value for
      newValue - the new value to set
      Returns:
      this ItemCreator for method chaining
    • removeTag

      public ItemCreator removeTag(String tag)
      Removes a tag from the item.
      Parameters:
      tag - the tag to remove
      Returns:
      this ItemCreator for method chaining
    • setDurability

      public ItemCreator setDurability(int durability)
      Sets the durability of the item.
      Parameters:
      durability - the durability value
      Returns:
      this ItemCreator for method chaining
    • setDataContainer

      public ItemCreator setDataContainer(String key, Object value, PersistType type)
      Sets data in the item's PersistentDataContainer.
      Parameters:
      key - the key of the data to set
      value - the value to set
      type - the type of the data
      Returns:
      this ItemCreator for method chaining
    • addInteraction

      public ItemCreator addInteraction(ItemInteraction itemInteraction)
      Adds an interaction to the item.
      Parameters:
      itemInteraction - the ItemInteraction to add
      Returns:
      this ItemCreator for method chaining