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, unmodifiableViewers, viewers
-
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.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 inventoryMethods inherited from class net.minestom.server.inventory.AbstractInventory
addInventoryCondition, addItemStack, addItemStack, addItemStacks, clear, copyContents, getInnerSize, getInventoryConditions, getItemStack, getItemStacks, getSize, getViewers, processItemStack, processItemStacks, replaceItemStack, sendSlotRefresh, setItemStack, setItemStack, tagHandler, takeItemStack, takeItemStacks, UNSAFE_itemInsert, update, update
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()Description copied from class:AbstractInventory
Gets this window id.This is the id that the client will send to identify the affected inventory, mostly used by packets.
- Specified by:
getWindowId
in classAbstractInventory
- Returns:
- the window id
-
addViewer
This will not open the inventory forplayer
, usePlayer.openInventory(Inventory)
.- Specified by:
addViewer
in interfaceViewable
- Overrides:
addViewer
in classAbstractInventory
- Parameters:
player
- the viewer to add- Returns:
- true if the player has successfully been added
-
removeViewer
This will not close the inventory forplayer
, usePlayer.closeInventory()
.- Specified by:
removeViewer
in interfaceViewable
- Overrides:
removeViewer
in classAbstractInventory
- 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:
-
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- 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- 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- 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- 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
-
drop
Description copied from interface:InventoryClickHandler
Called when aPlayer
press the drop button- 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
-
doubleClick
Description copied from interface:InventoryClickHandler
Called when aPlayer
double click in the inventory- Parameters:
player
- the player who clickedslot
- the slot number- Returns:
- true if the click hasn't been cancelled, false otherwise
-