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
ConstructorDescriptionInventory
(@NotNull InventoryType inventoryType, @NotNull String title) Inventory
(@NotNull InventoryType inventoryType, @NotNull Component title) -
Method Summary
Modifier and TypeMethodDescriptionboolean
This will not open the inventory forplayer
, usePlayer.openInventory(Inventory)
.boolean
changeHeld
(@NotNull Player player, int slot, int key) Called when aPlayer
held click in the inventoryboolean
doubleClick
(@NotNull Player player, int slot) Called when aPlayer
double click in the inventoryboolean
boolean
Called when aPlayer
press the drop button@NotNull ItemStack
getCursorItem
(@NotNull Player player) Deprecated.normal inventories no longer store cursor items@NotNull InventoryType
Gets the inventory type.@NotNull Component
getTitle()
Gets the inventory title.Gets all the viewers of this viewable element.byte
Gets this window id.boolean
Called when aPlayer
left click in the inventory.boolean
middleClick
(@NotNull Player player, int slot) boolean
removeViewer
(@NotNull Player player) This will not close the inventory forplayer
, usePlayer.closeInventory()
.boolean
rightClick
(@NotNull Player player, int slot) Called when aPlayer
right click in the inventory.protected void
sendProperty
(@NotNull InventoryProperty property, short value) Sends a window property to all viewers.void
setCursorItem
(@NotNull Player player, @NotNull ItemStack cursorItem) Deprecated.normal inventories no longer store cursor itemsvoid
Changes the inventory title.boolean
shiftClick
(@NotNull Player player, int slot) Called when aPlayer
shift click in the inventoryprotected void
UNSAFE_itemInsert
(int slot, @NotNull ItemStack itemStack, boolean sendPacket) void
update()
Refreshes the inventory for all viewers.void
Refreshes 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, takeItemStacks
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.InventoryClickHandler
callClickEvent
Methods inherited from interface net.minestom.server.tag.Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
Methods 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:
update
in 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:Viewable
Gets all the viewers of this viewable element.- Specified by:
getViewers
in 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:
removeViewer
in 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_itemInsert
in 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: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
-
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
-
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 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:
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
-