Class SpigotItem
java.lang.Object
io.github.projectunified.craftitem.spigot.core.SpigotItem
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionCreates a new SpigotItem of STONE material with no owner.SpigotItem(UUID 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 TypeMethodDescriptionvoidAllows direct modification of the ItemStack.<T extends org.bukkit.inventory.meta.ItemMeta>
voidAllows type-safe modification of specific ItemMeta subclasses.voidAllows modification of the item's metadata.org.bukkit.inventory.ItemStackGets the underlying ItemStack.getOwner()Gets the UUID of the item's owner.voidsetAmount(int amount) Sets the stack amount of the item.voidsetItemStack(org.bukkit.inventory.ItemStack itemStack) Sets the underlying ItemStack (cloned to prevent external modifications).voidSets the display name of the item.
-
Constructor Details
-
SpigotItem
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
Creates a new SpigotItem with the specified Material type and owner.- Parameters:
material- the Material type for the new ItemStackowner- 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
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
Allows direct modification of the ItemStack.- Parameters:
consumer- the consumer to modify the ItemStack
-
editMeta
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 modifyconsumer- the consumer to modify the metadata
-
setName
Sets the display name of the item. -
setAmount
public void setAmount(int amount) Sets the stack amount of the item. -
getOwner
Gets the UUID of the item's owner.
-