Package net.minestom.server.inventory
Class AbstractInventory
java.lang.Object
net.minestom.server.inventory.AbstractInventory
- All Implemented Interfaces:
EventHandler<InventoryEvent>,InventoryClickHandler,Taggable,TagReadable,TagWritable,Viewable
- Direct Known Subclasses:
Inventory,PlayerInventory
public abstract sealed class AbstractInventory
extends Object
implements InventoryClickHandler, Taggable, Viewable, EventHandler<InventoryEvent>
permits Inventory, PlayerInventory
Represents an inventory where items can be modified/retrieved.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InventoryClickProcessorprotected final ItemStack[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddItemStack(@NotNull ItemStack itemStack) <T> TaddItemStack(@NotNull ItemStack itemStack, @NotNull TransactionOption<T> option) Adds anItemStackto the inventory and sends relevant update to the viewer(s).<T> @NotNull List<@NotNull T> addItemStacks(@NotNull List<@NotNull ItemStack> itemStacks, @NotNull TransactionOption<T> option) AddsItemStacks to the inventory and sends relevant updates to the viewer(s).booleanAdds a viewer.voidclear()Clears the inventory and send relevant update to the viewer(s).voidcopyContents(@NotNull ItemStack[] itemStacks) Places all the items ofitemStacksinto the internal array.@NotNull EventNode<InventoryEvent> intGets the size of the "inner inventory" (which includes only "usable" slots).@NotNull ItemStackgetItemStack(int slot) Gets theItemStackat the specified slot.@NotNull ItemStack[]Gets all theItemStackin the inventory.intgetSize()Gets the size of the inventory.Gets all the viewers of this viewable element.abstract byteGets this window id.<T> TprocessItemStack(@NotNull ItemStack itemStack, @NotNull TransactionType type, @NotNull TransactionOption<T> option) <T> @NotNull List<@NotNull T> processItemStacks(@NotNull List<@NotNull ItemStack> itemStacks, @NotNull TransactionType type, @NotNull TransactionOption<T> option) booleanremoveViewer(@NotNull Player player) Removes a viewer.voidreplaceItemStack(int slot, @NotNull UnaryOperator<@NotNull ItemStack> operator) voidsendSlotRefresh(int slot, @NotNull ItemStack item) voidsetItemStack(int slot, @NotNull ItemStack itemStack) Sets anItemStackat the specified slot and send relevant update to the viewer(s).voidsetItemStack(int slot, @NotNull ItemStack itemStack, boolean sendPacket) Sets anItemStackat the specified slot and send relevant update to the viewer(s).@NotNull TagHandler<T> TtakeItemStack(@NotNull ItemStack itemStack, @NotNull TransactionOption<T> option) Takes anItemStackfrom the inventory and sends relevant update to the viewer(s).<T> @NotNull List<@NotNull T> takeItemStacks(@NotNull List<@NotNull ItemStack> itemStacks, @NotNull TransactionOption<T> option) TakesItemStacks from the inventory and sends relevant updates to the viewer(s).protected voidUNSAFE_itemInsert(int slot, @NotNull ItemStack item, @NotNull ItemStack previous, boolean sendPacket) voidupdate()Refreshes the inventory for all viewers.voidRefreshes the inventory for a specific viewer.Methods 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
callClickEvent, changeHeld, doubleClick, dragging, drop, handleClick, leftClick, middleClick, rightClick, shiftClickMethods 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
-
Field Details
-
itemStacks
-
clickProcessor
-
viewers
-
unmodifiableViewers
-
-
Constructor Details
-
AbstractInventory
protected AbstractInventory(int size)
-
-
Method Details
-
getWindowId
public abstract 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
-
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
Description copied from interface:ViewableAdds a viewer. -
removeViewer
Description copied from interface:ViewableRemoves a viewer.- Specified by:
removeViewerin interfaceViewable- Parameters:
player- the viewer to remove- Returns:
- true if the player has been removed, false otherwise (could be because he was not a viewer)
-
setItemStack
Sets anItemStackat the specified slot and send relevant update to the viewer(s).- Parameters:
slot- the slot to set the itemitemStack- the item to set
-
setItemStack
Sets anItemStackat the specified slot and send relevant update to the viewer(s).- Parameters:
slot- the slot to set the itemitemStack- the item to setsendPacket- whether or not to send packets
-
UNSAFE_itemInsert
-
sendSlotRefresh
-
processItemStack
@NotNull public <T> T processItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionType type, @NotNull @NotNull TransactionOption<T> option) -
processItemStacks
@NotNull public <T> @NotNull List<@NotNull T> processItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionType type, @NotNull @NotNull TransactionOption<T> option) -
addItemStack
@NotNull public <T> T addItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionOption<T> option) Adds anItemStackto the inventory and sends relevant update to the viewer(s).- Parameters:
itemStack- the item to addoption- the transaction option- Returns:
- true if the item has been successfully added, false otherwise
-
addItemStack
-
addItemStacks
@NotNull public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionOption<T> option) AddsItemStacks to the inventory and sends relevant updates to the viewer(s).- Parameters:
itemStacks- items to addoption- the transaction option- Returns:
- the operation results
-
takeItemStack
@NotNull public <T> T takeItemStack(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull TransactionOption<T> option) Takes anItemStackfrom the inventory and sends relevant update to the viewer(s).- Parameters:
itemStack- the item to take- Returns:
- true if the item has been successfully fully taken, false otherwise
-
takeItemStacks
@NotNull public <T> @NotNull List<@NotNull T> takeItemStacks(@NotNull @NotNull List<@NotNull ItemStack> itemStacks, @NotNull @NotNull TransactionOption<T> option) TakesItemStacks from the inventory and sends relevant updates to the viewer(s).- Parameters:
itemStacks- items to take- Returns:
- the operation results
-
replaceItemStack
public void replaceItemStack(int slot, @NotNull @NotNull UnaryOperator<@NotNull ItemStack> operator) -
clear
public void clear()Clears the inventory and send relevant update to the viewer(s). -
update
public void update()Refreshes the inventory for all viewers. -
update
Refreshes the inventory for a specific viewer.- Parameters:
player- the player to update the inventory for
-
getItemStack
Gets theItemStackat the specified slot.- Parameters:
slot- the slot to check- Returns:
- the item in the slot
slot
-
getItemStacks
Gets all theItemStackin the inventory.Be aware that the returned array does not need to be the original one, meaning that modifying it directly may not work.
- Returns:
- an array containing all the inventory's items
-
getSize
public int getSize()Gets the size of the inventory.- Returns:
- the inventory's size
-
getInnerSize
public int getInnerSize()Gets the size of the "inner inventory" (which includes only "usable" slots).- Returns:
- inner inventory's size
-
copyContents
Places all the items ofitemStacksinto the internal array.- Parameters:
itemStacks- the array to copy the content from- Throws:
IllegalArgumentException- if the size of the array is not equal togetSize()NullPointerException- ifitemStackscontains one null element or more
-
tagHandler
- Specified by:
tagHandlerin interfaceTaggable
-
eventNode
- Specified by:
eventNodein interfaceEventHandler<InventoryEvent>
-