KtInventory

abstract class KtInventory(plugin: Plugin, val line: Int, altColorChar: Char? = '&') : AbstractKtInventory

Abstract inventory class that creates an inventory with a customizable title. Extends AbstractKtInventory to provide basic inventory functionality.

Since

2.0.0

Parameters

plugin

The plugin instance

line

Number of inventory rows

altColorChar

Character used for color codes in the title. Default is '&'. Set to null to disable color code translation.

Constructors

Link copied to clipboard
constructor(plugin: Plugin, line: Int, altColorChar: Char? = '&')

Properties

Link copied to clipboard

Map of all buttons in the inventory

Link copied to clipboard
val line: Int

Number of rows in the inventory (must be between 1 and 6)

Link copied to clipboard
val size: Int

Total size of inventory (line * 9)

Link copied to clipboard

Storage options for this inventory's storable components

Link copied to clipboard

Set of all storable components in this inventory

Link copied to clipboard
val viewers: List<HumanEntity>

List of entities currently viewing this inventory

Functions

Link copied to clipboard
override fun button(slot: Int, item: KtInventoryButton<KtInventoryBase>)

Adds an existing button to a single slot

fun button(vararg slot: Int, item: KtInventoryButton<KtInventoryBase>)

Adds an existing button to multiple slots

fun button(slot: Int, itemStack: ItemStack, onClick: (KtInventoryButton.ClickEvent<AbstractKtInventory>) -> Unit = {})

Adds a button to a single slot with the given item and click handler

fun button(vararg slot: Int, itemStack: ItemStack, onClick: (KtInventoryButton.ClickEvent<AbstractKtInventory>) -> Unit = {})
fun button(slots: Iterable<Int>, itemStack: ItemStack, onClick: (KtInventoryButton.ClickEvent<AbstractKtInventory>) -> Unit = {})

Adds a button to multiple slots with the given item and click handler

Link copied to clipboard

Creates a new inventory button with the specified item and click handler

Link copied to clipboard
open override fun getInventory(): @NotNull Inventory
Link copied to clipboard
fun getItem(slot: Int): @Nullable ItemStack?

Gets the item at the specified slot

Link copied to clipboard

Gets all storables that have the given slot

Gets all storables that have any of the given slots

Link copied to clipboard
open fun onClick(event: InventoryClickEvent)

Called when top inventory is clicked

Link copied to clipboard
open fun onClickBottom(event: InventoryClickEvent)

Called when bottom inventory is clicked

Link copied to clipboard
open fun onClose(event: InventoryCloseEvent)

Called when inventory is closed

Link copied to clipboard
open fun onDrag(event: InventoryDragEvent)

Called when items are dragged in inventory

Link copied to clipboard
open fun onOpen(event: InventoryOpenEvent)

Called when inventory is opened

Link copied to clipboard
override fun open(player: HumanEntity)

Opens this inventory for the given player

Link copied to clipboard

Saves the state of all storable components in this inventory

Link copied to clipboard
fun setItem(slot: Int, item: ItemStack?)

Sets an item at the specified slot

Link copied to clipboard
fun storable(initialize: () -> List<ItemStack?> = { emptyList() }, onPreClick: (KtInventoryStorable.ClickEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onClick: (KtInventoryStorable.ClickEvent) -> Unit = {}, onPreDrag: (KtInventoryStorable.DragEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onDrag: (KtInventoryStorable.DragEvent) -> Unit = {}, save: (List<ItemStack?>) -> Unit = {})

Add a storable component using all slots in the inventory

fun storable(vararg slots: Int, initialize: () -> List<ItemStack?> = { emptyList() }, onPreClick: (KtInventoryStorable.ClickEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onClick: (KtInventoryStorable.ClickEvent) -> Unit = {}, onPreDrag: (KtInventoryStorable.DragEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onDrag: (KtInventoryStorable.DragEvent) -> Unit = {}, save: (List<ItemStack?>) -> Unit = {})
fun storable(slots: Iterable<Int>, initialize: () -> List<ItemStack?> = { emptyList() }, onPreClick: (KtInventoryStorable.ClickEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onClick: (KtInventoryStorable.ClickEvent) -> Unit = {}, onPreDrag: (KtInventoryStorable.DragEvent) -> KtInventoryStorable.EventResult = { KtInventoryStorable.EventResult.Allow }, onDrag: (KtInventoryStorable.DragEvent) -> Unit = {}, save: (List<ItemStack?>) -> Unit = {}): KtInventoryStorable

Add a storable component with the specified slot numbers

Link copied to clipboard
abstract fun title(): String

Gets the title of the inventory. The title can include color codes if altColorChar is not null.