Skip to content

Economy Bridge

The economy bridge provides a unified economy operation interface for EmakiCoreLib, abstracting away API differences between different economy plugins.

Supported Economy Providers

ProviderPluginMulti-currency SupportDescription
vaultVaultNoThe most widely used economy API, single currency
excellenteconomyExcellentEconomyYesEconomy plugin with multi-currency support (formerly CoinsEngine)

Provider Selection Logic

The economy service selects the default provider at startup using the following logic:

1. Check if economy.provider is explicitly specified in config.yml
   ├─ Yes → Use the specified provider
   └─ No  → Enter auto-detection
2. Auto-detection (auto mode)
   ├─ Detect ExcellentEconomy → Installed → Use ExcellentEconomy
   └─ Detect Vault            → Installed → Use Vault
3. Neither installed → Economy service unavailable, related actions will return errors

Configuration Example

yaml
# config.yml
economy:
  # Provider selection: auto / vault / excellenteconomy
  provider: auto

  # ExcellentEconomy default currency (only effective for ExcellentEconomy)
  excellenteconomy:
    default_currency: "coins"

Tip

In most cases, auto is sufficient. You only need to explicitly configure provider when the server has multiple economy plugins installed and you need to specify which one to prioritize.

Usage in Actions

Economy-related actions support optional provider and currency parameters:

givemoney — Give Money

yaml
actions:
  # Use default provider and currency
  - "givemoney amount=100"

  # Specify provider
  - "givemoney amount=100 provider=vault"

  # Specify a specific ExcellentEconomy currency
  - "givemoney amount=50 provider=excellenteconomy currency=gems"

takemoney — Deduct Money

yaml
actions:
  # Deduct 50 coins (default provider)
  - "takemoney amount=50"

  # Action fails if balance is insufficient, subsequent actions won't execute
  # Use @ignore_failure to skip the failure
  - "@ignore_failure takemoney amount=9999"
  - "sendmessage message=<yellow>扣款尝试完成"

Warning

takemoney returns an ECONOMY_INSUFFICIENT error and interrupts the action chain when the balance is insufficient. If you want subsequent actions to continue when the balance is insufficient, add the @ignore_failure prefix.

setmoney — Set Balance

yaml
actions:
  # Set balance to 1000
  - "setmoney amount=1000"

  # Specify provider and currency
  - "setmoney amount=500 provider=excellenteconomy currency=points"

Parameter Reference

ParameterRequiredDescription
amountYesAmount (supports decimals)
providerNoEconomy provider (vault / excellenteconomy), defaults to the configured provider
currencyNoCurrency type (ExcellentEconomy only), defaults to the configured default_currency

Custom Provider Registration

Other plugins can register custom economy providers:

java
EconomyService economyService = EmakiServiceRegistry.get(EconomyService.class);

economyService.registerProvider("my_economy", new EconomyProvider() {
    @Override
    public double getBalance(Player player, String currency) {
        return MyEconomyAPI.getBalance(player);
    }

    @Override
    public boolean deposit(Player player, double amount, String currency) {
        return MyEconomyAPI.deposit(player, amount);
    }

    @Override
    public boolean withdraw(Player player, double amount, String currency) {
        if (MyEconomyAPI.getBalance(player) < amount) {
            return false;
        }
        return MyEconomyAPI.withdraw(player, amount);
    }

    @Override
    public boolean setBalance(Player player, double amount, String currency) {
        return MyEconomyAPI.setBalance(player, amount);
    }

    @Override
    public String getDefaultCurrency() {
        return "default";
    }
});

Once registered, it can be used in actions via provider=my_economy:

yaml
actions:
  - "givemoney amount=100 provider=my_economy"

Tip

Custom providers should be registered during the plugin's onEnable phase to ensure registration is complete before other modules use economy actions. The withdraw method should return false when the balance is insufficient, and the system will automatically convert it to an ECONOMY_INSUFFICIENT error.

Released under the GPL-3.0 License