java.lang.Object
io.github.projectunified.craftitem.spigot.core.SpigotItem
All Implemented Interfaces:
Item

public class SpigotItem extends Object implements Item
Spigot-specific implementation of the Item interface. Wraps Bukkit's ItemStack and provides convenient modification methods.

Provides multiple constructors for flexibility and specialized methods for editing item metadata and the underlying ItemStack.

Example Usage:


 SpigotItem item = new SpigotItem(Material.DIAMOND_SWORD, playerUUID);
 item.setName("Legendary Sword");
 item.setAmount(1);
 item.editMeta(meta -> meta.setCustomModelData(1));
 ItemStack resultStack = item.getItemStack();
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new SpigotItem of STONE material with no owner.
    Creates a new SpigotItem of STONE material with the specified owner.
    SpigotItem(org.bukkit.inventory.ItemStack itemStack)
    Creates a new SpigotItem with the specified ItemStack and no owner.
    SpigotItem(org.bukkit.inventory.ItemStack itemStack, UUID owner)
    Creates a new SpigotItem with the specified ItemStack and owner.
    SpigotItem(org.bukkit.Material material)
    Creates a new SpigotItem with the specified Material type and no owner.
    SpigotItem(org.bukkit.Material material, UUID owner)
    Creates a new SpigotItem with the specified Material type and owner.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    edit(Consumer<org.bukkit.inventory.ItemStack> consumer)
    Allows direct modification of the ItemStack.
    <T extends org.bukkit.inventory.meta.ItemMeta>
    void
    editMeta(Class<T> metaClass, Consumer<T> consumer)
    Allows type-safe modification of specific ItemMeta subclasses.
    void
    editMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> consumer)
    Allows modification of the item's metadata.
    org.bukkit.inventory.ItemStack
    Gets the underlying ItemStack.
    Gets the UUID of the item's owner.
    void
    setAmount(int amount)
    Sets the stack amount of the item.
    void
    setItemStack(org.bukkit.inventory.ItemStack itemStack)
    Sets the underlying ItemStack (cloned to prevent external modifications).
    void
    Sets the display name of the item.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpigotItem

      public SpigotItem(org.bukkit.inventory.ItemStack itemStack, UUID owner)
      Creates a new SpigotItem with the specified ItemStack and owner.
      Parameters:
      itemStack - the ItemStack to wrap (will be cloned)
      owner - the UUID of the item's owner, or null
    • SpigotItem

      public SpigotItem(org.bukkit.inventory.ItemStack itemStack)
      Creates a new SpigotItem with the specified ItemStack and no owner.
      Parameters:
      itemStack - the ItemStack to wrap (will be cloned)
    • SpigotItem

      public SpigotItem(org.bukkit.Material material, UUID owner)
      Creates a new SpigotItem with the specified Material type and owner.
      Parameters:
      material - the Material type for the new ItemStack
      owner - the UUID of the item's owner, or null
    • SpigotItem

      public SpigotItem(org.bukkit.Material material)
      Creates a new SpigotItem with the specified Material type and no owner.
      Parameters:
      material - the Material type for the new ItemStack
    • SpigotItem

      public SpigotItem(UUID owner)
      Creates a new SpigotItem of STONE material with the specified owner.
      Parameters:
      owner - the UUID of the item's owner, or null
    • SpigotItem

      public SpigotItem()
      Creates a new SpigotItem of STONE material with no owner.
  • Method Details

    • getItemStack

      public org.bukkit.inventory.ItemStack getItemStack()
      Gets the underlying ItemStack.
      Returns:
      the ItemStack
    • setItemStack

      public void setItemStack(org.bukkit.inventory.ItemStack itemStack)
      Sets the underlying ItemStack (cloned to prevent external modifications).
      Parameters:
      itemStack - the new ItemStack
    • edit

      public void edit(Consumer<org.bukkit.inventory.ItemStack> consumer)
      Allows direct modification of the ItemStack.
      Parameters:
      consumer - the consumer to modify the ItemStack
    • editMeta

      public void editMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> consumer)
      Allows modification of the item's metadata.
      Parameters:
      consumer - the consumer to modify the ItemMeta
    • editMeta

      public <T extends org.bukkit.inventory.meta.ItemMeta> void editMeta(Class<T> metaClass, Consumer<T> consumer)
      Allows type-safe modification of specific ItemMeta subclasses.
      Type Parameters:
      T - the ItemMeta subclass type
      Parameters:
      metaClass - the class of the ItemMeta to modify
      consumer - the consumer to modify the metadata
    • setName

      public void setName(String name)
      Sets the display name of the item.
      Specified by:
      setName in interface Item
      Parameters:
      name - the new display name
    • setAmount

      public void setAmount(int amount)
      Sets the stack amount of the item.
      Specified by:
      setAmount in interface Item
      Parameters:
      amount - the stack size
    • getOwner

      public UUID getOwner()
      Gets the UUID of the item's owner.
      Specified by:
      getOwner in interface Item
      Returns:
      the owner's UUID, or null if no owner