API Functionality
API Functionality
This section provides detailed documentation for each function available in the BlanketEconomy API. These functions are designed to help developers manage in-game currencies effectively, both virtual and item-based.
1. getBalance
getBalance
Signature: getBalance(playerId: UUID, currencyType: String): BigDecimal
Description: Retrieves the balance of a specific player for a given currency type.
Parameters:
playerId
(UUID): The UUID of the player.currencyType
(String): The type of currency.
Returns:
BigDecimal
- The balance of the player in the specified currency.Example:
2. setBalance
setBalance
Signature: setBalance(playerId: UUID, balance: BigDecimal, currencyType: String)
Description: Sets the balance of a specific player for a given currency type.
Parameters:
playerId
(UUID): The UUID of the player.balance
(BigDecimal): The new balance to set.currencyType
(String): The type of currency.
Example:
3. addBalance
addBalance
Signature: addBalance(playerId: UUID, amount: BigDecimal, currencyType: String)
Description: Adds a specific amount to the balance of a player for a given currency type.
Parameters:
playerId
(UUID): The UUID of the player.amount
(BigDecimal): The amount to add.currencyType
(String): The type of currency.
Example:
4. subtractBalance
subtractBalance
Signature: subtractBalance(playerId: UUID, amount: BigDecimal, currencyType: String): Boolean
Description: Subtracts a specific amount from the balance of a player for a given currency type. Returns
true
if successful,false
otherwise.Parameters:
playerId
(UUID): The UUID of the player.amount
(BigDecimal): The amount to subtract.currencyType
(String): The type of currency.
Returns:
Boolean
-true
if the balance was successfully subtracted;false
otherwise.Example:
5. transfer
transfer
Signature: transfer(fromPlayerId: UUID, toPlayerId: UUID, amount: BigDecimal, currencyType: String): Boolean
Description: Transfers a specific amount of currency from one player to another. Returns
true
if successful,false
if the sender has insufficient funds.Parameters:
fromPlayerId
(UUID): The UUID of the player sending the currency.toPlayerId
(UUID): The UUID of the player receiving the currency.amount
(BigDecimal): The amount to transfer.currencyType
(String): The type of currency.
Returns:
Boolean
-true
if the transfer was successful;false
otherwise.Example:
6. addEventListener
addEventListener
Signature: addEventListener(listener: EconomyEventListener)
Description: Adds an event listener to the economy system. The listener will be notified of specific events, such as when a player's balance changes.
Parameters:
listener
(EconomyEventListener): The listener to handle events.
Example:
7. removeEventListener
removeEventListener
Signature: removeEventListener(listener: EconomyEventListener)
Description: Removes a previously added event listener from the economy system.
Parameters:
listener
(EconomyEventListener): The listener to remove.
Example:
8. conditionalTransaction
conditionalTransaction
Signature: conditionalTransaction(playerId: UUID, amount: BigDecimal, currencyType: String, condition: (BigDecimal) -> Boolean): Boolean
Description: Performs a transaction that subtracts an amount from a player's balance only if a condition is met.
Parameters:
playerId
(UUID): The UUID of the player.amount
(BigDecimal): The amount to subtract.currencyType
(String): The type of currency.condition
((BigDecimal) -> Boolean): The condition for the transaction.
Returns:
Boolean
-true
if the condition was met and the transaction succeeded.Example:
9. logTransaction
logTransaction
Signature: logTransaction(playerId: UUID, currencyType: String, amount: BigDecimal, type: String)
Description: Logs a transaction for a player.
Parameters:
playerId
(UUID): The UUID of the player.currencyType
(String): The type of currency.amount
(BigDecimal): The amount of the transaction.type
(String): The type of transaction (e.g., "credit", "debit").
Example:
10. getTransactionHistory
getTransactionHistory
Signature: getTransactionHistory(playerId: UUID): List<Transaction>
Description: Retrieves the transaction history for a specific player.
Parameters:
playerId
(UUID): The UUID of the player.
Returns:
List<Transaction>
- A list of transaction details.Example:
Additional API Functions
Last updated