Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.inventory.Inventory Interface Reference
Inheritance diagram for org.bukkit.inventory.Inventory:
org.bukkit.inventory.AnvilInventory org.bukkit.inventory.BeaconInventory org.bukkit.inventory.BrewerInventory org.bukkit.inventory.CraftingInventory org.bukkit.inventory.DoubleChestInventory org.bukkit.inventory.EnchantingInventory org.bukkit.inventory.FurnaceInventory org.bukkit.inventory.HorseInventory org.bukkit.inventory.MerchantInventory org.bukkit.inventory.PlayerInventory

Public Member Functions

int getSize ()
 
int getMaxStackSize ()
 
void setMaxStackSize (int size)
 
String getName ()
 
ItemStack getItem (int index)
 
void setItem (int index, ItemStack item)
 
HashMap< Integer, ItemStackaddItem (ItemStack...items) throws IllegalArgumentException
 
HashMap< Integer, ItemStackremoveItem (ItemStack...items) throws IllegalArgumentException
 
ItemStack[] getContents ()
 
void setContents (ItemStack[] items) throws IllegalArgumentException
 
boolean contains (int materialId)
 
boolean contains (Material material) throws IllegalArgumentException
 
boolean contains (ItemStack item)
 
boolean contains (int materialId, int amount)
 
boolean contains (Material material, int amount) throws IllegalArgumentException
 
boolean contains (ItemStack item, int amount)
 
boolean containsAtLeast (ItemStack item, int amount)
 
HashMap< Integer,?extends ItemStackall (int materialId)
 
HashMap< Integer,?extends ItemStackall (Material material) throws IllegalArgumentException
 
HashMap< Integer,?extends ItemStackall (ItemStack item)
 
int first (int materialId)
 
int first (Material material) throws IllegalArgumentException
 
int first (ItemStack item)
 
int firstEmpty ()
 
void remove (int materialId)
 
void remove (Material material) throws IllegalArgumentException
 
void remove (ItemStack item)
 
void clear (int index)
 
void clear ()
 
List< HumanEntitygetViewers ()
 
String getTitle ()
 
InventoryType getType ()
 
InventoryHolder getHolder ()
 
ListIterator< ItemStackiterator ()
 
ListIterator< ItemStackiterator (int index)
 

Detailed Description

Interface to the various inventories. Behavior relating to Material#AIR is unspecified.

Definition at line 15 of file Inventory.java.

Member Function Documentation

HashMap<Integer, ItemStack> org.bukkit.inventory.Inventory.addItem ( ItemStack...  items) throws IllegalArgumentException

Stores the given ItemStacks in the inventory. This will try to fill existing stacks and empty slots as well as it can.

The returned HashMap contains what it couldn't store, where the key is the index of the parameter, and the value is the ItemStack at that index of the varargs parameter. If all items are stored, it will return an empty HashMap.

If you pass in ItemStacks which exceed the maximum stack size for the Material, first they will be added to partial stacks where Material.getMaxStackSize() is not exceeded, up to Material.getMaxStackSize(). When there are no partial stacks left stacks will be split on Inventory.getMaxStackSize() allowing you to exceed the maximum stack size for that material.

Parameters
itemsThe ItemStacks to add
Returns
A HashMap containing items that didn't fit.
Exceptions
IllegalArgumentExceptionif items or any element in it is null
HashMap<Integer, ? extends ItemStack> org.bukkit.inventory.Inventory.all ( int  materialId)

Returns a HashMap with all slots and ItemStacks in the inventory with given materialId.

The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given materialId is found, an empty map is returned.

Parameters
materialIdThe materialId to look for
Returns
A HashMap containing the slot index, ItemStack pairs
Deprecated:
Magic value
HashMap<Integer, ? extends ItemStack> org.bukkit.inventory.Inventory.all ( Material  material) throws IllegalArgumentException

Returns a HashMap with all slots and ItemStacks in the inventory with the given Material.

The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given Material is found, an empty map is returned.

Parameters
materialThe material to look for
Returns
A HashMap containing the slot index, ItemStack pairs
Exceptions
IllegalArgumentExceptionif material is null
HashMap<Integer, ? extends ItemStack> org.bukkit.inventory.Inventory.all ( ItemStack  item)

Finds all slots in the inventory containing any ItemStacks with the given ItemStack. This will only match slots if both the type and the amount of the stack match

The HashMap contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack with the given Material is found, an empty map is returned.

Parameters
itemThe ItemStack to match against
Returns
A map from slot indexes to item at index
void org.bukkit.inventory.Inventory.clear ( int  index)

Clears out a particular slot in the index.

Parameters
indexThe index to empty.
void org.bukkit.inventory.Inventory.clear ( )

Clears out the whole Inventory.

boolean org.bukkit.inventory.Inventory.contains ( int  materialId)

Checks if the inventory contains any ItemStacks with the given materialId

Parameters
materialIdThe materialId to check for
Returns
true if an ItemStack in this inventory contains the materialId
Deprecated:
Magic value
boolean org.bukkit.inventory.Inventory.contains ( Material  material) throws IllegalArgumentException

Checks if the inventory contains any ItemStacks with the given material.

Parameters
materialThe material to check for
Returns
true if an ItemStack is found with the given Material
Exceptions
IllegalArgumentExceptionif material is null
boolean org.bukkit.inventory.Inventory.contains ( ItemStack  item)

Checks if the inventory contains any ItemStacks matching the given ItemStack.

This will only return true if both the type and the amount of the stack match.

Parameters
itemThe ItemStack to match against
Returns
false if item is null, true if any exactly matching ItemStacks were found
boolean org.bukkit.inventory.Inventory.contains ( int  materialId,
int  amount 
)

Checks if the inventory contains any ItemStacks with the given materialId, adding to at least the minimum amount specified.

Parameters
materialIdThe materialId to check for
amountThe minimum amount to look for
Returns
true if this contains any matching ItemStack with the given materialId and amount
Deprecated:
Magic value
boolean org.bukkit.inventory.Inventory.contains ( Material  material,
int  amount 
) throws IllegalArgumentException

Checks if the inventory contains any ItemStacks with the given material, adding to at least the minimum amount specified.

Parameters
materialThe material to check for
amountThe minimum amount
Returns
true if amount is less than 1, true if enough ItemStacks were found to add to the given amount
Exceptions
IllegalArgumentExceptionif material is null
boolean org.bukkit.inventory.Inventory.contains ( ItemStack  item,
int  amount 
)

Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks.

An ItemStack only counts if both the type and the amount of the stack match.

Parameters
itemthe ItemStack to match against
amounthow many identical stacks to check for
Returns
false if item is null, true if amount less than 1, true if amount of exactly matching ItemStacks were found
See also
containsAtLeast(ItemStack, int)
boolean org.bukkit.inventory.Inventory.containsAtLeast ( ItemStack  item,
int  amount 
)

Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.

Parameters
itemthe ItemStack to match against
amountthe minimum amount
Returns
false if item is null, true if amount less than 1, true if enough ItemStacks were found to add to the given amount
int org.bukkit.inventory.Inventory.first ( int  materialId)

Finds the first slot in the inventory containing an ItemStack with the given materialId.

Parameters
materialIdThe materialId to look for
Returns
The slot index of the given materialId or -1 if not found
Deprecated:
Magic value
int org.bukkit.inventory.Inventory.first ( Material  material) throws IllegalArgumentException

Finds the first slot in the inventory containing an ItemStack with the given material

Parameters
materialThe material to look for
Returns
The slot index of the given Material or -1 if not found
Exceptions
IllegalArgumentExceptionif material is null
int org.bukkit.inventory.Inventory.first ( ItemStack  item)

Returns the first slot in the inventory containing an ItemStack with the given stack. This will only match a slot if both the type and the amount of the stack match

Parameters
itemThe ItemStack to match against
Returns
The slot index of the given ItemStack or -1 if not found
int org.bukkit.inventory.Inventory.firstEmpty ( )

Returns the first empty Slot.

Returns
The first empty Slot found, or -1 if no empty slots.
ItemStack [] org.bukkit.inventory.Inventory.getContents ( )

Returns all ItemStacks from the inventory

Returns
An array of ItemStacks from the inventory.
InventoryHolder org.bukkit.inventory.Inventory.getHolder ( )

Gets the block or entity belonging to the open inventory

Returns
The holder of the inventory; null if it has no holder.

Implemented in org.bukkit.inventory.PlayerInventory, org.bukkit.inventory.FurnaceInventory, org.bukkit.inventory.BrewerInventory, and org.bukkit.inventory.DoubleChestInventory.

ItemStack org.bukkit.inventory.Inventory.getItem ( int  index)

Returns the ItemStack found in the slot at the given index

Parameters
indexThe index of the Slot's ItemStack to return
Returns
The ItemStack in the slot

Referenced by org.bukkit.inventory.InventoryView.getItem().

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

Returns the maximum stack size for an ItemStack in this inventory.

Returns
The maximum size for an ItemStack in this inventory.
String org.bukkit.inventory.Inventory.getName ( )

Returns the name of the inventory

Returns
The String with the name of the inventory
int org.bukkit.inventory.Inventory.getSize ( )

Returns the size of the inventory

Returns
The size of the inventory

Referenced by org.bukkit.inventory.InventoryView.convertSlot(), and org.bukkit.inventory.InventoryView.countSlots().

String org.bukkit.inventory.Inventory.getTitle ( )

Returns the title of this inventory.

Returns
A String with the title.

Referenced by org.bukkit.inventory.InventoryView.getTitle().

InventoryType org.bukkit.inventory.Inventory.getType ( )

Returns what type of inventory this is.

Returns
The InventoryType representing the type of inventory.
List<HumanEntity> org.bukkit.inventory.Inventory.getViewers ( )

Gets a list of players viewing the inventory. Note that a player is considered to be viewing their own inventory and internal crafting screen even when said inventory is not open. They will normally be considered to be viewing their inventory even when they have a different inventory screen open, but it's possible for customized inventory screens to exclude the viewer's inventory, so this should never be assumed to be non-empty.

Returns
A list of HumanEntities who are viewing this Inventory.

Referenced by org.bukkit.event.inventory.InventoryEvent.getViewers().

ListIterator<ItemStack> org.bukkit.inventory.Inventory.iterator ( int  index)

Returns an iterator starting at the given index. If the index is positive, then the first call to next() will return the item at that index; if it is negative, the first call to previous will return the item at index (getSize() + index).

Parameters
indexThe index.
Returns
An iterator.
void org.bukkit.inventory.Inventory.remove ( int  materialId)

Removes all stacks in the inventory matching the given materialId.

Parameters
materialIdThe material to remove
Deprecated:
Magic value
void org.bukkit.inventory.Inventory.remove ( Material  material) throws IllegalArgumentException

Removes all stacks in the inventory matching the given material.

Parameters
materialThe material to remove
Exceptions
IllegalArgumentExceptionif material is null
void org.bukkit.inventory.Inventory.remove ( ItemStack  item)

Removes all stacks in the inventory matching the given stack.

This will only match a slot if both the type and the amount of the stack match

Parameters
itemThe ItemStack to match against
HashMap<Integer, ItemStack> org.bukkit.inventory.Inventory.removeItem ( ItemStack...  items) throws IllegalArgumentException

Removes the given ItemStacks from the inventory.

It will try to remove 'as much as possible' from the types and amounts you give as arguments.

The returned HashMap contains what it couldn't remove, where the key is the index of the parameter, and the value is the ItemStack at that index of the varargs parameter. If all the given ItemStacks are removed, it will return an empty HashMap.

Parameters
itemsThe ItemStacks to remove
Returns
A HashMap containing items that couldn't be removed.
Exceptions
IllegalArgumentExceptionif items is null
void org.bukkit.inventory.Inventory.setContents ( ItemStack[]  items) throws IllegalArgumentException

Completely replaces the inventory's contents. Removes all existing contents and replaces it with the ItemStacks given in the array.

Parameters
itemsA complete replacement for the contents; the length must be less than or equal to getSize().
Exceptions
IllegalArgumentExceptionIf the array has more items than the inventory.
void org.bukkit.inventory.Inventory.setItem ( int  index,
ItemStack  item 
)

Stores the ItemStack at the given index of the inventory.

Parameters
indexThe index where to put the ItemStack
itemThe ItemStack to set

Referenced by org.bukkit.inventory.InventoryView.setItem().

void org.bukkit.inventory.Inventory.setMaxStackSize ( int  size)

This method allows you to change the maximum stack size for an inventory.

Caveats:

  • Not all inventories respect this value.
  • Stacks larger than 127 may be clipped when the world is saved.
  • This value is not guaranteed to be preserved; be sure to set it before every time you want to set a slot over the max stack size.
  • Stacks larger than the default max size for this type of inventory may not display correctly in the client.
Parameters
sizeThe new maximum stack size for items in this inventory.

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