Pagination
This page describes how to register paginations in an inventory provider.
Pagination is the fact of splitting a list of values into pages. This is very useful when you want to display a large list of values in a container with a restricted size.
In CraftVentory, you can paginate a list of Java objects and convert each item to an InventoryItem
to be displayed in an inventory.
Pagination configuration
To learn how to configure a pagination in an inventory configuration file, please refer to the Paginations configuration section.
Create a pagination provider
Like inventories, paginations are configurable. As a pagination relies on a list of Java object, there must be a link between its configuration and this list.
Let's say we want to paginate the following list of integers:
To paginate this list, you must create a pagination provider to let the library understand what data is paginated. This can be done by redefining the addProviders(ProviderManager manager)
method from the InventoryDescriptor
interface:
The PaginationProvider
class takes the following paramaters in its constructors:
paginationId
: The id of the pagination. It must be the same as the one defined in the configuration file of the inventory.dataType
: The data type that will be paginated. In the example, it is anInteger
but it must be any Java class type.supplier
: A function that retrieves and returns the list of values to paginate. Here, we simply use the variable values defined above but we can imagine that the list comes from another class.
An inventory can contain several paginations. Each pagination must have its own pagination provider.
Example
Configuration :
Last updated