Declare an inventory
This page describes how to declare and register an inventory in Java.
In CraftVentory, an inventory is declared using the InventoryDescriptor
interface. This interface is then mapped into an InventoryProvider
which is a bridge between an InventoryConfig
and an in-game inventory.
Create an InventoryDescriptor
Using the InventoryDescriptor
interface, you can declare some properties of your inventory: the configuration file to load, the inventory id, its hooks, paginations and enhancements. The following code shows a basic implementation of this interface:
The interface also contains default methods you can redefine to register pagination providers, hooks and enhancements. These methods are not shown in the example above.
As these methods are not necessary for each inventory, the choice was make to declare them as default empty methods in the InventoryDescriptor
interface. Thus, when using them, you don't need to make a call using the super
keyword.
Create an InventoryProvider
An InventoryProvider
encapsulates an InventoryDescriptor
to create and provide an inventory. To be reused, inventory providers are registered in an InventoryService
. The following code illustrates how to create and register a provider using a descriptor:
Advanced concepts
Paginations
The page Pagination describes how to create a new pagination to paginate a large list of results in the inventory.
Placeholders
The page Placeholders describes how to create a new placeholder to be able to display custom values.
Enhancements
The page Enhancements describes how you can enhance some inventory properties manually using Java code.
Hooks
The page Hooks describes how you can execute Java code when events happen for an inventory.
Last updated