-
Notifications
You must be signed in to change notification settings - Fork 1
ElasticEconomy
Luis Benavides-Naranjo edited this page Mar 20, 2025
·
1 revision
ElasticEconomy is a flexible economy system that supports both single-currency and multi-currency implementations through Vault's Economy system.
To access ElasticEconomy, use the BlobLibEconomyAPI:
ElasticEconomy economy = BlobLibEconomyAPI.getInstance().getElasticEconomy();ElasticEconomy can operate in three modes:
-
Single Economy (
isSingleEconomy()) - Traditional single-currency economy -
Multi Economy (
isMultiEconomy()) - Multiple currency support -
Absent (
isAbsent()) - No economy provider available
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
}// 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();// Map an optional currency name to its implementation, falling back to default
Optional<String> currencyName = Optional.of("gems");
IdentityEconomy currency = economy.map(currencyName);- Always check if the economy is absent before operations:
if (economy.isAbsent()) {
// Handle no economy provider case
return;
}- Use the appropriate methods based on economy type:
if (economy.isMultiEconomy()) {
// Use specific implementations
economy.getImplementation("custom_currency");
} else {
// Use default implementation
economy.getDefault();
}- Use the mapping function for optional currency names:
economy.map(Optional.ofNullable(currencyName));