Developer API

ExcellentEconomy provides a robust and easy-to-use API for developers looking to integrate their plugins with it.

Replace {VERSION} with the latest version shown on the badge below:

Repository:

<repository>
  <id>nightexpress-releases</id>
  <url>https://repo.nightexpressdev.com/releases</url>
</repository>

Dependency:

<dependency>
  <groupId>su.nightexpress.excellenteconomy</groupId>
  <artifactId>ExcellentEconomy</artifactId>
  <version>{VERSION}</version>
  <scope>provided</scope>
</dependency>

Repository:

maven { url = 'https://repo.nightexpressdev.com/releases' }

Dependency:

compileOnly("su.nightexpress.excellenteconomy:ExcellentEconomy:{VERSION}")

Events

The following events are available:

  • ChangeBalanceEvent Cancellable - Triggered when a player's currency balance is about to be modified.

API Usage

Use the Bukkit ServiceManager to get the API instance:

RegisteredServiceProvider<ExcellentEconomyAPI> provider = Bukkit.getServer().getServicesManager().getRegistration(ExcellentEconomyAPI.class);
if (provider != null) {
    ExcellentEconomyAPI api = provider.getProvider();
}

The API offers both Asynchronous methods (for database calls) and Cached methods (for active players).


Operation Context

I highly recommend you to create your own OperationContext and pass it to API methods:

OperationContext myContext = OperationContext.custom("YourPlugin")
    .silentFor(NotificationTarget.USER, NotificationTarget.EXECUTOR, NotificationTarget.CONSOLE_LOGGER);

Operations Lockdown

You can also check whether currency operations are allowed before you call API methods. For example, operations are disabled during data migration or balance reset process.

boolean canPerformOperations = api.canPerformOperations();

Retrieve Balance

// Asynchronous
CompletableFuture<Double> future = api.getBalanceAsync(UUID playerId, String currencyName);
CompletableFuture<Double> future = api.getBalanceAsync(UUID playerId, ExcellentCurrency currency);

// Cached
double balance = api.getBalance(Player player, String currencyId);
double balance = api.getBalance(Player player, ExcellentCurrency currency);

Deposit Currency

// Asynchronous
CompletableFuture<OperationResult> future = api.depositAsync(UUID playerId, String currencyName, double amount);
CompletableFuture<OperationResult> future = api.depositAsync(UUID playerId, String currencyName, double amount, OperationContext context);
CompletableFuture<OperationResult> future = api.depositAsync(UUID playerId, ExcellentCurrency currency, double amount);
CompletableFuture<OperationResult> future = api.depositAsync(UUID playerId, ExcellentCurrency currency, double amount, OperationContext context);

// Cached
boolean result = api.deposit(Player player, String currencyId, double amount);
boolean result = api.deposit(Player player, String currencyId, double amount, OperationContext context);
boolean result = api.deposit(Player player, ExcellentCurrency currency, double amount);
boolean result = api.deposit(Player player, ExcellentCurrency currency, double amount, OperationContext context);

Withdraw Currency

// Asynchronous
CompletableFuture<OperationResult> future = api.withdrawAsync(UUID playerId, String currencyId, double amount);
CompletableFuture<OperationResult> future = api.withdrawAsync(UUID playerId, String currencyId, double amount, OperationContext context);
CompletableFuture<OperationResult> future = api.withdrawAsync(UUID playerId, ExcellentCurrency currency, double amount);
CompletableFuture<OperationResult> future = api.withdrawAsync(UUID playerId, ExcellentCurrency currency, double amount, OperationContext context);

// Cached
boolean result = api.withdraw(Player player, String currencyId, double amount);
boolean result = api.withdraw(Player player, String currencyId, double amount, OperationContext context);
boolean result = api.withdraw(Player player, ExcellentCurrency currency, double amount);
boolean result = api.withdraw(Player player, ExcellentCurrency currency, double amount, OperationContext context);

Set Currency Balance

// Asynchronous
CompletableFuture<OperationResult> future = api.setBalanceAsync(UUID playerId, String currencyId, double amount);
CompletableFuture<OperationResult> future = api.setBalanceAsync(UUID playerId, String currencyId, double amount, OperationContext context);
CompletableFuture<OperationResult> future = api.setBalanceAsync(UUID playerId, ExcellentCurrency currency, double amount);
CompletableFuture<OperationResult> future = api.setBalanceAsync(UUID playerId, ExcellentCurrency currency, double amount, OperationContext context);

// Cached
boolean result = api.setBalance(Player player, String currencyId, double amount);
boolean result = api.setBalance(Player player, String currencyId, double amount, OperationContext context);
boolean result = api.setBalance(Player player, ExcellentCurrency currency, double amount);
boolean result = api.setBalance(Player player, ExcellentCurrency currency, double amount, OperationContext context);

Currency Management

// Check if currency exists
boolean hasCurrency = api.hasCurrency(String id);

// Get all registered currencies
Set<ExcellentCurrency> currencies = api.getCurrencies();

// Get currency by ID
ExcellentCurrency currency = api.getCurrency(String id);
Optional<ExcellentCurrency> optionalCurrency = api.currencyById(String id);

// Register custom currency (with commands).
api.currencyManager().injectCurrency(myCurrency);

// Register custom currency (without commands).
api.currencyManager().registerCurrency(myCurrency);

User Data Management

// Get Cached User Data
CoinsUser = api.getCachedUserData(Player player);
Optional<CoinsUser> optionalUser = api.getCachedUserData(String name);
Optional<CoinsUser> optionalUser = api.getCachedUserData(UUID uuid);

// Fetch From Database (or instant cached result)
CompletableFuture<Optional<CoinsUser>> future = api.loadUserDataByName(String name);
CompletableFuture<Optional<CoinsUser>> future = api.loadUserDataById(UUID uuid);

// Manage balance
user.setBalance(currency, amount);
user.addBalance(currency, amount);.
user.removeBalance(currency, amount);

// Mark user for save
user.markDirty();