Creating Custom Balance Format Rule
Adding Custom Currency Formatting Rules for TheNewEconomy
The currency formatting system in TheNewEconomy allows developers to define custom rules for displaying currencies. These rules are used in the Format
configuration of a currency YAML file (e.g., USD.yml
) and control how currency balances are formatted.
Overview of Format Rules
A Format Rule is a component that defines how a placeholder in the currency format is replaced with dynamic content. For example, <symbol>
can be replaced with $
, and <decimal>
can include the decimal separator.
Example Default Format in YAML
Creating a Custom Format Rule
1. Implement the FormatRule
Interface
FormatRule
InterfaceTo create a custom formatting rule, implement the FormatRule
interface. Below is an example of a rule that adds a custom placeholder <custom>
, which displays a fixed string.
2. Register the Rule
Register your custom rule with the CurrencyFormatter
class to make it available in TNE:
This should be done during your plugin or integration's initialization phase.
Examples of Default Rules
SymbolRule
Replaces <symbol>
with the currency symbol:
DecimalRule
Handles the <decimal>
placeholder, adding or omitting the decimal separator based on the amount:
Example Custom Formatting Rule Usage
YAML Configuration
After adding your custom rule, it can be used in the Format
configuration of a currency YAML file:
When applied, the <custom>
placeholder will be replaced with the value defined in your CustomRule
.
Notes
Registration: Always register custom rules using
CurrencyFormatter.addRule()
.Compatibility: Ensure your custom rules align with TNE's currency formatting system.
Dynamic Content: Use the
Account
andHoldingsEntry
parameters in your rule to provide dynamic formatting based on player or balance data.
By following these steps, you can expand TNE's currency formatting system to suit your server's unique needs. For further reference, review default rules such as SymbolRule
, DecimalRule
, and ShortenRule
.
Last updated