VitalPagedInventory

Defines a pageable inventory menu within the Vital-Framework. A pageable inventory can be used to display an inventory, whose content may extend to multiple inventory pages. Useful for creating "scrollable" content inside an inventory GUI, or a shop, selector, etc.

By default, the class will be a bean.

@VitalPagedInventory.Info(fromSlot = 0, toSlot = 9)
@VitalInventory.Info(type = VitalInventory.Type.GENERIC_9X1, name = "MyPagedInventory")
public class MyPagedInventory extends VitalPagedInventory {
@Override
public void onPageChange(int page, Player player) {
// This function is called when a specific player changes the page of his inventory.
}

// ...
}

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class Info(val fromSlot: Int = 0, val toSlot: Int = 0)

Defines the info for a VitalPagedInventory. This annotation must be used on-top of VitalInventory.Info.

Properties

Link copied to clipboard
val actions: MutableMap<UUID, MutableMap<Int, Consumer<InventoryClickEvent>>>
Link copied to clipboard
val background: ItemStack
Link copied to clipboard
open override val info: MutableMap<Class<out Annotation>, Annotation>
Link copied to clipboard
val items: MutableMap<UUID, MutableMap<Int, ItemStack?>>
Link copied to clipboard
val playerInventories: MutableMap<UUID, InventoryView>

Functions

Link copied to clipboard
open fun click(e: InventoryClickEvent)

Internal function to handle a InventoryClickEvent for this inventory. If the clicked item has an action attached to it via setItem, the action will be triggered.

Link copied to clipboard
override fun close(player: SpigotPlayer)

Closes this inventory for the given player. This function will clean up the state for this inventory and eventually call the onClose lifecycle function for the given player.

Link copied to clipboard
fun getActions(playerUniqueId: UUID): MutableMap<Int, Consumer<InventoryClickEvent>>

Gets all mapped actions for the given playerUniqueId. This function will never return null, even if the given playerUniqueId doesn't have this inventory open.

Link copied to clipboard
open fun <T : Annotation> getInfo(type: Class<T>): T
Link copied to clipboard
fun getInventory(playerUniqueId: UUID): InventoryView?

Gets the actual InventoryView for the given playerUniqueId. This function will return null if the given playerUniqueId doesn't have this inventory open.

Link copied to clipboard
fun getItems(playerUniqueId: UUID): MutableMap<Int, ItemStack?>

Gets all items for the given playerUniqueId. This function will never return null, even if the given playerUniqueId doesn't have this inventory open.

Link copied to clipboard
fun getMaxPage(playerUniqueId: UUID): Int

Gets the current max page of the given playerUniqueId. This function will always at minimum return 1, even if the given player does not have this inventory open.

Link copied to clipboard
fun getPage(playerUniqueId: UUID): Int

Gets the current page of the given playerUniqueId. This function will always at minimum return 1, even if the given player does not have this inventory open.

Link copied to clipboard

Gets the page content amount of this inventory defined by (Info.fromSlot + 1) - Info.toSlot.

Link copied to clipboard

Checks if the given SpigotPlayer currently has this inventory open.

Link copied to clipboard
override fun open(player: SpigotPlayer, previousInventory: VitalInventory? = null)
fun open(player: SpigotPlayer, previousInventory: VitalInventory? = null, page: Int = 1, totalContent: Int? = null)

Opens this inventory for the given player. Optionally, a previousInventory can be passed to make back-traversal possible.

Link copied to clipboard
fun setItem(player: SpigotPlayer, slot: Int, item: ItemStack?, action: Consumer<InventoryClickEvent> = Consumer {})

Sets the given item in the slot for the inventory of the given player. Once the player opens this inventory, the actual InventoryView will be populated with all items set via this function. Additionally, an item may have an action attached to it.

Link copied to clipboard
fun setPage(page: Int, player: SpigotPlayer, totalContent: Int? = null)

Sets the given page for the given player. Additionally totalContent can be defined to automatically calculate the maxPages for the given player.

Link copied to clipboard
fun update()

Updates this inventory for all players currently viewing it. Calling this function will call the onUpdate lifecycle function.

override fun update(player: SpigotPlayer)

Updates this inventory for the given player and additionally calls the onPageChange lifecycle.

Link copied to clipboard
fun updateMaxPage(playerUniqueId: UUID, totalContent: Int)

Updates the maximum number of pages based on the total amount of content.