The IslandBank interface provides methods for managing an island’s bank account, including deposits, withdrawals, and transaction history.
Getting the Island Bank
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.island.bank.IslandBank;
public IslandBank getBank(Island island) {
return island.getIslandBank();
}
Balance Management
getBalance()
Get the current balance in the bank.
IslandBank bank = island.getIslandBank();
BigDecimal balance = bank.getBalance();
setBalance(BigDecimal balance)
Set the balance in the bank. This does not create transaction records and is primarily used for loading data from the database.
bank.setBalance(new BigDecimal("10000"));
Deposits
depositMoney(SuperiorPlayer superiorPlayer, BigDecimal amount)
Deposit money into the bank from a player’s account.
The player depositing the money
import com.bgsoftware.superiorskyblock.api.island.bank.BankTransaction;
import java.math.BigDecimal;
BankTransaction transaction = bank.depositMoney(
superiorPlayer,
new BigDecimal("1000")
);
depositAdminMoney(CommandSender commandSender, BigDecimal amount)
Deposit money into the bank without taking it from any player’s account. This is an admin command that creates money.
The command sender performing the deposit (typically console or admin)
BankTransaction adminDeposit = bank.depositAdminMoney(
Bukkit.getConsoleSender(),
new BigDecimal("5000")
);
canDepositMoney(BigDecimal amount)
Check if it’s possible to deposit money without exceeding the bank limit.
True if the deposit is allowed
BigDecimal depositAmount = new BigDecimal("10000");
if (bank.canDepositMoney(depositAmount)) {
bank.depositMoney(superiorPlayer, depositAmount);
} else {
// Bank limit would be exceeded
}
Withdrawals
withdrawMoney(SuperiorPlayer superiorPlayer, BigDecimal amount, List<String> commandsToExecute)
Withdraw money from the bank and give it to a player.
The player withdrawing the money
Optional commands to execute instead of using the default economy provider. Use for player name and for amount
// Standard withdrawal using economy provider
BankTransaction withdrawal = bank.withdrawMoney(
superiorPlayer,
new BigDecimal("500"),
null
);
// Withdrawal with custom commands
List<String> commands = Arrays.asList(
"give {0} diamond {1}"
);
BankTransaction customWithdrawal = bank.withdrawMoney(
superiorPlayer,
new BigDecimal("100"),
commands
);
withdrawAdminMoney(CommandSender commandSender, BigDecimal amount)
Withdraw money from the bank without giving it to any player. This is an admin command that removes money.
The command sender performing the withdrawal (typically console or admin)
BankTransaction adminWithdrawal = bank.withdrawAdminMoney(
Bukkit.getConsoleSender(),
new BigDecimal("2000")
);
Transaction History
getAllTransactions()
Get all transactions of the bank, sorted by creation time.
List of all bank transactions
List<BankTransaction> allTransactions = bank.getAllTransactions();
for (BankTransaction transaction : allTransactions) {
// Process transaction
}
getTransactions(SuperiorPlayer superiorPlayer)
Get all transactions made by a specific player.
The player whose transactions to retrieve
List of transactions by the player
List<BankTransaction> playerTransactions = bank.getTransactions(superiorPlayer);
getConsoleTransactions()
Get all transactions made by CONSOLE (admin commands).
List of console transactions
List<BankTransaction> consoleTransactions = bank.getConsoleTransactions();
loadTransaction(BankTransaction bankTransaction)
Load a transaction log. This is used internally to load transactions from the database.
The transaction object to load
Bank Limits
Bank limits are managed at the Island level:
// Get bank limit
BigDecimal limit = island.getBankLimit();
// Set bank limit (-1 for unlimited)
island.setBankLimit(new BigDecimal("100000"));
// Get raw bank limit (set via command)
BigDecimal rawLimit = island.getBankLimitRaw();
Bank Interest
The island also manages bank interest:
// Give bank interest
boolean interestGiven = island.giveInterest(true);
// Get last interest time
long lastInterest = island.getLastInterestTime();
// Set last interest time
island.setLastInterestTime(System.currentTimeMillis());
// Get next interest time in seconds
long nextInterest = island.getNextInterest();
Example: Complete Bank Transaction
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.island.bank.IslandBank;
import com.bgsoftware.superiorskyblock.api.island.bank.BankTransaction;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import java.math.BigDecimal;
public void handleBankDeposit(Island island, SuperiorPlayer player, double amount) {
IslandBank bank = island.getIslandBank();
BigDecimal depositAmount = BigDecimal.valueOf(amount);
// Check if deposit is allowed
if (!bank.canDepositMoney(depositAmount)) {
player.asPlayer().sendMessage("Bank limit would be exceeded!");
return;
}
// Perform deposit
BankTransaction transaction = bank.depositMoney(player, depositAmount);
// Notify player
player.asPlayer().sendMessage(
"Deposited $" + amount + ". New balance: $" + bank.getBalance()
);
}