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:


Example: Default Currency Types in TNE

VirtualType

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

ItemType

A currency type based on physical items:

MixedType

A combination of virtual and item-based currencies:


Registering the Custom Currency Type

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


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.

Last updated