Bukkit  1.6.4-R2.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
org.bukkit.inventory.ItemStack Class Reference

Represents a stack of items. More...

+ Inheritance diagram for org.bukkit.inventory.ItemStack:
+ Collaboration diagram for org.bukkit.inventory.ItemStack:

Public Member Functions

 ItemStack (final int type)
 Defaults stack size to 1, with no extra data.
 
 ItemStack (final Material type)
 Defaults stack size to 1, with no extra data.
 
 ItemStack (final int type, final int amount)
 An item stack with no extra data.
 
 ItemStack (final Material type, final int amount)
 An item stack with no extra data.
 
 ItemStack (final int type, final int amount, final short damage)
 An item stack with the specified damage / durability.
 
 ItemStack (final Material type, final int amount, final short damage)
 An item stack with the specified damage / durabiltiy.
 
 ItemStack (final int type, final int amount, final short damage, final Byte data)
 
 ItemStack (final Material type, final int amount, final short damage, final Byte data)
 
 ItemStack (final ItemStack stack) throws IllegalArgumentException
 Creates a new item stack derived from the specified stack.
 
Material getType ()
 Gets the type of this item.
 
void setType (Material type)
 Sets the type of this item.
 
int getTypeId ()
 Gets the type id of this item.
 
void setTypeId (int type)
 Sets the type id of this item.
 
int getAmount ()
 Gets the amount of items in this stack.
 
void setAmount (int amount)
 Sets the amount of items in this stack.
 
MaterialData getData ()
 Gets the MaterialData for this stack of items.
 
void setData (MaterialData data)
 Sets the MaterialData for this stack of items.
 
void setDurability (final short durability)
 Sets the durability of this item.
 
short getDurability ()
 Gets the durability of this item.
 
int getMaxStackSize ()
 Get the maximum stacksize for the material hold in this ItemStack Returns -1 if it has no idea.
 
String toString ()
 
boolean equals (Object obj)
 
boolean isSimilar (ItemStack stack)
 This method is the same as equals, but does not consider stack size (amount).
 
ItemStack clone ()
 
final int hashCode ()
 
boolean containsEnchantment (Enchantment ench)
 Checks if this ItemStack contains the given Enchantment.
 
int getEnchantmentLevel (Enchantment ench)
 Gets the level of the specified enchantment on this item stack.
 
Map< Enchantment, Integer > getEnchantments ()
 Gets a map containing all enchantments and their levels on this item.
 
void addEnchantments (Map< Enchantment, Integer > enchantments)
 Adds the specified enchantments to this item stack.
 
void addEnchantment (Enchantment ench, int level)
 Adds the specified Enchantment to this item stack.
 
void addUnsafeEnchantments (Map< Enchantment, Integer > enchantments)
 Adds the specified enchantments to this item stack in an unsafe manner.
 
void addUnsafeEnchantment (Enchantment ench, int level)
 Adds the specified Enchantment to this item stack.
 
int removeEnchantment (Enchantment ench)
 Removes the specified Enchantment if it exists on this item stack.
 
Map< String, Object > serialize ()
 
ItemMeta getItemMeta ()
 Get a copy of this ItemStack's ItemMeta.
 
boolean hasItemMeta ()
 Checks to see if any meta data has been defined.
 
boolean setItemMeta (ItemMeta itemMeta)
 Set the ItemMeta of this ItemStack.
 
- Public Member Functions inherited from org.bukkit.configuration.serialization.ConfigurationSerializable
Map< String, Object > serialize ()
 Creates a Map representation of this class.
 

Static Public Member Functions

static ItemStack deserialize (Map< String, Object > args)
 Required method for configuration serialization.
 

Protected Member Functions

 ItemStack ()
 

Detailed Description

Represents a stack of items.

Definition at line 19 of file ItemStack.java.

Constructor & Destructor Documentation

org.bukkit.inventory.ItemStack.ItemStack ( )
protected
org.bukkit.inventory.ItemStack.ItemStack ( final int  type)

Defaults stack size to 1, with no extra data.

Parameters
typeitem material id
Deprecated:
Magic value

Definition at line 36 of file ItemStack.java.

org.bukkit.inventory.ItemStack.ItemStack ( final Material  type)

Defaults stack size to 1, with no extra data.

Parameters
typeitem material

Definition at line 45 of file ItemStack.java.

org.bukkit.inventory.ItemStack.ItemStack ( final int  type,
final int  amount 
)

An item stack with no extra data.

Parameters
typeitem material id
amountstack size
Deprecated:
Magic value

Definition at line 57 of file ItemStack.java.

org.bukkit.inventory.ItemStack.ItemStack ( final Material  type,
final int  amount 
)

An item stack with no extra data.

Parameters
typeitem material
amountstack size

Definition at line 67 of file ItemStack.java.

References org.bukkit.Material.getId().

org.bukkit.inventory.ItemStack.ItemStack ( final int  type,
final int  amount,
final short  damage 
)

An item stack with the specified damage / durability.

Parameters
typeitem material id
amountstack size
damagedurability / damage
Deprecated:
Magic value

Definition at line 80 of file ItemStack.java.

org.bukkit.inventory.ItemStack.ItemStack ( final Material  type,
final int  amount,
final short  damage 
)

An item stack with the specified damage / durabiltiy.

Parameters
typeitem material
amountstack size
damagedurability / damage

Definition at line 93 of file ItemStack.java.

References org.bukkit.Material.getId().

org.bukkit.inventory.ItemStack.ItemStack ( final int  type,
final int  amount,
final short  damage,
final Byte  data 
)
Deprecated:
this method uses an ambiguous data byte object

Definition at line 101 of file ItemStack.java.

org.bukkit.inventory.ItemStack.ItemStack ( final Material  type,
final int  amount,
final short  damage,
final Byte  data 
)
Deprecated:
this method uses an ambiguous data byte object

Definition at line 115 of file ItemStack.java.

References org.bukkit.Material.getId().

org.bukkit.inventory.ItemStack.ItemStack ( final ItemStack  stack) throws IllegalArgumentException

Creates a new item stack derived from the specified stack.

Parameters
stackthe stack to copy
Exceptions
IllegalArgumentExceptionif the specified stack is null or returns an item meta not created by the item factory

Definition at line 125 of file ItemStack.java.

References org.bukkit.material.MaterialData.getData().

Member Function Documentation

void org.bukkit.inventory.ItemStack.addEnchantment ( Enchantment  ench,
int  level 
)

Adds the specified Enchantment to this item stack.

If this item stack already contained the given enchantment (at any level), it will be replaced.

Parameters
enchEnchantment to add
levelLevel of the enchantment
Exceptions
IllegalArgumentExceptionif enchantment null, or enchantment is not applicable

Definition at line 421 of file ItemStack.java.

References org.bukkit.inventory.ItemStack.addUnsafeEnchantment(), org.bukkit.enchantments.Enchantment.canEnchantItem(), org.bukkit.enchantments.Enchantment.getMaxLevel(), and org.bukkit.enchantments.Enchantment.getStartLevel().

Referenced by org.bukkit.inventory.ItemStack.addEnchantments().

void org.bukkit.inventory.ItemStack.addEnchantments ( Map< Enchantment, Integer >  enchantments)

Adds the specified enchantments to this item stack.

This method is the same as calling addEnchantment(org.bukkit.enchantments.Enchantment, int) for each element of the map.

Parameters
enchantmentsEnchantments to add
Exceptions
IllegalArgumentExceptionif the specified enchantments is null
IllegalArgumentExceptionif any specific enchantment or level is null. Warning: Some enchantments may be added before this exception is thrown.

Definition at line 404 of file ItemStack.java.

References org.bukkit.inventory.ItemStack.addEnchantment().

void org.bukkit.inventory.ItemStack.addUnsafeEnchantment ( Enchantment  ench,
int  level 
)

Adds the specified Enchantment to this item stack.

If this item stack already contained the given enchantment (at any level), it will be replaced.

This method is unsafe and will ignore level restrictions or item type. Use at your own discretion.

Parameters
enchEnchantment to add
levelLevel of the enchantment

Definition at line 458 of file ItemStack.java.

References org.bukkit.Bukkit.getItemFactory(), and org.bukkit.inventory.ItemFactory.getItemMeta().

Referenced by org.bukkit.inventory.ItemStack.addEnchantment(), org.bukkit.inventory.ItemStack.addUnsafeEnchantments(), org.bukkit.inventory.ItemStack.deserialize(), and org.bukkit.command.defaults.EnchantCommand.execute().

void org.bukkit.inventory.ItemStack.addUnsafeEnchantments ( Map< Enchantment, Integer >  enchantments)

Adds the specified enchantments to this item stack in an unsafe manner.

This method is the same as calling addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int) for each element of the map.

Parameters
enchantmentsEnchantments to add

Definition at line 441 of file ItemStack.java.

References org.bukkit.inventory.ItemStack.addUnsafeEnchantment().

boolean org.bukkit.inventory.ItemStack.containsEnchantment ( Enchantment  ench)

Checks if this ItemStack contains the given Enchantment.

Parameters
enchEnchantment to test
Returns
True if this has the given enchantment

Definition at line 369 of file ItemStack.java.

References org.bukkit.inventory.meta.ItemMeta.hasEnchant().

static ItemStack org.bukkit.inventory.ItemStack.deserialize ( Map< String, Object >  args)
static

Required method for configuration serialization.

Parameters
argsmap to deserialize
Returns
deserialized item stack
See Also
ConfigurationSerializable

Definition at line 506 of file ItemStack.java.

References org.bukkit.inventory.ItemStack.addUnsafeEnchantment(), org.bukkit.enchantments.Enchantment.getByName(), org.bukkit.Material.getMaterial(), org.bukkit.inventory.ItemStack.ItemStack(), and org.bukkit.inventory.ItemStack.setItemMeta().

boolean org.bukkit.inventory.ItemStack.equals ( Object  obj)
int org.bukkit.inventory.ItemStack.getAmount ( )

Gets the amount of items in this stack.

Returns
Amount of items in this stick

Definition at line 201 of file ItemStack.java.

Referenced by org.bukkit.inventory.ItemStack.equals(), org.bukkit.inventory.ItemStack.hashCode(), org.bukkit.inventory.ItemStack.serialize(), and org.bukkit.inventory.ItemStack.toString().

MaterialData org.bukkit.inventory.ItemStack.getData ( )

Gets the MaterialData for this stack of items.

Returns
MaterialData for this item

Definition at line 219 of file ItemStack.java.

References org.bukkit.Material.getData(), org.bukkit.inventory.ItemStack.getDurability(), org.bukkit.Material.getNewData(), and org.bukkit.inventory.ItemStack.getType().

int org.bukkit.inventory.ItemStack.getEnchantmentLevel ( Enchantment  ench)

Gets the level of the specified enchantment on this item stack.

Parameters
enchEnchantment to check
Returns
Level of the enchantment, or 0

Definition at line 379 of file ItemStack.java.

References org.bukkit.inventory.meta.ItemMeta.getEnchantLevel().

Referenced by org.bukkit.inventory.ItemStack.removeEnchantment().

Map<Enchantment, Integer> org.bukkit.inventory.ItemStack.getEnchantments ( )

Gets a map containing all enchantments and their levels on this item.

Returns
Map of enchantments.

Definition at line 388 of file ItemStack.java.

References org.bukkit.inventory.meta.ItemMeta.getEnchants().

Referenced by org.bukkit.command.defaults.EnchantCommand.execute().

int org.bukkit.inventory.ItemStack.getMaxStackSize ( )

Get the maximum stacksize for the material hold in this ItemStack Returns -1 if it has no idea.

Returns
The maximum you can stack this material to.

Definition at line 272 of file ItemStack.java.

References org.bukkit.Material.getMaxStackSize(), and org.bukkit.inventory.ItemStack.getType().

int org.bukkit.inventory.ItemStack.getTypeId ( )

Gets the type id of this item.

Returns
Type Id of the items in this stack
Deprecated:
Magic value

Definition at line 175 of file ItemStack.java.

Referenced by org.bukkit.inventory.ItemStack.getType(), org.bukkit.inventory.ItemStack.hashCode(), and org.bukkit.inventory.ItemStack.isSimilar().

boolean org.bukkit.inventory.ItemStack.hasItemMeta ( )

Checks to see if any meta data has been defined.

Returns
Returns true if some meta data has been set for this item

Definition at line 559 of file ItemStack.java.

References org.bukkit.inventory.ItemFactory.equals(), and org.bukkit.Bukkit.getItemFactory().

Referenced by org.bukkit.inventory.ItemStack.hashCode(), org.bukkit.inventory.ItemStack.isSimilar(), and org.bukkit.inventory.ItemStack.toString().

boolean org.bukkit.inventory.ItemStack.isSimilar ( ItemStack  stack)

This method is the same as equals, but does not consider stack size (amount).

Parameters
stackthe item stack to compare to
Returns
true if the two stacks are equal, ignoring the amount

Definition at line 321 of file ItemStack.java.

References org.bukkit.inventory.ItemFactory.equals(), org.bukkit.inventory.ItemStack.getDurability(), org.bukkit.Bukkit.getItemFactory(), org.bukkit.inventory.ItemStack.getItemMeta(), org.bukkit.inventory.ItemStack.getTypeId(), and org.bukkit.inventory.ItemStack.hasItemMeta().

Referenced by org.bukkit.inventory.ItemStack.equals().

int org.bukkit.inventory.ItemStack.removeEnchantment ( Enchantment  ench)

Removes the specified Enchantment if it exists on this item stack.

Parameters
enchEnchantment to remove
Returns
Previous level, or 0

Definition at line 468 of file ItemStack.java.

References org.bukkit.inventory.ItemStack.getEnchantmentLevel(), and org.bukkit.inventory.meta.ItemMeta.removeEnchant().

Referenced by org.bukkit.command.defaults.EnchantCommand.execute().

void org.bukkit.inventory.ItemStack.setAmount ( int  amount)

Sets the amount of items in this stack.

Parameters
amountNew amount of items in this stack

Definition at line 210 of file ItemStack.java.

void org.bukkit.inventory.ItemStack.setData ( MaterialData  data)

Sets the MaterialData for this stack of items.

Parameters
dataNew MaterialData for this item

Definition at line 233 of file ItemStack.java.

References org.bukkit.Material.getData(), and org.bukkit.inventory.ItemStack.getType().

void org.bukkit.inventory.ItemStack.setDurability ( final short  durability)

Sets the durability of this item.

Parameters
durabilityDurability of this item

Definition at line 252 of file ItemStack.java.

Referenced by org.bukkit.potion.Potion.apply().

boolean org.bukkit.inventory.ItemStack.setItemMeta ( ItemMeta  itemMeta)

Set the ItemMeta of this ItemStack.

Parameters
itemMetanew ItemMeta, or null to indicate meta data be cleared.
Returns
True if successfully applied ItemMeta, see ItemFactory#isApplicable(ItemMeta, ItemStack)
Exceptions
IllegalArgumentExceptionif the item meta was not created by the ItemFactory

Definition at line 570 of file ItemStack.java.

Referenced by org.bukkit.inventory.ItemStack.deserialize().

void org.bukkit.inventory.ItemStack.setType ( Material  type)

Sets the type of this item.

Note that in doing so you will reset the MaterialData for this stack

Parameters
typeNew type to set the items in this stack to

Definition at line 163 of file ItemStack.java.

References org.bukkit.Material.getId(), and org.bukkit.inventory.ItemStack.setTypeId().

void org.bukkit.inventory.ItemStack.setTypeId ( int  type)

Sets the type id of this item.

Note that in doing so you will reset the MaterialData for this stack

Parameters
typeNew type id to set the items in this stack to
Deprecated:
Magic value

Definition at line 188 of file ItemStack.java.

References org.bukkit.inventory.ItemFactory.asMetaFor(), and org.bukkit.Bukkit.getItemFactory().

Referenced by org.bukkit.inventory.ItemStack.setType().


The documentation for this class was generated from the following file: