-
Notifications
You must be signed in to change notification settings - Fork 6
dev java getting started
Config Plugins edited this page Sep 3, 2026
·
3 revisions
Quick guide to integrate Vault 2.0 into your plugin using the modern SimpleEconomy interface.
name: MyPlugin
main: com.yourplugin.MyPlugin
version: 1.0.0
depend:
- Vaultpackage com.yourplugin;
import net.milkbowl.vault.VaultPlugin;
import net.milkbowl.vault.economy.SimpleEconomy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin {
private static SimpleEconomy economy;
@Override
public void onEnable() {
if (!setupEconomy()) {
getLogger().severe("Vault not found!");
getServer().getPluginManager().disablePlugin(this);
return;
}
getLogger().info("✓ Vault 2.1.0 loaded");
}
private boolean setupEconomy() {
RegisteredServiceProvider<SimpleEconomy> rsp =
getServer().getServicesManager().getRegistration(SimpleEconomy.class);
if (rsp == null) return false;
economy = rsp.getProvider();
return economy != null;
}
public static SimpleEconomy getEconomy() {
return economy;
}
}| Method | Return | Description |
|---|---|---|
getBalance(OfflinePlayer) |
double |
Player balance in default currency |
getBalance(OfflinePlayer, String) |
double |
Balance in a specific currency |
depositPlayer(OfflinePlayer, double) |
EconomyResponse |
Deposit money |
withdrawPlayer(OfflinePlayer, double) |
EconomyResponse |
Withdraw money |
has(OfflinePlayer, double) |
boolean |
Does the player have X money? |
format(double) |
String |
Formats amount with symbol |
getDefaultCurrencyId() |
String |
Default currency ID |
currencyNamePlural() |
String |
Plural currency name |
currencyNameSingular() |
String |
Singular currency name |
import org.bukkit.entity.Player;
public class BalanceExample {
public void showBalance(Player p) {
SimpleEconomy eco = MyPlugin.getEconomy();
double balance = eco.getBalance(p);
// Also by currency
double gemBalance = eco.getBalance(p, "gems");
p.sendMessage("Your balance: " + eco.format(balance));
}
}import net.milkbowl.vault.economy.EconomyResponse;
public void reward(Player p, double amount) {
SimpleEconomy eco = MyPlugin.getEconomy();
EconomyResponse response = eco.depositPlayer(p, amount);
if (response.transactionSuccess()) {
p.sendMessage("&a+ " + eco.format(response.amount));
} else {
p.sendMessage("&cError: " + response.errorMessage);
}
}public void charge(Player p, double price) {
SimpleEconomy eco = MyPlugin.getEconomy();
if (!eco.has(p, price)) {
p.sendMessage("&cYou don't have enough money");
return;
}
EconomyResponse response = eco.withdrawPlayer(p, price);
if (response.transactionSuccess()) {
p.sendMessage("&aPaid: " + eco.format(response.amount));
p.sendMessage("&fRemaining balance: " + eco.format(response.balance));
}
}public String formatMoney(double value) {
SimpleEconomy eco = MyPlugin.getEconomy();
// Example output: $1,500.75
return eco.format(value);
}# balances.yml
currencies:
coins:
symbol: "$"
name-plural: "dollars"
name-singular: "dollar"
default: true # ← this is the one getDefaultCurrencyId() returns
gems:
symbol: "💎"
name-plural: "gems"public void defaultCurrencyInfo() {
SimpleEconomy eco = MyPlugin.getEconomy();
String id = eco.getDefaultCurrencyId(); // "coins"
String plural = eco.currencyNamePlural(); // "dollars"
String singular = eco.currencyNameSingular(); // "dollar"
getLogger().info("Active currency: " + id);
}public boolean transfer(Player from, Player to, double amount) {
SimpleEconomy eco = MyPlugin.getEconomy();
if (!eco.has(from, amount)) return false;
EconomyResponse withdrawal = eco.withdrawPlayer(from, amount);
if (!withdrawal.transactionSuccess()) return false;
EconomyResponse deposit = eco.depositPlayer(to, amount);
if (!deposit.transactionSuccess()) {
// Manual rollback
eco.depositPlayer(from, amount);
return false;
}
return true;
}All methods accept OfflinePlayer for disconnected players:
import org.bukkit.OfflinePlayer;
public void chargeOfflineUser(UUID uuid, double amount) {
SimpleEconomy eco = MyPlugin.getEconomy();
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
eco.withdrawPlayer(op, amount); // Supports offline players
}| Field | Type | Description |
|---|---|---|
amount |
double |
Amount that was moved |
balance |
double |
Player's final balance |
type |
ResponseType |
SUCCESS, FAILURE, NOT_IMPLEMENTED
|
errorMessage |
String |
Error message if it failed |
transactionSuccess() |
boolean |
Was the transaction OK? |
if (resp.type == EconomyResponse.ResponseType.SUCCESS) {
// OK
}
Vault Economy v2.1.0 · Compatible with Spigot 1.8.8 – 1.21.x
📦 Modrinth ·
💬 Discord ·
Java 17 (legacy) · Java 21 (modern)
Documentation generated on 2026-09-03 · Vault Project Team
- 🏠 Home
- 🚀 First Install
- 🧑🏫 Getting Started
- ❓ Basic FAQ
- 📋 Complete Command List
- 🛡️ Complete Permission List
- ⚙️ config.yml Reference
- 🌐 Supported Languages
- 🆕 Modrinth Updates
- 💰 Player-to-Player Payments
- 🏦 Bank System
- 💵 Physical Notes
- 💸 Loans
- 📜 Transaction History
- 📊 Top Players
- ⏸️ Offline Payments
- 💳 Charges / Payment Requests
- 🔔 Discord Webhook
- 🛠️ Installation Errors
- 🚫 Players Can't Pay
- 🧨 Balances Wiped on Restart
- 📉 Bank Doesn't Pay Interest
- 🧾 Invalid / Expired Notes
- 🩺 Complete Step-by-Step Troubleshooting
- Java API
- 📜 Skript
- 🧰 Contribute · Dual Maven Build