Package net.minestom.server.inventory
Class PlayerInventory
java.lang.Object
net.minestom.server.inventory.PlayerInventory
- All Implemented Interfaces:
DataContainer
,EquipmentHandler
,InventoryClickHandler
,InventoryModifier
public class PlayerInventory extends java.lang.Object implements InventoryModifier, InventoryClickHandler, EquipmentHandler, DataContainer
Represents the inventory of a
Player
, retrieved with Player.getInventory()
.-
Field Summary
Fields Modifier and Type Field Description static int
INVENTORY_SIZE
-
Constructor Summary
Constructors Constructor Description PlayerInventory(Player player)
-
Method Summary
Modifier and Type Method Description void
addInventoryCondition(InventoryCondition inventoryCondition)
Adds a newInventoryCondition
to this inventory.boolean
addItemStack(ItemStack itemStack)
Adds anItemStack
to the inventory and send relevant update to the viewer(s).boolean
changeHeld(Player player, int slot, int key)
Called when aPlayer
held click in the inventoryvoid
clear()
Clears the inventory and send relevant update to the viewer(s).boolean
doubleClick(Player player, int slot)
Called when aPlayer
double click in the inventoryboolean
dragging(Player player, int slot, int button)
boolean
drop(Player player, int mode, int slot, int button)
Called when aPlayer
press the drop buttonItemStack
getBoots()
Gets the boots.ItemStack
getChestplate()
Gets the chestplate.ItemStack
getCursorItem()
Gets the item in player cursor.Data
getData()
Gets theData
of this container.ItemStack
getHelmet()
Gets the helmet.java.util.List<InventoryCondition>
getInventoryConditions()
Gets all theInventoryCondition
of this inventory.ItemStack
getItemInMainHand()
Gets theItemStack
in main hand.ItemStack
getItemInOffHand()
Gets theItemStack
in off hand.ItemStack
getItemStack(int slot)
Gets theItemStack
at the specified slot.protected ItemStack
getItemStack(int slot, int offset)
Gets the item from a packet slot.ItemStack[]
getItemStacks()
Gets all theItemStack
in the inventory.ItemStack
getLeggings()
Gets the leggings.int
getSize()
Gets the size of the inventory.boolean
leftClick(Player player, int slot)
Called when aPlayer
left click in the inventory.boolean
middleClick(Player player, int slot)
void
refreshSlot(short slot)
Refreshes only a specific slot with the updated item stack data.boolean
rightClick(Player player, int slot)
Called when aPlayer
right click in the inventory.protected void
sendSlotRefresh(short slot, ItemStack itemStack)
Refreshes an inventory slot.void
setBoots(ItemStack itemStack)
Changes the boots.void
setChestplate(ItemStack itemStack)
Changes the chestplate.void
setCursorItem(ItemStack cursorItem)
Changes the player cursor item.void
setData(Data data)
Sets theData
of this container.void
setHelmet(ItemStack itemStack)
Changes the helmet.void
setItemInMainHand(ItemStack itemStack)
Changes the main handItemStack
.void
setItemInOffHand(ItemStack itemStack)
Changes the off handItemStack
.protected void
setItemStack(int slot, int offset, ItemStack itemStack)
Sets an item from a packet slot.void
setItemStack(int slot, ItemStack itemStack)
Sets anItemStack
at the specified slot and send relevant update to the viewer(s).protected void
setItemStackInternal(int slot, ItemStack itemStack)
void
setLeggings(ItemStack itemStack)
Changes the leggings.boolean
shiftClick(Player player, int slot)
Called when aPlayer
shift click in the inventoryvoid
update()
Refreshes the player inventory by sending aWindowItemsPacket
containing all.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, setItemInHand, syncEquipment, syncEquipments, syncEquipments
-
Field Details
-
INVENTORY_SIZE
public static final int INVENTORY_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
getItemStack
Description copied from interface:InventoryModifier
Gets theItemStack
at the specified slot.- Specified by:
getItemStack
in interfaceInventoryModifier
- Parameters:
slot
- the slot to check- Returns:
- the item in the slot
slot
-
getItemStacks
Description copied from interface:InventoryModifier
Gets all theItemStack
in the inventory.- Specified by:
getItemStacks
in interfaceInventoryModifier
- Returns:
- an array containing all the inventory's items
-
getInventoryConditions
Description copied from interface:InventoryModifier
Gets all theInventoryCondition
of this inventory.- Specified by:
getInventoryConditions
in interfaceInventoryModifier
- Returns:
- a modifiable
List
containing all the inventory conditions
-
addInventoryCondition
Description copied from interface:InventoryModifier
Adds a newInventoryCondition
to this inventory.- Specified by:
addInventoryCondition
in interfaceInventoryModifier
- Parameters:
inventoryCondition
- the inventory condition to add
-
setItemStack
Description copied from interface:InventoryModifier
Sets anItemStack
at the specified slot and send relevant update to the viewer(s).- Specified by:
setItemStack
in interfaceInventoryModifier
- Parameters:
slot
- the slot to set the itemitemStack
- the item to set
-
addItemStack
Description copied from interface:InventoryModifier
Adds anItemStack
to the inventory and send relevant update to the viewer(s).Even the item cannot be fully added, the amount of
itemStack
will be updated.- Specified by:
addItemStack
in interfaceInventoryModifier
- Parameters:
itemStack
- the item to add- Returns:
- true if the item has been successfully fully added, false otherwise
-
clear
public void clear()Description copied from interface:InventoryModifier
Clears the inventory and send relevant update to the viewer(s).- Specified by:
clear
in interfaceInventoryModifier
-
getSize
public int getSize()Description copied from interface:InventoryModifier
Gets the size of the inventory.- Specified by:
getSize
in interfaceInventoryModifier
- Returns:
- the inventory's size
-
getItemInMainHand
Description copied from interface:EquipmentHandler
Gets theItemStack
in main hand.- Specified by:
getItemInMainHand
in interfaceEquipmentHandler
- Returns:
- the
ItemStack
in main hand
-
setItemInMainHand
Description copied from interface:EquipmentHandler
Changes the main handItemStack
.- Specified by:
setItemInMainHand
in interfaceEquipmentHandler
- Parameters:
itemStack
- the main handItemStack
-
getItemInOffHand
Description copied from interface:EquipmentHandler
Gets theItemStack
in off hand.- Specified by:
getItemInOffHand
in interfaceEquipmentHandler
- Returns:
- the item in off hand
-
setItemInOffHand
Description copied from interface:EquipmentHandler
Changes the off handItemStack
.- Specified by:
setItemInOffHand
in interfaceEquipmentHandler
- Parameters:
itemStack
- the off handItemStack
-
getHelmet
Description copied from interface:EquipmentHandler
Gets the helmet.- Specified by:
getHelmet
in interfaceEquipmentHandler
- Returns:
- the helmet
-
setHelmet
Description copied from interface:EquipmentHandler
Changes the helmet.- Specified by:
setHelmet
in interfaceEquipmentHandler
- Parameters:
itemStack
- the helmet
-
getChestplate
Description copied from interface:EquipmentHandler
Gets the chestplate.- Specified by:
getChestplate
in interfaceEquipmentHandler
- Returns:
- the chestplate
-
setChestplate
Description copied from interface:EquipmentHandler
Changes the chestplate.- Specified by:
setChestplate
in interfaceEquipmentHandler
- Parameters:
itemStack
- the chestplate
-
getLeggings
Description copied from interface:EquipmentHandler
Gets the leggings.- Specified by:
getLeggings
in interfaceEquipmentHandler
- Returns:
- the leggings
-
setLeggings
Description copied from interface:EquipmentHandler
Changes the leggings.- Specified by:
setLeggings
in interfaceEquipmentHandler
- Parameters:
itemStack
- the leggings
-
getBoots
Description copied from interface:EquipmentHandler
Gets the boots.- Specified by:
getBoots
in interfaceEquipmentHandler
- Returns:
- the boots
-
setBoots
Description copied from interface:EquipmentHandler
Changes the boots.- Specified by:
setBoots
in interfaceEquipmentHandler
- Parameters:
itemStack
- the boots
-
update
public void update()Refreshes the player inventory by sending aWindowItemsPacket
containing all. the inventory items -
refreshSlot
public void refreshSlot(short slot)Refreshes only a specific slot with the updated item stack data.- Parameters:
slot
- the slot to refresh
-
getCursorItem
Gets the item in player cursor.- Returns:
- the cursor item
-
setCursorItem
Changes the player cursor item.- Parameters:
cursorItem
- the new cursor item
-
setItemStackInternal
-
setItemStack
Sets an item from a packet slot.- Parameters:
slot
- a packet slotoffset
- offset (generally 9 to ignore armor and craft slots)itemStack
- the item stack to set
-
getItemStack
Gets the item from a packet slot.- Parameters:
slot
- a packet slotoffset
- offset (generally 9 to ignore armor and craft slots)- Returns:
- the item in the specified slot
-
sendSlotRefresh
Refreshes an inventory slot.- Parameters:
slot
- the packet slot seePlayerInventoryUtils.convertToPacketSlot(int)
itemStack
- the item stack in the slot
-
leftClick
Description copied from interface:InventoryClickHandler
Called when aPlayer
left click in the inventory. Can also be to drop the cursor item- Specified by:
leftClick
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-
rightClick
Description copied from interface:InventoryClickHandler
Called when aPlayer
right click in the inventory. Can also be to drop the cursor item- Specified by:
rightClick
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-
middleClick
- Specified by:
middleClick
in interfaceInventoryClickHandler
-
drop
Description copied from interface:InventoryClickHandler
Called when aPlayer
press the drop button- Specified by:
drop
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot numberbutton
- -999 if clicking outside, normal if he is not- Returns:
- true if the drop hasn't been cancelled, false otherwise
-
shiftClick
Description copied from interface:InventoryClickHandler
Called when aPlayer
shift click in the inventory- Specified by:
shiftClick
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-
changeHeld
Description copied from interface:InventoryClickHandler
Called when aPlayer
held click in the inventory- Specified by:
changeHeld
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot numberkey
- the held slot (0-8) pressed- Returns:
- true if the click hasn't been cancelled, false otherwise
-
dragging
- Specified by:
dragging
in interfaceInventoryClickHandler
-
doubleClick
Description copied from interface:InventoryClickHandler
Called when aPlayer
double click in the inventory- Specified by:
doubleClick
in interfaceInventoryClickHandler
- Parameters:
player
- the player who clickedslot
- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-
getData
Description copied from interface:DataContainer
Gets theData
of this container.A
DataContainer
data is always optional, meaning that this will be null if no data has been defined.- Specified by:
getData
in interfaceDataContainer
- Returns:
- the
Data
of this container, can be null
-
setData
Description copied from interface:DataContainer
Sets theData
of this container.Default implementations are
DataImpl
andSerializableDataImpl
depending on your use-case.- Specified by:
setData
in interfaceDataContainer
- Parameters:
data
- the newData
of this container, null to remove it
-