Interface PlayerInventory
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ItemStack[]
getArmorContents()
Get all ItemStacks from the armor slotsItemStack
getBoots()
Return the ItemStack from the boots slotItemStack
getChestplate()
Return the ItemStack from the chestplate slotItemStack[]
getExtraContents()
Get all additional ItemStacks stored in this inventory.int
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()
Deprecated.players can duel wield now use the methods for the specific hand insteadItemStack
getItemInMainHand()
Gets a copy of the item the player is currently holding in their main hand.ItemStack
getItemInOffHand()
Gets a copy of the item the player is currently holding in their off hand.ItemStack
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
setExtraContents(ItemStack[] items)
Put the given ItemStacks into the extra slots
SeegetExtraContents()
for an explanation of extra slots.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)
Deprecated.players can duel wield now use the methods for the specific hand insteadvoid
setItemInMainHand(ItemStack item)
Sets the item the player is holding in their main hand.void
setItemInOffHand(ItemStack item)
Sets the item the player is holding in their off hand.void
setLeggings(ItemStack leggings)
Put the given ItemStack into the leg slot.-
Methods inherited from interface org.bukkit.inventory.Inventory
addItem, all, all, clear, clear, contains, contains, contains, contains, containsAtLeast, first, first, firstEmpty, getContents, getItem, getLocation, getMaxStackSize, getSize, getStorageContents, getType, getViewers, iterator, iterator, remove, remove, removeItem, setContents, setMaxStackSize, setStorageContents
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getArmorContents
@NotNull ItemStack[] getArmorContents()
Get all ItemStacks from the armor slots- Returns:
- All the ItemStacks from the armor slots. Individual items can be null.
-
getExtraContents
@NotNull ItemStack[] getExtraContents()
Get all additional ItemStacks stored in this inventory.
NB: What defines an extra slot is up to the implementation, however it will not be contained withinInventory.getStorageContents()
orgetArmorContents()
- Returns:
- All additional ItemStacks. Individual items can be null.
-
getHelmet
@Nullable ItemStack getHelmet()
Return the ItemStack from the helmet slot- Returns:
- The ItemStack in the helmet slot
-
getChestplate
@Nullable ItemStack getChestplate()
Return the ItemStack from the chestplate slot- Returns:
- The ItemStack in the chestplate slot
-
getLeggings
@Nullable ItemStack getLeggings()
Return the ItemStack from the leg slot- Returns:
- The ItemStack in the leg slot
-
getBoots
@Nullable ItemStack getBoots()
Return the ItemStack from the boots slot- Returns:
- The ItemStack in the boots slot
-
setItem
void setItem(int index, @Nullable ItemStack item)
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.
Index 40 refers to the off hand (shield) item slot. Though you can set off hand with this method using this index, you are encouraged to use the provided method for this slot.
If you attempt to use this method with an index less than 0 or greater than 40, 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:
ArrayIndexOutOfBoundsException
- when index < 0 || index > 40- See Also:
setBoots(ItemStack)
,setChestplate(ItemStack)
,setHelmet(ItemStack)
,setLeggings(ItemStack)
,setItemInOffHand(ItemStack)
-
setArmorContents
void setArmorContents(@Nullable ItemStack[] items)
Put the given ItemStacks into the armor slots- Parameters:
items
- The ItemStacks to use as armour
-
setExtraContents
void setExtraContents(@Nullable ItemStack[] items)
Put the given ItemStacks into the extra slots
SeegetExtraContents()
for an explanation of extra slots.- Parameters:
items
- The ItemStacks to use as extra
-
setHelmet
void setHelmet(@Nullable ItemStack helmet)
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
void setChestplate(@Nullable ItemStack chestplate)
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
void setLeggings(@Nullable ItemStack leggings)
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
void setBoots(@Nullable ItemStack boots)
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
-
getItemInMainHand
@NotNull ItemStack getItemInMainHand()
Gets a copy of the item the player is currently holding in their main hand.- Returns:
- the currently held item
-
setItemInMainHand
void setItemInMainHand(@Nullable ItemStack item)
Sets the item the player is holding in their main hand.- Parameters:
item
- The item to put into the player's hand
-
getItemInOffHand
@NotNull ItemStack getItemInOffHand()
Gets a copy of the item the player is currently holding in their off hand.- Returns:
- the currently held item
-
setItemInOffHand
void setItemInOffHand(@Nullable ItemStack item)
Sets the item the player is holding in their off hand.- Parameters:
item
- The item to put into the player's hand
-
getItemInHand
@Deprecated @NotNull ItemStack getItemInHand()
Deprecated.players can duel wield now use the methods for the specific hand insteadGets a copy of the item the player is currently holding- Returns:
- the currently held item
- See Also:
getItemInMainHand()
,getItemInOffHand()
-
setItemInHand
@Deprecated void setItemInHand(@Nullable ItemStack stack)
Deprecated.players can duel wield now use the methods for the specific hand insteadSets the item the player is holding- Parameters:
stack
- The item to put into the player's hand- See Also:
setItemInMainHand(ItemStack)
,setItemInOffHand(ItemStack)
-
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:
IllegalArgumentException
- Thrown if slot is not between 0 and 8 inclusive
-
getHolder
@Nullable HumanEntity getHolder()
Description copied from interface:Inventory
Gets the block or entity belonging to the open inventory
-
-