# Creating Custom Currency Type

## Creating a Custom Currency Type for TheNewEconomy

In **TheNewEconomy (TNE)**, currency types define the behavior of a currency, such as how it interacts with players' accounts, whether it uses virtual balances, physical items, or other mechanisms. This guide will help you implement and register a custom currency type.

***

### Overview

#### What is a Currency Type?

A **Currency Type** is an implementation of the `CurrencyType` interface that defines:

1. **Behavior**: Determines how the currency is stored, accessed, and interacted with.
2. **Compatibility**: Specifies whether it supports features like virtual balances, physical items, or both.
3. **Integration**: Provides the logic for interacting with holdings and regions.

#### Registration

To register your custom currency type:

```java
TNECore.eco().currency().addType(new CustomCurrencyType());
```

***

### Steps to Create a Custom Currency Type

#### Step 1: Implement the `CurrencyType` Interface

Create a class that implements the `CurrencyType` interface. Below is an example of a custom type called `CustomType`:

```java
import net.tnemc.core.EconomyManager;
import net.tnemc.core.account.Account;
import net.tnemc.core.currency.CurrencyType;
import net.tnemc.core.utils.Identifier;

import java.math.BigDecimal;

public class CustomType implements CurrencyType {

  @Override
  public String name() {
    return "custom";
  }

  @Override
  public String description() {
    return "A custom currency type with unique behavior.";
  }

  @Override
  public boolean supportsVirtual() {
    return false; // Specify if virtual balances are supported
  }

  @Override
  public Identifier defaultHandler() {
    return EconomyManager.VIRTUAL; // Specify the default handler
  }

  @Override
  public boolean supportsExchange() {
    return false; // Specify if this currency supports exchanging items and virtual balances
  }

  @Override
  public boolean setHoldings(Account account, String region, Currency currency, Identifier type, BigDecimal amount) {
    // Define how holdings are set for this currency type
    return true;
  }
}
```

***

### Example: Default Currency Types in TNE

#### VirtualType

A simple currency type that is entirely virtual (e.g., command-based money):

```java
@Override
public String name() {
  return "virtual";
}

@Override
public String description() {
  return "A simple currency type that is strictly virtual.";
}

@Override
public Identifier defaultHandler() {
  return EconomyManager.VIRTUAL;
}
```

#### ItemType

A currency type based on physical items:

```java
@Override
public String name() {
  return "item";
}

@Override
public String description() {
  return "A currency based solely on physical items.";
}

@Override
public Identifier defaultHandler() {
  return EconomyManager.INVENTORY_ONLY;
}
```

#### MixedType

A combination of virtual and item-based currencies:

```java
@Override
public String name() {
  return "mixed";
}

@Override
public String description() {
  return "A currency that is a mixture of item and virtual types.";
}

@Override
public boolean supportsExchange() {
  return true; // Enables exchanging items and virtual balances
}
```

***

### Registering the Custom Currency Type

To register your custom type, use the following code during your plugin's initialization:

```java
TNECore.eco().currency().addType(new CustomType());
```

***

### Key Methods in `CurrencyType`

| Method               | Description                                                               |
| -------------------- | ------------------------------------------------------------------------- |
| `name()`             | Returns the unique name of the currency type.                             |
| `description()`      | Returns a brief description of the currency type.                         |
| `supportsVirtual()`  | Indicates if the currency supports virtual balances.                      |
| `defaultHandler()`   | Specifies the default holdings handler for the currency type.             |
| `setHoldings()`      | Defines how the holdings are set for the currency type.                   |
| `supportsExchange()` | Indicates if the currency supports exchanging items and virtual balances. |

***

### Notes

* **Unique Behavior**: Use the `setHoldings()` method to implement unique behavior for your custom type.
* **Compatibility**: Implement `supportsVirtual()` and `supportsExchange()` to ensure compatibility with TNE's features.
* **Thorough Testing**: Test your custom type to confirm its behavior aligns with your expectations.

***

By following this guide, you can create and integrate custom currency types into **TheNewEconomy**, enabling tailored behavior for your server's economy system.


---

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

```
GET https://tne.gitbook.io/tne-docs/developers/creating-custom-currency-type.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
