2011-12-30 18:03:21 +01:00
|
|
|
package net.milkbowl.vault.economy.plugins;
|
|
|
|
|
|
|
|
import is.currency.Currency;
|
|
|
|
import is.currency.syst.AccountContext;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
import net.milkbowl.vault.economy.EconomyResponse;
|
|
|
|
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
|
|
|
|
|
2012-01-26 01:06:29 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.server.PluginDisableEvent;
|
|
|
|
import org.bukkit.event.server.PluginEnableEvent;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2011-12-30 18:03:21 +01:00
|
|
|
public class Economy_CurrencyCore implements Economy {
|
|
|
|
|
|
|
|
private Currency currency;
|
|
|
|
private static final Logger log = Logger.getLogger("Minecraft");
|
|
|
|
private final Plugin plugin;
|
|
|
|
private final String name = "CurrencyCore";
|
|
|
|
|
|
|
|
public Economy_CurrencyCore(Plugin plugin) {
|
|
|
|
this.plugin = plugin;
|
2012-01-26 01:06:29 +01:00
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2011-12-30 18:03:21 +01:00
|
|
|
// Load Plugin in case it was loaded before
|
|
|
|
if(currency == null) {
|
|
|
|
Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
|
|
|
|
if(currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) {
|
|
|
|
this.currency = (Currency) currencyPlugin;
|
|
|
|
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 01:06:29 +01:00
|
|
|
public class EconomyServerListener implements Listener {
|
2011-12-30 18:03:21 +01:00
|
|
|
|
|
|
|
private Economy_CurrencyCore economy = null;
|
|
|
|
|
|
|
|
public EconomyServerListener(Economy_CurrencyCore economy) {
|
|
|
|
this.economy = economy;
|
|
|
|
}
|
|
|
|
|
2012-01-26 01:06:29 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-12-30 18:03:21 +01:00
|
|
|
public void onPluginEnable(PluginEnableEvent event) {
|
|
|
|
if(this.economy.currency == null) {
|
|
|
|
Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore");
|
|
|
|
if(currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) {
|
|
|
|
this.economy.currency = (Currency) currencyPlugin;
|
|
|
|
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), this.economy.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 01:06:29 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-12-30 18:03:21 +01:00
|
|
|
public void onPluginDisable(PluginDisableEvent event) {
|
|
|
|
if (this.economy.currency != null) {
|
|
|
|
if (event.getPlugin().getDescription().getName().equals("CurrencyCore")) {
|
|
|
|
this.economy.currency = null;
|
|
|
|
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), this.economy.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return currency != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String format(double amount) {
|
|
|
|
return this.currency.getFormatHelper().format(amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getBalance(String playerName) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
|
|
|
|
if (account == null)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
return account.getBalance();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean has(String playerName, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
|
|
|
|
if (account == null)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return account.hasBalance(amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
|
|
|
|
} else if (!account.hasBalance(amount)) {
|
|
|
|
return new EconomyResponse(0.0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds");
|
2012-01-01 01:02:21 +01:00
|
|
|
} else {
|
|
|
|
account.subtractBalance(amount);
|
|
|
|
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
|
2011-12-30 18:03:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse depositPlayer(String playerName, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
|
|
|
|
}
|
|
|
|
account.addBalance(amount);
|
|
|
|
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse createBank(String name, String player) {
|
|
|
|
if (this.currency.getAccountManager().hasAccount(name)) {
|
|
|
|
return new EconomyResponse(0, currency.getAccountManager().getAccount(name).getBalance(), ResponseType.FAILURE, "That account already exists.");
|
|
|
|
}
|
|
|
|
this.currency.getAccountManager().createAccount(name);
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
|
2012-01-28 20:15:41 +01:00
|
|
|
@Override
|
|
|
|
public EconomyResponse deleteBank(String name) {
|
|
|
|
if (this.currency.getAccountManager().hasAccount(name)) {
|
|
|
|
this.currency.getAccountManager().removeAccount(name);
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
|
|
|
|
}
|
|
|
|
|
2011-12-30 18:03:21 +01:00
|
|
|
@Override
|
|
|
|
public EconomyResponse bankBalance(String name) {
|
2012-01-01 01:02:21 +01:00
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(name);
|
|
|
|
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exists.");
|
2011-12-30 18:03:21 +01:00
|
|
|
}
|
2012-01-01 01:02:21 +01:00
|
|
|
return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, "");
|
2011-12-30 18:03:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankHas(String name, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(name);
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
|
|
|
|
} else if (!account.hasBalance(amount)) {
|
|
|
|
return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!");
|
|
|
|
} else {
|
|
|
|
return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankWithdraw(String name, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(name);
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
|
|
|
|
} else if (!account.hasBalance(amount)) {
|
|
|
|
return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!");
|
|
|
|
} else {
|
|
|
|
account.subtractBalance(amount);
|
|
|
|
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankDeposit(String name, double amount) {
|
|
|
|
AccountContext account = this.currency.getAccountManager().getAccount(name);
|
|
|
|
if (account == null) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
|
|
|
|
} else {
|
|
|
|
account.addBalance(amount);
|
|
|
|
return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse isBankOwner(String name, String playerName) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse isBankMember(String name, String playerName) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getBanks() {
|
|
|
|
return Arrays.asList(this.currency.getAccountManager().getAccounts());
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2012-01-02 19:19:29 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasBankSupport() {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-02 19:50:16 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasAccount(String playerName) {
|
|
|
|
return this.currency.getAccountManager().getAccount(playerName) != null;
|
|
|
|
}
|
2012-01-15 20:55:14 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean createPlayerAccount(String playerName) {
|
|
|
|
if (this.currency.getAccountManager().getAccount(playerName) != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.currency.getAccountManager().createAccount(playerName);
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-30 18:03:21 +01:00
|
|
|
}
|