Creating Custom TaxType
Last updated
Last updated
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.
A Tax Type is a mechanism that determines how taxes are calculated based on transaction amounts. Examples include flat taxes or percentage-based taxes.
To use a custom tax type, register it during the plugin’s initialization:
TNECore.eco().transaction().addTax(new CustomTaxType());
TaxType
InterfaceCreate 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 {
To register the tax type, use the following code:
TNECore.eco().transaction().addTax(new CustomFlatTaxType());
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;
}
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);
}
TaxType
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.
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.