Enhancements
This page describes the enhancement concept to customize inventories programmatically.
Last updated
This page describes the enhancement concept to customize inventories programmatically.
Last updated
To understand the enhancement concept and why it was implemented in CraftVentory, you first need to have a brief overview on how the library works. CraftVentory is built on three modules:
Configuration: Responsible for loading an inventory from a configuration file and store this configuration as a set of Java objects.
Transform: Bridge between the Configuration module and the Inventory module which is responsible for dynamically converting the configuration to a working inventory.
Inventory: The working inventory that can be opened and viewed by players in-game, with events and actions.
The image below illustrates the links between all of these modules:
During the Transformation process, each inventory property is converted by a specific provider which is responsible to do the transformation. This enables to customize the behavior dependently of the transformed property.
The enhancement step takes place during the Transformation process and is executed by a provider on the property it handles. It allows to add custom Java code to customize and enhance properties programatically before they are provided and without changing the original configuration.
Enhancements work with two specific objects:
Context: Class that contains additional data that may be useful for the enhancement. See this page for more information.
DTO (Data Transfer Object): Class that contains the inventory properties currently transformed. It provides getters and setters to modify some of these properties.
To create a new enhancement, you first need to know the name and the class of the DTO it will manipulate. Below is the list of all the available DTO:
TITLE
TitleDto
INVENTORY_TYPE
InventoryTypeDto
INVENTORY_ITEM
InventoryItemDto
PAGINATION
PaginationDto
PAGINATION_ITEM
PaginationItemDto
PAGINATION_PREVIOUS_PAGE_ITEM
PaginationPageItemDto
PAGINATION_NEXT_PAGE_ITEM
PaginationPageItemDto
Enhancements are defined using the generic Enhancement
class. The following code gives an example of enhancement for pagination items.
Enhancements are registered specifically for an inventory in its inventory descriptor and are then provided to its provider.
The following code registers the enhancement created in the section above by redefining the addEnhancements(EnhancementManager manager)
method of the InventoryDescriptor
interface:
In this code, you must provide as first argument the name of the DTO used. This name can be found in the table defined in a previous section of this page.
Result: