Creating Custom Account Type

Adding Custom Account Types to TheNewEconomy

TheNewEconomy allows developers to create and integrate custom account types for various plugins or unique server setups. This guide provides an example of adding custom account types using the Towny plugin as a reference.


Steps to Add Custom Account Types

1. Define Your Custom Account Class

Custom account types should extend the NonPlayerAccount or PlayerAccount class. For example, here’s a NationAccount linked to a Towny Nation:

public class NationAccount extends NonPlayerAccount {

  public NationAccount(final UUID identifier, final String name) {
    super(identifier, name);
    this.identifier = identifier;
  }

  @Override
  public String type() {
    return "nation";
  }

  @Override
  public UUID generateIdentifier(final String name) {
    try {
      return Objects.requireNonNull(TownyAPI.getInstance().getNation(name)).getUUID();
    } catch (final Exception ignore) {
      return super.generateIdentifier(name);
    }
  }
}

Similarly, a TownAccount can represent Towny Town accounts:


2. Implement Account Type Validation

Create validation classes by implementing the AccountTypeCheck interface. This ensures only valid identifiers are used for your custom accounts:

NationCheck

TownCheck


3. Register the Custom Account Types

In a handler class, register your custom account types with TNE using the CallbackManager. Below is an example of how to integrate Towny account types:


4. Hook into Plugin Callbacks

Ensure your custom account types are added during the appropriate lifecycle events by using the CallbackManager. Below is an example:


Key Points to Remember

  • Account Type Name: Ensure the type() method in your custom account class returns a unique, descriptive string (e.g., "town" or "nation").

  • Validation: Use AccountTypeCheck to validate identifiers for your account type.

  • Integration: Register custom account types through the CallbackManager to ensure they are loaded when TNE initializes.


By following these steps, you can create and integrate custom account types tailored to your server’s needs. For further details, refer to the TNE Developer Documentation or the source files provided.

Last updated