Changelog
- I fixed the problem with negative money from pay/add.
- I fixed a problem of reconnecting to databases.
- I modified the balance command and now you can configure it just like normal commands in config.json
- I made some changes to the API.
New functions for API:
/**
* Sets the player's balance to a specific amount.
*
* This method should be used instead of directly calling `BEconfig.setBalance(...)`,
* as it also triggers the `onBalanceChanged` event and notifies all registered listeners.
*
* @param playerId The UUID of the player whose balance is being updated.
* @param currencyType The currency type to modify.
* @param newBalance The exact value to set as the new balance.
*/
fun updateBalance(playerId: UUID, currencyType: String, newBalance: BigDecimal)
/**
* Adds a specified amount to the player's balance.
*
* This method updates the balance, triggers the `onBalanceChanged` event,
* and logs the transaction as a credit. Always use this instead of modifying the balance manually.
*
* @param playerId The UUID of the player.
* @param currencyType The currency to increase.
* @param amount The amount to add to the current balance.
*/
fun increaseBalance(playerId: UUID, currencyType: String, amount: BigDecimal)
/**
* Subtracts a specified amount from the player's balance.
*
* This method checks for sufficient funds before subtracting, triggers the `onBalanceChanged` event,
* and logs the transaction as a debit. Returns false if the player has insufficient funds.
*
* @param playerId The UUID of the player.
* @param currencyType The currency to subtract from.
* @param amount The amount to subtract.
* @return True if the subtraction was successful, false otherwise.
*/
fun decreaseBalance(playerId: UUID, currencyType: String, amount: BigDecimal): Boolean
/**
* Forces a balance sync to the player using packets.
*
* This is useful when an external system (like a scoreboard or UI) needs
* to refresh the display without changing the balance.
*
* @param playerId The UUID of the player.
* @param currencyType The currency type to sync.
*/
fun syncBalanceToPlayer(playerId: UUID, currencyType: String)
/**
* Applies a modification to the player's balance using a safe lambda.
* Automatically handles balance update and events.
*
* Example usage:
* modifyBalanceSafely(uuid, "pokedollars") { it.multiply(BigDecimal("1.05")) }
*
* @param playerId The UUID of the player.
* @param currencyType The currency type.
* @param modifier A function that receives the current balance and returns the new one.
*/
fun modifyBalanceSafely(playerId: UUID, currencyType: String, modifier: (BigDecimal) -> BigDecimal)
/**
* Resets a player's balance to the default value defined in config for the currency.
* Triggers the `onBalanceChanged` event.
*
* @param playerId The UUID of the player.
* @param currencyType The currency type to reset.
*/
fun resetBalanceToDefault(playerId: UUID, currencyType: String)
/**
* Retrieves a map of all balances for a specific player across all currencies.
*
* @param playerId The UUID of the player.
* @return Map of currency type to balance.
*/
fun getAllPlayerBalances(playerId: UUID): Map<String, BigDecimal>
/**
* Retrieves the top players based on their balance for a specific currency.
* This works across all storage types (local file or database).
*
* @param currencyType The type of currency to rank by.
* @param limit The maximum number of top players to return.
* @return A list of PlayerBalance objects sorted by balance in descending order.
*/
fun getTopBalances(currencyType: String, limit: Int): List<PlayerBalance>
Dependencies
Files
beconomy-1.5.jar(223.9 KiB) Primary Download
Details
Licensed GPL-3.0-only
Published a year ago
Updated 3 months ago