Skip to main content

API: Economy Operations

Methods for economy operations and currency handling.

Economy Status

isEconomyEnabled

Check if economy is enabled.

Signature:

boolean isEconomyEnabled()

Returns: true if economy is enabled, false otherwise

Example:

if (!ordersAPI.isEconomyEnabled()) {
player.sendMessage("Economy is not available!");
return;
}

Balance Operations

getBalance

Get player balance.

Signature:

double getBalance(UUID playerUuid)

Parameters:

  • playerUuid - UUID of the player

Returns: Player balance, or 0.0 if economy is disabled

Example:

double balance = ordersAPI.getBalance(player.getUniqueId());
player.sendMessage("Your balance: " + ordersAPI.formatCurrency(balance));

hasBalance

Check if player has sufficient balance.

Signature:

boolean hasBalance(UUID playerUuid, double amount)

Parameters:

  • playerUuid - UUID of the player
  • amount - Amount to check

Returns: true if player has sufficient balance

Example:

double orderPrice = 1000.0;

if (ordersAPI.hasBalance(player.getUniqueId(), orderPrice)) {
// Player has enough money
createOrder();
} else {
player.sendMessage("Insufficient funds!");
}

Transaction Operations

withdrawPlayer

Withdraw money from player.

Signature:

boolean withdrawPlayer(UUID playerUuid, double amount)

Parameters:

  • playerUuid - UUID of the player
  • amount - Amount to withdraw

Returns: true if withdrawal successful

Example:

double orderPrice = 1000.0;

if (ordersAPI.withdrawPlayer(player.getUniqueId(), orderPrice)) {
player.sendMessage("Payment successful!");
} else {
player.sendMessage("Payment failed!");
}

depositPlayer

Deposit money to player.

Signature:

boolean depositPlayer(UUID playerUuid, double amount)

Parameters:

  • playerUuid - UUID of the player
  • amount - Amount to deposit

Returns: true if deposit successful

Example:

double payment = 500.0;

if (ordersAPI.depositPlayer(player.getUniqueId(), payment)) {
player.sendMessage("Payment received: " +
ordersAPI.formatCurrency(payment));
}

Currency Formatting

formatCurrency

Format currency amount.

Signature:

String formatCurrency(double amount)

Parameters:

  • amount - Amount to format

Returns: Formatted currency string

Example:

double amount = 1234.56;
String formatted = ordersAPI.formatCurrency(amount);
// Result: "$1,234.56" (format depends on economy plugin)

getCurrencyName

Get currency name (plural).

Signature:

String getCurrencyName()

Returns: Currency name plural, or empty string if economy disabled

Example:

String currency = ordersAPI.getCurrencyName();
// Result: "dollars" (depends on economy plugin)

getCurrencyNameSingular

Get currency name (singular).

Signature:

String getCurrencyNameSingular()

Returns: Currency name singular, or empty string if economy disabled

Example:

String currency = ordersAPI.getCurrencyNameSingular();
// Result: "dollar" (depends on economy plugin)

Complete Example

// Check economy
if (!ordersAPI.isEconomyEnabled()) {
player.sendMessage("Economy not available!");
return;
}

// Check balance
double orderPrice = 1000.0;
UUID playerUuid = player.getUniqueId();

if (!ordersAPI.hasBalance(playerUuid, orderPrice)) {
double balance = ordersAPI.getBalance(playerUuid);
player.sendMessage("Insufficient funds! You have " +
ordersAPI.formatCurrency(balance) +
", need " + ordersAPI.formatCurrency(orderPrice));
return;
}

// Withdraw payment
if (ordersAPI.withdrawPlayer(playerUuid, orderPrice)) {
player.sendMessage("Paid " + ordersAPI.formatCurrency(orderPrice));

// Create order...
} else {
player.sendMessage("Payment failed!");
}

Best Practices

  1. Check Economy First: Always verify economy is enabled
  2. Check Balance: Verify balance before transactions
  3. Handle Failures: Check return values for success/failure
  4. Format Currency: Use formatCurrency for user-facing amounts
  5. Error Handling: Handle transaction failures gracefully