Developer API
Public API for integrating mineWallet with external plugins.
Overview
mineWallet provides a public API module (wallet-api) that allows external plugins to interact with the wallet system. The API is compiled against Java 11 for maximum compatibility.
Maven Dependency
<dependency>
<groupId>cc.minecodes</groupId>
<artifactId>wallet-api</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
Core Interfaces
WalletPlugin
The main entry point for accessing wallet services:
WalletPlugin walletPlugin = (WalletPlugin) Bukkit.getPluginManager().getPlugin("mineWallet");
WalletServiceApi<WalletApi> walletService = walletPlugin.getWalletService();
WalletControllerApi<WalletApi> walletController = walletPlugin.getWalletController();
WalletApi
Represents a playerβs wallet:
interface WalletApi {
UUID getOwnerUniqueId();
double getBalance();
void setBalance(double balance);
Instant getLastUpdate();
void setLastUpdate(Instant lastUpdate);
}
WalletServiceApi
Handles wallet persistence:
interface WalletServiceApi<T extends WalletApi> {
Optional<T> findByUniqueId(UUID owner);
void save(T wallet);
}
WalletControllerApi
Handles wallet operations with validation:
interface WalletControllerApi<T extends WalletApi> {
WalletOperationState depositBalance(T wallet, double amount);
WalletOperationState withdrawBalance(T wallet, double amount);
WalletOperationState setupBalance(T wallet, double amount);
boolean hasBalance(T wallet, double amount);
}
Operation States
Every wallet operation returns a WalletOperationState:
| State | Description |
|---|---|
SUCCESS_DEPOSIT | Deposit completed successfully |
SUCCESS_WITHDRAW | Withdrawal completed successfully |
SUCCESS_SETUP | Balance set successfully |
NOT_ENOUGH_MONEY | Insufficient balance for withdrawal |
NEGATIVE_AMOUNT | Provided amount is negative |
NEGATIVE_BALANCE | Wallet balance is negative |
UNKNOWN_ERROR | Unexpected error occurred |
Examples
Check Player Balance
WalletPlugin walletPlugin = (WalletPlugin) Bukkit.getPluginManager().getPlugin("mineWallet");
WalletServiceApi<WalletApi> service = walletPlugin.getWalletService();
Optional<WalletApi> wallet = service.findByUniqueId(player.getUniqueId());
if (wallet.isPresent()) {
double balance = wallet.get().getBalance();
}
Deposit Money
WalletPlugin walletPlugin = (WalletPlugin) Bukkit.getPluginManager().getPlugin("mineWallet");
WalletServiceApi<WalletApi> service = walletPlugin.getWalletService();
WalletControllerApi<WalletApi> controller = walletPlugin.getWalletController();
Optional<WalletApi> wallet = service.findByUniqueId(player.getUniqueId());
if (wallet.isPresent()) {
WalletOperationState result = controller.depositBalance(wallet.get(), 100.0);
if (result == WalletOperationState.SUCCESS_DEPOSIT) {
service.save(wallet.get());
}
}
Check If Player Can Afford
WalletPlugin walletPlugin = (WalletPlugin) Bukkit.getPluginManager().getPlugin("mineWallet");
WalletServiceApi<WalletApi> service = walletPlugin.getWalletService();
WalletControllerApi<WalletApi> controller = walletPlugin.getWalletController();
Optional<WalletApi> wallet = service.findByUniqueId(player.getUniqueId());
if (wallet.isPresent()) {
boolean canAfford = controller.hasBalance(wallet.get(), 50.0);
}
Withdraw Money
Optional<WalletApi> wallet = service.findByUniqueId(player.getUniqueId());
if (wallet.isPresent()) {
WalletOperationState result = controller.withdrawBalance(wallet.get(), 25.0);
switch (result) {
case SUCCESS_WITHDRAW:
service.save(wallet.get());
break;
case NOT_ENOUGH_MONEY:
break;
case NEGATIVE_AMOUNT:
break;
}
}
plugin.yml
Add mineWallet as a dependency in your plugin:
depend: [mineWallet]
Or as a soft dependency if wallet integration is optional:
softdepend: [mineWallet]