Skip to content

ElasticEconomy

Luis Benavides-Naranjo edited this page Mar 20, 2025 · 1 revision

ElasticEconomy Documentation

ElasticEconomy is a flexible economy system that supports both single-currency and multi-currency implementations through Vault's Economy system.

Getting Started

To access ElasticEconomy, use the BlobLibEconomyAPI:

ElasticEconomy economy = BlobLibEconomyAPI.getInstance().getElasticEconomy();

Economy Types

ElasticEconomy can operate in three modes:

  1. Single Economy (isSingleEconomy()) - Traditional single-currency economy
  2. Multi Economy (isMultiEconomy()) - Multiple currency support
  3. Absent (isAbsent()) - No economy provider available

Usage Examples

Check Economy Type

ElasticEconomy economy = BlobLibEconomyAPI.getInstance().getElasticEconomy();

if (economy.isMultiEconomy()) {
    // Handle multi-currency operations
} else if (economy.isSingleEconomy()) {
    // Handle single-currency operations
} else {
    // Handle no economy provider case
}

Working with Currencies

// Get default currency
IdentityEconomy defaultCurrency = economy.getDefault();

// Get specific currency implementation
IdentityEconomy customCurrency = economy.getImplementation("gems");

// Check if currency exists
boolean hasCurrency = economy.existsImplementation("coins");

// Get all available currencies
Collection<IdentityEconomy> allCurrencies = economy.getAllImplementations();

Working with Optional Implementations

// Map an optional currency name to its implementation, falling back to default
Optional<String> currencyName = Optional.of("gems");
IdentityEconomy currency = economy.map(currencyName);

Best Practices

  1. Always check if the economy is absent before operations:
if (economy.isAbsent()) {
    // Handle no economy provider case
    return;
}
  1. Use the appropriate methods based on economy type:
if (economy.isMultiEconomy()) {
    // Use specific implementations
    economy.getImplementation("custom_currency");
} else {
    // Use default implementation
    economy.getDefault();
}
  1. Use the mapping function for optional currency names:
economy.map(Optional.ofNullable(currencyName));

Clone this wiki locally