Creating Custom Balance Handlers
Creating a Custom HoldingsHandler for TheNewEconomy
TheNewEconomy allows developers to extend its functionality by creating custom HoldingsHandler
implementations. These handlers enable the integration of various storage sources for player holdings, such as virtual wallets, inventory, experience levels, or external systems like banks.
What is a HoldingsHandler?
A HoldingsHandler
is an interface that provides methods to:
Set holdings for a player or account.
Retrieve holdings from a specific source.
Determine whether the handler supports specific currencies or accounts.
Steps to Create a Custom HoldingsHandler
1. Implement the HoldingsHandler Interface
Your custom class must implement the HoldingsHandler
interface. Below is a template example:
2. Register the Handler with TNE
After implementing the HoldingsHandler
interface, register your custom handler with TNE:
This ensures that TNE uses your handler when interacting with supported currencies or account types.
Example Implementations
EnderChestHandler
The EnderChestHandler
manages holdings stored in a player's Ender Chest:
ExperienceHandler
The ExperienceHandler
handles player holdings based on their experience points:
Key Points
Identifier: Each handler must have a unique identifier returned by the
identifier()
method.Compatibility: Use the
supports()
method to restrict the handler to specific currencies or types.Data Handling: Decide whether holdings should be saved in TNE's database or managed externally via the
database()
method.Integration: Handlers can interact with specific storage systems, such as inventory or external databases.
Notes
Use existing handlers like
VirtualHandler
,InventoryHandler
, orExperienceHandler
as references.Always register your custom handler with
TNECore.eco().addHandler()
to make it active in TNE.
By creating a custom HoldingsHandler
, you can expand TheNewEconomy to integrate with diverse systems and provide unique gameplay experiences.
Last updated