TNE Docs
  • Getting Started
    • Welcome
    • Currencies Key Concepts
    • Creating a Currency
    • Breakdown of Main Currency Configuration File
    • Breakdown of Denomination Configuration File
    • Commands & Permissions
    • PlaceholderAPI Placeholders
  • FAQ HOWTO
    • HOW TO: Limit Access to Currencies
    • HOWTO: Contribute Translation
    • HOWTO: Share Balances Across Servers
  • Developers
    • Welcome Developers
    • Contributing
    • API Usage
    • Callbacks
    • Platform Implementations
    • Creating Custom Account Type
    • Creating Custom Balance Handlers
    • Creating Custom Account Statuses
    • Creating Custom Balance Format Rule
    • Creating Custom Currency Loader & Saver
    • Creating Custom Currency Type
    • Creating Custom Transaction Checks
    • Creating Custom TaxType
    • Creating Custom Transaction Type
Powered by GitBook
On this page
  • Creating a Custom Currency Loader and Saver for TheNewEconomy
  • Overview
  • Creating a Custom Currency Loader
  • Creating a Custom Currency Saver
  • Example: Registering Custom Loader and Saver
  • Notes
  1. Developers

Creating Custom Currency Loader & Saver

Creating a Custom Currency Loader and Saver for TheNewEconomy

TheNewEconomy provides flexibility for managing currencies by allowing developers to implement custom currency loaders and savers. These components enable advanced control over how currencies are read from or written to storage.


Overview

Currency Loader

A Currency Loader is responsible for loading currencies and their denominations from a specified storage or configuration source.

Currency Saver

A Currency Saver handles saving currencies and their denominations to storage or configuration files.

Registration

To use your custom loader or saver, register it during the plugin's initialization:

TNECore.eco().currency().setLoader(new CustomCurrencyLoader());
TNECore.eco().currency().setSaver(new CustomCurrencySaver());

Creating a Custom Currency Loader

Step 1: Implement the CurrencyLoader Interface

Create a class that implements the CurrencyLoader interface. Below is an example:

import net.tnemc.core.currency.Currency;
import net.tnemc.core.currency.CurrencyLoader;
import net.tnemc.core.utils.exceptions.NoValidCurrenciesException;

import java.io.File;

public class CustomCurrencyLoader implements CurrencyLoader {

  @Override
  public void loadCurrencies(File directory) throws NoValidCurrenciesException {
    // Logic to load all currencies from the directory
  }

  @Override
  public boolean loadCurrency(File directory, String name) {
    // Logic to load a specific currency by name
    return true;
  }

  @Override
  public boolean loadCurrency(File directory, File curDirectory) {
    // Logic to load a specific currency by file
    return true;
  }

  @Override
  public boolean loadDenominations(File directory, Currency currency) {
    // Logic to load all denominations for a currency
    return true;
  }

  @Override
  public boolean loadDenomination(File directory, Currency currency, String name) {
    // Logic to load a specific denomination
    return true;
  }

  @Override
  public boolean loadDenomination(Currency currency, File denomFile) {
    // Logic to load a specific denomination by file
    return true;
  }
}

Creating a Custom Currency Saver

Step 1: Implement the CurrencySaver Interface

Create a class that implements the CurrencySaver interface. Below is an example:

import net.tnemc.core.currency.Currency;
import net.tnemc.core.currency.CurrencySaver;
import net.tnemc.core.currency.Denomination;

import java.io.File;

public class CustomCurrencySaver implements CurrencySaver {

  @Override
  public void saveCurrencies(File directory) {
    // Logic to save all currencies
  }

  @Override
  public void saveCurrenciesUUID(File directory) {
    // Logic to save only currency UUIDs
  }

  @Override
  public void saveCurrency(File directory, Currency currency) {
    // Logic to save a specific currency
  }

  @Override
  public void saveDenomination(File directory, Currency currency, Denomination denomination) {
    // Logic to save a specific denomination
  }
}

Example: Registering Custom Loader and Saver

To activate your custom loader and saver, register them as follows:

TNECore.eco().currency().setLoader(new CustomCurrencyLoader());
TNECore.eco().currency().setSaver(new CustomCurrencySaver());

Notes

  1. Error Handling: Ensure your loader and saver handle errors gracefully to avoid corrupting currency data.

  2. File Structure: Maintain a clear file structure for storing and retrieving currencies and denominations.

  3. Testing: Thoroughly test your loader and saver to ensure compatibility with the TNE ecosystem.


By implementing and registering custom loaders and savers, you can extend TheNewEconomy's capabilities to integrate with unique storage solutions or advanced configurations.

PreviousCreating Custom Balance Format RuleNextCreating Custom Currency Type

Last updated 5 months ago