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 Tax Type for TheNewEconomy
  • Overview
  • Steps to Create a Custom Tax Type
  • Step 2: Register the Custom Tax Type
  • Example: Default Tax Types in TNE
  • Key Methods in TaxType
  • Notes
  1. Developers

Creating Custom TaxType

Creating a Custom Tax Type for TheNewEconomy

In TheNewEconomy, tax types define how taxation is calculated and applied during transactions. This guide explains how to implement and register a custom tax type.


Overview

What is a Tax Type?

A Tax Type is a mechanism that determines how taxes are calculated based on transaction amounts. Examples include flat taxes or percentage-based taxes.

Registration

To use a custom tax type, register it during the plugin’s initialization:

TNECore.eco().transaction().addTax(new CustomTaxType());

Steps to Create a Custom Tax Type

Step 1: Implement the TaxType Interface

Create a class that implements the TaxType interface. Below is an example of a custom tax type called CustomFlatTaxType:

import net.tnemc.core.transaction.tax.TaxType;
import java.math.BigDecimal;

public class CustomFlatTaxType implements TaxType {

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

  @Override
  public String asString(final BigDecimal tax) {
    return tax.toPlainString();
  }

  @Override
  public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
    // Returns the tax as a flat value
    return tax;
  }
}

Step 2: Register the Custom Tax Type

To register the tax type, use the following code:

TNECore.eco().transaction().addTax(new CustomFlatTaxType());

Example: Default Tax Types in TNE

FlatType

Applies a fixed tax amount regardless of the transaction size:

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

@Override
public String asString(final BigDecimal tax) {
  return tax.toPlainString();
}

@Override
public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
  return tax;
}

PercentileType

Applies a tax as a percentage of the transaction amount:

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

@Override
public String asString(final BigDecimal tax) {
  return tax.multiply(new BigDecimal(100)).toPlainString() + "%";
}

@Override
public BigDecimal handleTaxation(final BigDecimal amount, final BigDecimal tax) {
  return amount.multiply(tax);
}

Key Methods in TaxType

Method
Description

name()

Returns the unique identifier for the tax type.

asString()

Converts the tax value to a display-friendly string.

handleTaxation()

Implements the logic to calculate the tax based on the transaction amount and tax value.


Notes

  • Dynamic Taxation: Customize handleTaxation() to apply taxes dynamically based on complex rules.

  • Unique Identifier: Ensure name() returns a unique identifier for the tax type.

  • Testing: Test your tax type to ensure it integrates properly with TNE's transaction system.


By implementing and registering custom tax types, you can introduce unique taxation systems tailored to your server's economic rules.

PreviousCreating Custom Transaction ChecksNextCreating Custom Transaction Type

Last updated 5 months ago