> For the complete documentation index, see [llms.txt](https://tne.gitbook.io/tne-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tne.gitbook.io/tne-docs/developers/creating-custom-currency-loader-and-saver.md).

# 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:

```java
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:

```java
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:

```java
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:

```java
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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tne.gitbook.io/tne-docs/developers/creating-custom-currency-loader-and-saver.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
