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, Component) 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
Constructors -
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 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 ItemStackgetCursorItem(@NotNull Player player) Gets the cursor item of a viewer.@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) Changes the cursor item of a viewer, does nothing ifplayeris not a viewer.voidChanges the inventory title.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 inventory for all viewers.voidRefreshes the inventory for a specific viewer.Methods inherited from class net.minestom.server.inventory.AbstractInventory
addInventoryCondition, addItemStack, addItemStack, addItemStacks, 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.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Constructor Details
-
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
-
clear
public void clear()Description copied from class:AbstractInventoryClears the inventory and send relevant update to the viewer(s).- Overrides:
clearin classAbstractInventory
-
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
Gets the cursor item of a viewer.- Parameters:
player- the player to get the cursor item from- Returns:
- the player cursor item, air item if the player is not a viewer
-
setCursorItem
Changes the cursor item of a viewer, does nothing ifplayeris not a viewer.- Parameters:
player- the player to change the cursor itemcursorItem- the new player cursor item
-
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 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
-
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
-