Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
org.bukkit.inventory.Inventory Interface Reference

Interface to the various inventories. More...

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

Public Member Functions

int getSize ()
 Returns the size of the inventory.
 
int getMaxStackSize ()
 Returns the maximum stack size for an ItemStack in this inventory.
 
void setMaxStackSize (int size)
 This method allows you to change the maximum stack size for an inventory.
 
String getName ()
 Returns the name of the inventory.
 
ItemStack getItem (int index)
 Returns the ItemStack found in the slot at the given index.
 
void setItem (int index, ItemStack item)
 Stores the ItemStack at the given index of the inventory.
 
HashMap< Integer, ItemStackaddItem (ItemStack...items) throws IllegalArgumentException
 Stores the given ItemStacks in the inventory.
 
HashMap< Integer, ItemStackremoveItem (ItemStack...items) throws IllegalArgumentException
 Removes the given ItemStacks from the inventory.
 
ItemStack[] getContents ()
 Returns all ItemStacks from the inventory.
 
void setContents (ItemStack[] items) throws IllegalArgumentException
 Completely replaces the inventory's contents.
 
boolean contains (int materialId)
 Checks if the inventory contains any ItemStacks with the given materialId.
 
boolean contains (Material material) throws IllegalArgumentException
 Checks if the inventory contains any ItemStacks with the given material.
 
boolean contains (ItemStack item)
 Checks if the inventory contains any ItemStacks matching the given ItemStack.
 
boolean contains (int materialId, int amount)
 Checks if the inventory contains any ItemStacks with the given materialId, adding to at least the minimum amount specified.
 
boolean 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.
 
boolean contains (ItemStack item, int amount)
 Checks if the inventory contains any ItemStacks matching the given ItemStack and at least the minimum amount specified This will only match if both the type and the amount of the stack match.
 
boolean containsAtLeast (ItemStack item, int amount)
 Returns a HashMap with all slots and ItemStacks in the inventory with given materialId.
 
HashMap< Integer,?extends
ItemStack
all (int materialId)
 Find all slots in the inventory containing any ItemStacks with the given materialId.
 
HashMap< Integer,?extends
ItemStack
all (Material material) throws IllegalArgumentException
 Returns a HashMap with all slots and ItemStacks in the inventory with the given Material.
 
HashMap< Integer,?extends
ItemStack
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.
 
int first (int materialId)
 Finds the first slot in the inventory containing an ItemStack with the given materialId.
 
int first (Material material) throws IllegalArgumentException
 Finds the first slot in the inventory containing an ItemStack with the given material.
 
int 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.
 
int firstEmpty ()
 Returns the first empty Slot.
 
void remove (int materialId)
 Removes all stacks in the inventory matching the given materialId.
 
void remove (Material material) throws IllegalArgumentException
 Removes all stacks in the inventory matching the given material.
 
void remove (ItemStack item)
 Removes all stacks in the inventory matching the given stack.
 
void clear (int index)
 Clears out a particular slot in the index.
 
void clear ()
 Clears out the whole Inventory.
 
List< HumanEntitygetViewers ()
 Gets a list of players viewing.
 
String getTitle ()
 Returns the title of this inventory.
 
InventoryType getType ()
 Returns what type of inventory this is.
 
InventoryHolder getHolder ()
 Gets the block or entity belonging to the open inventory.
 
ListIterator< ItemStackiterator ()
 
ListIterator< ItemStackiterator (int index)
 Returns an iterator starting at the given index.
 

Detailed Description

Interface to the various inventories.

Behavior relating to Material#AIR is unspecified.

Definition at line 14 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 variadic parameter. If all items are stored, it will return an empty HashMap.

Parameters
itemsThe ItemStacks to add
Returns
A HashMap containing items that didn't fit.
Exceptions
IllegalArgumentExceptionif items or any element in it is null

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

HashMap<Integer, ? extends ItemStack> org.bukkit.inventory.Inventory.all ( int  materialId)

Find all slots in the inventory containing any ItemStacks with the given materialId.

Parameters
materialIdThe materialId to look for
Returns
A HashMap containing the slot index, ItemStack pairs
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 ImemStrack 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
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
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 any ItemStacks matching the given ItemStack and at least the minimum amount specified This will only match if both the type and the amount of the stack match.

Parameters
itemThe ItemStack to match against
amountThe amount of stacks to find
Returns
false if item is null, true if amount less than 1, true if amount of exactly matching ItemStacks were found.
boolean org.bukkit.inventory.Inventory.containsAtLeast ( ItemStack  item,
int  amount 
)

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
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
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.

Referenced by org.bukkit.block.DoubleChest.getLeftSide(), and org.bukkit.block.DoubleChest.getRightSide().

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.

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 ( )
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
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 variadic 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: