-
-
Notifications
You must be signed in to change notification settings - Fork 6
API
TNE provides an internal API in addition to Vault support. This page deals only with the TNE API. If you're looking for the Vault API, you'll have to go to their page found here.
To use the TNEAPI, you'll have to add the TNE Core as a dependency to your project. Don't worry though, the core doesn't have any implementation-specific code.
<repository>
<id>codemc-releases</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>EconomyCore</artifactId>
<version>0.1.3.1-RELEASE-1</version>
<scope>provided</scope>
</dependency>
To get the TNE API after you've added TNE as a library into your project, you may simply use the API method in the TNECore class.
import net.tnemc.core.api.TNEAPI;
TNEAPI api = TNECore.api();
TNE doesn't use the normal event system that most other plugins utilize because it would require TNE to include a completely irrelevant and overly engineered platform-agnostic event system. This is why TNE sticks to using a callback-style system based on the Function system in Java. The way this is accessed is different than your normal Bukkit events, but will also allow you to utilize the same event code for TNE on any platform.
In order to add a "consumer" to a callback, you'll have to access the TNE callback manager. This could be done through the callbacks() method in the TNEAPI class or through the main TNE class itself, TNECore.callbacks(). Before adding a callback, make sure you know which callback you want to implement first. You may find the various class here.
//We will access the callback manager through the API class.
TNECore.api().callbacks().addConsumer("insert callback name", (callback)->{
//TODO: add your code here.
return false;
});
In this example, you'll notice you need to specify the callback name as well as your function, which should take the callback class as an argument, and should return a boolean. The boolean which is returned should be based on whether the callback should be canceled or not. If you wish to cancel the action associated with the callback, simply return true; otherwise, false. TNE also has an enum, which provides easy access to the names for every built-in callback.
If you wish to implement a new callback that other addons may utilize, this is done using the Callback Manager too.
//You need to provide the name for your callback, as well as the class associated with the callback.
TNECore.api().callbacks().addCallback("your_callback_name", YourCallbackClass.class);
//To call your custom callback, simply provide the instance of your callback class object.
TNECore.api().callbacks().call(new YourCallbackClass());
Through the TNE API, you may add custom Holdings Handlers or override the default ones. These handlers are used to calculate balances for a given currency type. Holdings handlers have a few different methods that may be used to customize your handler, depending on your use case.
If you want to create an addon for TNE that adds additional balance holding methods, such as an ATM or adding support for item currency to your backpack plugin, these handlers provide a hack-free method of doing just this. They also have the added benefit of utilizing the TNE balance database, so you don't have to worry about providing a storage method for your custom balance handler, but players may still have their funds associated with their account, whether they're on or offline.
/**
* The identifier for this handler.
* @return The identifier that represents this handler.
*/
Identifier identifier();
/**
* Used to determine if this handler may be used for the specified {@link CurrencyType}.
* @param type The currency type.
* @return True if it supports the currency type; otherwise, false.
*/
boolean supports(CurrencyType type);
/**
* Used to determine if this handler may be used for the specified {@link Account}. This defaults
* to true for all accounts.
* @param account The account.
* @return True if it supports the account; otherwise, false.
*/
default boolean appliesTo(Account account) {
return true;
}
/**
* Used to set the holdings for a specific account.
*
* @param region The name of the region involved. This is usually a world but could be something
* else such as a world guard region name/identifier.
* @param currency The instance of the currency to use.
* @param type The currency type.
* @param amount The amount to set the player's holdings to.
*/
void setHoldings(Account account, String region, Currency currency, CurrencyType type, BigDecimal amount);
/**
* Used to get the holdings for a specific account from this handler.
*
* @param account The Account.
* @param region The name of the region involved. This is usually a world but could be something
* else, such as a world guard region name/identifier.
* @param currency The instance of the currency to use.
* @param type The currency type.
* @return The holdings for the specific account.
*/
HoldingsEntry getHoldings(Account account, String region, Currency currency, CurrencyType type);
As you can see, you are able to modify everything from what currency types you associate your handler with to what players it applies to. This means you could have a custom holdings handler that only applies to accounts with a specific permission node or only to item-based currencies.
Identifiers should use the format: new Identifier("plugin-name", "HANDLER_NAME")
. The handler name should be in all caps and with underscores in place of spaces to maintain the standard found within TNE itself.
In order to override default handlers, just add a new handler using the default identifier for the built-in handler. The default handlers are served as a public static final field in the EconomyManager class. It should be noted that the NORMAL and DATABASE identifiers have no associate handlers and are used solely for internal purposes.
If you're looking for documentation related to making a custom module for TNE, check out the module page.