Skip to content

KInventory

Devin Fritz edited this page May 23, 2024 · 5 revisions

Relevant pages

Building an Inventory

To build a default inventory, with default bukkit behaviour, you should use the kInventory builder method:

val inventory = kInventory(sender, 5.rows, InventoryType.CHEST) {}

This will build an inventory with the size of 5x9 with a chest type. For the holder, you can use any kind of Bukkit player.

To make it easier to handle rows, you can use the .rows extension function on an integer.

Building the inventory is done inside the context delivered by the builder function. You can use the methods of the inventory to build it.

val inventory = kInventory(sender, 5.rows, InventoryType.CHEST) {
    setItem(1, 4, kItem(Material.DIAMOND_PICKAXE) {})
}

This will set the given item in row 1 slot 4. Learn more here


Set items

Items can be set using 2 ways.

  • Using the setItem method
  • Using a kRow to directly set a row

Usage of animations

To learn about the concept of animations take a look at here.

Inside the inventory, you can set an openingAnimation, which will play as soon as the inventory is opened by a player. Using the isAnimating() function you can also check if the inventory is currently inside an animation.

Saving animations

Animations can also be saved, using the "animations" mapping in the inventory. You can then access them later, if required. Then using the startAnimation() method, you can play an animation.

Inventory events

To listen to events on the inventory you can use one of the close/open listeners like the following:

val inventory = kInventory(sender, 5.rows, InventoryType.CHEST) {
    onOpen {
        // do something
    }

    onClose {
        // do something
    }
}

Inventories

Item management

Utility

Clone this wiki locally