Package net.minestom.server.inventory
Class PlayerInventory
java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.PlayerInventory
- All Implemented Interfaces:
EquipmentHandler,InventoryClickHandler,Taggable,TagReadable,TagWritable
Represents the inventory of a
Player, retrieved with Player.getInventory().-
Field Summary
FieldsFields inherited from class net.minestom.server.inventory.AbstractInventory
clickProcessor, inventoryConditions, itemStacks -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanchangeHeld(@NotNull Player player, int slot, int key) Called when aPlayerheld click in the inventoryvoidclear()Clears the inventory and send relevant update to the viewer(s).booleandoubleClick(@NotNull Player player, int slot) Called when aPlayerdouble click in the inventorybooleanbooleanCalled when aPlayerpress the drop button@NotNull ItemStackgetBoots()Gets the boots.@NotNull ItemStackGets the chestplate.@NotNull ItemStackGets the item in player cursor.@NotNull ItemStackGets the helmet.intGets the size of the "inner inventory" (which includes only "usable" slots).@NotNull ItemStackGets theItemStackin main hand.@NotNull ItemStackGets theItemStackin off hand.@NotNull ItemStackGets the leggings.booleanCalled when aPlayerleft click in the inventory.booleanmiddleClick(@NotNull Player player, int slot) booleanrightClick(@NotNull Player player, int slot) Called when aPlayerright click in the inventory.protected voidsendSlotRefresh(short slot, ItemStack itemStack) Refreshes an inventory slot.voidChanges the boots.voidsetChestplate(@NotNull ItemStack itemStack) Changes the chestplate.voidsetCursorItem(@NotNull ItemStack cursorItem) Changes the player cursor item.voidChanges the helmet.voidsetItemInMainHand(@NotNull ItemStack itemStack) Changes the main handItemStack.voidsetItemInOffHand(@NotNull ItemStack itemStack) Changes the off handItemStack.voidsetLeggings(@NotNull ItemStack itemStack) Changes the leggings.booleanshiftClick(@NotNull Player player, int slot, int button) Called when aPlayershift click in the inventoryprotected voidUNSAFE_itemInsert(int slot, @NotNull ItemStack itemStack, boolean sendPacket) voidupdate()Refreshes the player inventory by sending aWindowItemsPacketcontaining all.Methods inherited from class net.minestom.server.inventory.AbstractInventory
addInventoryCondition, addItemStack, addItemStack, addItemStacks, copyContents, getInventoryConditions, getItemStack, getItemStacks, getSize, processItemStack, processItemStacks, replaceItemStack, safeItemInsert, safeItemInsert, setItemStack, tagHandler, takeItemStack, takeItemStacksMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, hasEquipment, setEquipment, setItemInHand, syncEquipmentMethods inherited from interface net.minestom.server.inventory.InventoryClickHandler
callClickEvent
-
Field Details
-
INVENTORY_SIZE
public static final int INVENTORY_SIZE- See Also:
-
INNER_INVENTORY_SIZE
public static final int INNER_INVENTORY_SIZE- See Also:
-
player
-
-
Constructor Details
-
PlayerInventory
-
-
Method Details
-
clear
public void clear()Description copied from class:AbstractInventoryClears the inventory and send relevant update to the viewer(s).- Overrides:
clearin classAbstractInventory
-
getInnerSize
public int getInnerSize()Description copied from class:AbstractInventoryGets the size of the "inner inventory" (which includes only "usable" slots).- Overrides:
getInnerSizein classAbstractInventory- Returns:
- inner inventory's size
-
getItemInMainHand
Description copied from interface:EquipmentHandlerGets theItemStackin main hand.- Specified by:
getItemInMainHandin interfaceEquipmentHandler- Returns:
- the
ItemStackin main hand
-
setItemInMainHand
Description copied from interface:EquipmentHandlerChanges the main handItemStack.- Specified by:
setItemInMainHandin interfaceEquipmentHandler- Parameters:
itemStack- the main handItemStack
-
getItemInOffHand
Description copied from interface:EquipmentHandlerGets theItemStackin off hand.- Specified by:
getItemInOffHandin interfaceEquipmentHandler- Returns:
- the item in off hand
-
setItemInOffHand
Description copied from interface:EquipmentHandlerChanges the off handItemStack.- Specified by:
setItemInOffHandin interfaceEquipmentHandler- Parameters:
itemStack- the off handItemStack
-
getHelmet
Description copied from interface:EquipmentHandlerGets the helmet.- Specified by:
getHelmetin interfaceEquipmentHandler- Returns:
- the helmet
-
setHelmet
Description copied from interface:EquipmentHandlerChanges the helmet.- Specified by:
setHelmetin interfaceEquipmentHandler- Parameters:
itemStack- the helmet
-
getChestplate
Description copied from interface:EquipmentHandlerGets the chestplate.- Specified by:
getChestplatein interfaceEquipmentHandler- Returns:
- the chestplate
-
setChestplate
Description copied from interface:EquipmentHandlerChanges the chestplate.- Specified by:
setChestplatein interfaceEquipmentHandler- Parameters:
itemStack- the chestplate
-
getLeggings
Description copied from interface:EquipmentHandlerGets the leggings.- Specified by:
getLeggingsin interfaceEquipmentHandler- Returns:
- the leggings
-
setLeggings
Description copied from interface:EquipmentHandlerChanges the leggings.- Specified by:
setLeggingsin interfaceEquipmentHandler- Parameters:
itemStack- the leggings
-
getBoots
Description copied from interface:EquipmentHandlerGets the boots.- Specified by:
getBootsin interfaceEquipmentHandler- Returns:
- the boots
-
setBoots
Description copied from interface:EquipmentHandlerChanges the boots.- Specified by:
setBootsin interfaceEquipmentHandler- Parameters:
itemStack- the boots
-
update
public void update()Refreshes the player inventory by sending aWindowItemsPacketcontaining all. the inventory items- Specified by:
updatein classAbstractInventory
-
getCursorItem
Gets the item in player cursor.- Returns:
- the cursor item
-
setCursorItem
Changes the player cursor item.- Parameters:
cursorItem- the new cursor item
-
UNSAFE_itemInsert
protected void UNSAFE_itemInsert(int slot, @NotNull @NotNull ItemStack itemStack, boolean sendPacket) - Specified by:
UNSAFE_itemInsertin classAbstractInventory
-
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:InventoryClickHandlerCalled when aPlayerleft click in the inventory. Can also be to drop the cursor item- Specified by:
leftClickin 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:InventoryClickHandlerCalled when aPlayerright click in the inventory. Can also be to drop the cursor item- Specified by:
rightClickin interfaceInventoryClickHandler- Parameters:
player- the player who clickedslot- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-
middleClick
- Specified by:
middleClickin interfaceInventoryClickHandler
-
drop
Description copied from interface:InventoryClickHandlerCalled when aPlayerpress the drop button- Specified by:
dropin interfaceInventoryClickHandler- Parameters:
player- the player who clickedall-slot- 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:InventoryClickHandlerCalled when aPlayershift click in the inventory- Specified by:
shiftClickin interfaceInventoryClickHandler- Parameters:
player- the player who clickedslot- the slot numberbutton- the primary mouse or secondary mouse button- Returns:
- true if the click hasn't been cancelled, false otherwise
-
changeHeld
Description copied from interface:InventoryClickHandlerCalled when aPlayerheld click in the inventory- Specified by:
changeHeldin 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:
draggingin interfaceInventoryClickHandler
-
doubleClick
Description copied from interface:InventoryClickHandlerCalled when aPlayerdouble click in the inventory- Specified by:
doubleClickin interfaceInventoryClickHandler- Parameters:
player- the player who clickedslot- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-