Skip to content

AllayMC/EconomyAPI

Repository files navigation

EconomyAPI

Maven Central Version

EconomyAPI is a plugin that unifies all economy plugins under one single API. The API can be used by both economy plugins providing the API, and other plugins using the API (i.e. shop plugins). This allows for all plugins that require an economy to work with any economy plugin.

Note

EconomyAPI cannot be used alone! It only provides abstract APIs for uniform calls and requires another economy plugin to implement it. You must use an economy plugin that provides the EconomyAPI implementation.

Usages

Use in Gradle

repositories {
    mavenCentral()
}

dependencies {
    compileOnly(group = "org.allaymc", name = "economy-api", version = "0.1.0")
}

Use the API

import org.allaymc.economyapi.EconomyAPI;
import org.allaymc.economyapi.Account;
import org.allaymc.economyapi.Currency;
import java.math.BigDecimal;
import java.util.UUID;

public class Example {
    public void example() {
        // Get the api instance
        EconomyAPI api = EconomyAPI.get();
        // Create an account
        UUID uuid = UUID.randomUUID();
        Account account = api.getOrCreateAccount(uuid);
        // Get the balance of the account for the default currency
        Currency currency = api.getDefaultCurrency();
        BigDecimal balance = account.getBalance(currency);
        // Convert it to a string
        String formattedBalance = currency.format(balance);
        // More...
    }
}

Implement the API

import org.allaymc.api.plugin.Plugin;
import org.allaymc.economyapi.EconomyAPI;

public class MyEconomyAPI extends Plugin implements EconomyAPI {
    @Override
    public void onLoad() {
        // Set the api instance, note that EconomyAPI#API can only be set once
        EconomyAPI.API.set(this);
    }
}

Available Events

  • AccountCreateEvent: Called when an account is created.
  • AccountDeleteEvent: Called when an account is deleted.
  • BalanceChangeEvent: Called when a change occurs in the balance of an account.
  • BalanceTransferEvent: Called when a balance transfer occurs between two accounts.

Requirement

Java: 21+

Allay: 0.17.0+

Contributing

Contributions are welcome! Feel free to fork the repository, improve the code, and submit pull requests with your changes.

License

This project is licensed under the LGPL v3 License - see the LICENSE file for details.

About

EconomyAPI is a plugin that unifies all economy plugins under one single API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages