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 Type for TheNewEconomy
  • Overview
  • Steps to Create a Custom Currency Type
  • Example: Default Currency Types in TNE
  • Registering the Custom Currency Type
  • Key Methods in CurrencyType
  • Notes
  1. Developers

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:

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:

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

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

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

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

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.

PreviousCreating Custom Currency Loader & SaverNextCreating Custom Transaction Checks

Last updated 5 months ago