Interface MenuSize
- All Known Implementing Classes:
MenuSizeRows, MenuSizeType
@NonExtendable
public interface MenuSize
Represents the size of a menu.
Can either be a
Can either be a
MenuSizeRows, or MenuSizeType.
Do not implement this outside KamiCommon. This was a sealed hierarchy until
spigot-utils dropped to Java 8 so that 1.8.x servers could load it; sealed is Java 17
and has no Java 8 spelling. The closed set is still enforced within the library by the
verifySealedHierarchies build task, which fails if an implementation appears that is
not on the permitted list (MenuSizeRows, MenuSizeType). Nothing can enforce it in your code, hence this annotation.
-
Method Summary
Modifier and TypeMethodDescription@NotNull MenuSizecopy()Deep copies thisMenuSizeinto an identical object clone.@NotNull InventorycreateInventory(@NotNull InventoryHolder owner, @NotNull VersionedComponent title) Creates a newInventorywith the givenInventoryHolderand title.
Uses thisMenuSizeto determine the size of the inventory.intintgetSlotInLastRow(int index) Returns the slot number for the slot in the last row with the given index in that row.intmapPositionToSlot(int row, int col) Maps a position to a slot number.
-
Method Details
-
createInventory
@NotNull @NotNull Inventory createInventory(@NotNull @NotNull InventoryHolder owner, @NotNull @NotNull VersionedComponent title) Creates a newInventorywith the givenInventoryHolderand title.
Uses thisMenuSizeto determine the size of the inventory. -
getSlotInLastRow
int getSlotInLastRow(int index) Returns the slot number for the slot in the last row with the given index in that row. -
copy
-
getNumberOfSlots
int getNumberOfSlots()- Returns:
- the 1-index number of slots in this menu size.
-
mapPositionToSlot
Maps a position to a slot number. For example position (1, 1) maps to slot 0 (top-left) in a traditional inventory.- Parameters:
row- The row (top to bottom) of the position. (1-indexed)col- The column (left to right) of the position. (1-indexed)- Returns:
- The bukkit slot number corresponding to the given position.
- Throws:
IllegalArgumentException- if the given position is outside the bounds of this MenuSize.IllegalStateException- if this method is called on an unsupported MenuSize (including someMenuSizeTypes using non-standardInventoryTypeconfigurations.)
-