Creating Custom Balance Handlers
Last updated
Last updated
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.
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.
Your custom class must implement the HoldingsHandler
interface. Below is a template example:
import net.tnemc.core.account.Account;
import net.tnemc.core.account.holdings.HoldingsEntry;
import net.tnemc.core.account.
After implementing the HoldingsHandler
interface, register your custom handler with TNE:
TNECore.eco().addHandler(new CustomHandler());
This ensures that TNE uses your handler when interacting with supported currencies or account types.
The EnderChestHandler
manages holdings stored in a player's Ender Chest:
@Override
public boolean setHoldings(Account account, String region, Currency currency, CurrencyType type, BigDecimal amount) {
account.getWallet().setHoldings(new HoldingsEntry(region, currency.getUid(), amount, identifier()));
// Logic to update items in Ender Chest
return true;
}
The ExperienceHandler
handles player holdings based on their experience points:
@Override
public boolean setHoldings(Account account, String region, Currency currency, CurrencyType type, BigDecimal amount) {
if(account instanceof PlayerAccount player && player.isOnline()) {
Experience.setExperience(player.getPlayer().get(), amount.intValueExact());
}
return true;
}
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.
Use existing handlers like VirtualHandler
, InventoryHandler
, or ExperienceHandler
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.