Package net.minestom.server.inventory
Class Inventory
java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.Inventory
- All Implemented Interfaces:
InventoryClickHandler,Taggable,TagReadable,TagWritable,Viewable
- Direct Known Subclasses:
AnvilInventory,BeaconInventory,BrewingStandInventory,EnchantmentTableInventory,FurnaceInventory,VillagerInventory
Represents an inventory which can be viewed by a collection of
Player.
You can create one with Inventory(InventoryType, String) or by making your own subclass.
It can then be opened using Player.openInventory(Inventory).
-
Field Summary
Fields inherited from class net.minestom.server.inventory.AbstractInventory
clickProcessor, inventoryConditions, itemStacks -
Constructor Summary
ConstructorsConstructorDescriptionInventory(@NotNull InventoryType inventoryType, @NotNull String title) Inventory(@NotNull InventoryType inventoryType, @NotNull Component title) -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis will not open the inventory forplayer, usePlayer.openInventory(Inventory).booleanchangeHeld(@NotNull Player player, int slot, int key) Called when aPlayerheld click in the inventorybooleandoubleClick(@NotNull Player player, int slot) Called when aPlayerdouble click in the inventorybooleanbooleanCalled when aPlayerpress the drop button@NotNull ItemStackgetCursorItem(@NotNull Player player) Deprecated.normal inventories no longer store cursor items@NotNull InventoryTypeGets the inventory type.@NotNull ComponentgetTitle()Gets the inventory title.Gets all the viewers of this viewable element.byteGets this window id.booleanCalled when aPlayerleft click in the inventory.booleanmiddleClick(@NotNull Player player, int slot) booleanremoveViewer(@NotNull Player player) This will not close the inventory forplayer, usePlayer.closeInventory().booleanrightClick(@NotNull Player player, int slot) Called when aPlayerright click in the inventory.protected voidsendProperty(@NotNull InventoryProperty property, short value) Sends a window property to all viewers.voidsetCursorItem(@NotNull Player player, @NotNull ItemStack cursorItem) Deprecated.normal inventories no longer store cursor itemsvoidChanges the inventory title.booleanshiftClick(@NotNull Player player, int slot) Called when aPlayershift click in the inventoryprotected voidUNSAFE_itemInsert(int slot, @NotNull ItemStack itemStack, boolean sendPacket) voidupdate()Refreshes the inventory for all viewers.voidRefreshes the inventory for a specific viewer.Methods inherited from class net.minestom.server.inventory.AbstractInventory
addInventoryCondition, addItemStack, addItemStack, addItemStacks, clear, copyContents, getInnerSize, 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.InventoryClickHandler
callClickEventMethods inherited from interface net.minestom.server.tag.Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTagMethods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Constructor Details
-
Inventory
-
Inventory
-
-
Method Details
-
getInventoryType
Gets the inventory type.- Returns:
- the inventory type
-
getTitle
Gets the inventory title.- Returns:
- the inventory title
-
setTitle
Changes the inventory title.- Parameters:
title- the new inventory title
-
getWindowId
public byte getWindowId()Gets this window id.This is the id that the client will send to identify the affected inventory, mostly used by packets.
- Returns:
- the window id
-
update
public void update()Refreshes the inventory for all viewers.- Specified by:
updatein classAbstractInventory
-
update
Refreshes the inventory for a specific viewer.The player needs to be a viewer, otherwise nothing is sent.
- Parameters:
player- the player to update the inventory
-
getViewers
Description copied from interface:ViewableGets all the viewers of this viewable element.- Specified by:
getViewersin interfaceViewable- Returns:
- A Set containing all the element's viewers
-
addViewer
This will not open the inventory forplayer, usePlayer.openInventory(Inventory). -
removeViewer
This will not close the inventory forplayer, usePlayer.closeInventory().- Specified by:
removeViewerin interfaceViewable- Parameters:
player- the viewer to remove- Returns:
- true if the player has successfully been removed
-
getCursorItem
Deprecated.normal inventories no longer store cursor itemsGets the cursor item of a player.- See Also:
-
setCursorItem
@Deprecated public void setCursorItem(@NotNull @NotNull Player player, @NotNull @NotNull ItemStack cursorItem) Deprecated.normal inventories no longer store cursor itemsChanges the cursor item of a player.- See Also:
-
UNSAFE_itemInsert
protected void UNSAFE_itemInsert(int slot, @NotNull @NotNull ItemStack itemStack, boolean sendPacket) - Specified by:
UNSAFE_itemInsertin classAbstractInventory
-
sendProperty
Sends a window property to all viewers.- Parameters:
property- the property to sendvalue- the value of the property- See Also:
-
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
-
shiftClick
Description copied from interface:InventoryClickHandlerCalled when aPlayershift click in the inventory- Specified by:
shiftClickin 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: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
-
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
-
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
-