Package org.bukkit.inventory
Interface PlayerInventory
public interface PlayerInventory extends Inventory
Interface to the inventory of a Player, including the four armor slots.
-
Method Summary
Modifier and Type Method Description int
clear(int id, int data)
Deprecated.Magic valueItemStack[]
getArmorContents()
Get all ItemStacks from the armor slotsItemStack
getBoots()
Return the ItemStack from the boots slotItemStack
getChestplate()
Return the ItemStack from the chestplate slotint
getHeldItemSlot()
Get the slot number of the currently held itemItemStack
getHelmet()
Return the ItemStack from the helmet slotHumanEntity
getHolder()
Gets the block or entity belonging to the open inventoryItemStack
getItemInHand()
Returns the ItemStack currently holdItemStack
getLeggings()
Return the ItemStack from the leg slotvoid
setArmorContents(ItemStack[] items)
Put the given ItemStacks into the armor slotsvoid
setBoots(ItemStack boots)
Put the given ItemStack into the boots slot.void
setChestplate(ItemStack chestplate)
Put the given ItemStack into the chestplate slot.void
setHeldItemSlot(int slot)
Set the slot number of the currently held item.void
setHelmet(ItemStack helmet)
Put the given ItemStack into the helmet slot.void
setItem(int index, ItemStack item)
Stores the ItemStack at the given index of the inventory.void
setItemInHand(ItemStack stack)
Sets the item in handvoid
setLeggings(ItemStack leggings)
Put the given ItemStack into the leg slot.Methods inherited from interface org.bukkit.inventory.Inventory
addItem, all, all, all, clear, clear, contains, contains, contains, contains, contains, contains, containsAtLeast, first, first, first, firstEmpty, getContents, getItem, getMaxStackSize, getName, getSize, getTitle, getType, getViewers, iterator, iterator, remove, remove, remove, removeItem, setContents, setMaxStackSize
-
Method Details
-
getArmorContents
ItemStack[] getArmorContents()Get all ItemStacks from the armor slots- Returns:
- All the ItemStacks from the armor slots
-
getHelmet
ItemStack getHelmet()Return the ItemStack from the helmet slot- Returns:
- The ItemStack in the helmet slot
-
getChestplate
ItemStack getChestplate()Return the ItemStack from the chestplate slot- Returns:
- The ItemStack in the chestplate slot
-
getLeggings
ItemStack getLeggings()Return the ItemStack from the leg slot- Returns:
- The ItemStack in the leg slot
-
getBoots
ItemStack getBoots()Return the ItemStack from the boots slot- Returns:
- The ItemStack in the boots slot
-
setItem
Stores the ItemStack at the given index of the inventory.Indexes 0 through 8 refer to the hotbar. 9 through 35 refer to the main inventory, counting up from 9 at the top left corner of the inventory, moving to the right, and moving to the row below it back on the left side when it reaches the end of the row. It follows the same path in the inventory like you would read a book.
Indexes 36 through 39 refer to the armor slots. Though you can set armor with this method using these indexes, you are encouraged to use the provided methods for those slots.
If you attempt to use this method with an index less than 0 or greater than 39, an ArrayIndexOutOfBounds exception will be thrown.
- Specified by:
setItem
in interfaceInventory
- Parameters:
index
- The index where to put the ItemStackitem
- The ItemStack to set- Throws:
java.lang.ArrayIndexOutOfBoundsException
- when index < 0 || index > 39- See Also:
setBoots(ItemStack)
,setChestplate(ItemStack)
,setHelmet(ItemStack)
,setLeggings(ItemStack)
-
setArmorContents
Put the given ItemStacks into the armor slots- Parameters:
items
- The ItemStacks to use as armour
-
setHelmet
Put the given ItemStack into the helmet slot. This does not check if the ItemStack is a helmet- Parameters:
helmet
- The ItemStack to use as helmet
-
setChestplate
Put the given ItemStack into the chestplate slot. This does not check if the ItemStack is a chestplate- Parameters:
chestplate
- The ItemStack to use as chestplate
-
setLeggings
Put the given ItemStack into the leg slot. This does not check if the ItemStack is a pair of leggings- Parameters:
leggings
- The ItemStack to use as leggings
-
setBoots
Put the given ItemStack into the boots slot. This does not check if the ItemStack is a boots- Parameters:
boots
- The ItemStack to use as boots
-
getItemInHand
ItemStack getItemInHand()Returns the ItemStack currently hold- Returns:
- The currently held ItemStack
-
setItemInHand
Sets the item in hand- Parameters:
stack
- Stack to set
-
getHeldItemSlot
int getHeldItemSlot()Get the slot number of the currently held item- Returns:
- Held item slot number
-
setHeldItemSlot
void setHeldItemSlot(int slot)Set the slot number of the currently held item.This validates whether the slot is between 0 and 8 inclusive.
- Parameters:
slot
- The new slot number- Throws:
java.lang.IllegalArgumentException
- Thrown if slot is not between 0 and 8 inclusive
-
clear
@Deprecated int clear(int id, int data)Deprecated.Magic valueClears all matching items from the inventory. Setting either value to -1 will skip it's check, while setting both to -1 will clear all items in your inventory unconditionally.- Parameters:
id
- the id of the item you want to clear from the inventorydata
- the data of the item you want to clear from the inventory- Returns:
- The number of items cleared
-
getHolder
HumanEntity getHolder()Description copied from interface:Inventory
Gets the block or entity belonging to the open inventory
-