This commit is contained in:
mung3r 2011-10-31 10:22:34 -07:00
commit 371a1c3d4f
9 changed files with 570 additions and 151 deletions

View File

@ -49,6 +49,13 @@ public interface Economy {
*/ */
public double getBalance(String playerName); public double getBalance(String playerName);
/**
* Checks if the player account has the amount
* @param playerName
* @param amount
* @return
*/
public boolean has(String playerName, double amount);
/** /**
* Withdraw an amount from a player * Withdraw an amount from a player
* @param playerName Name of player * @param playerName Name of player
@ -64,4 +71,52 @@ public interface Economy {
* @return Detailed response of transaction * @return Detailed response of transaction
*/ */
public EconomyResponse depositPlayer(String playerName, double amount); public EconomyResponse depositPlayer(String playerName, double amount);
/**
* Creates a bank account with the specified name and the player as the owner
* @param name
* @param player
* @return
*/
public EconomyResponse createBank(String name, String player);
/**
* Returns true or false whether the bank has the amount specified
* @param name
* @param amount
* @return
*/
public EconomyResponse bankHas(String name, double amount);
/**
* Withdraw an amount from a bank account
* @param name
* @param amount
* @return
*/
public EconomyResponse bankWithdraw(String name, double amount);
/**
* Deposit an amount into a bank account
* @param name
* @param amount
* @return
*/
public EconomyResponse bankDeposit(String name, double amount);
/**
* Check if a player is the owner of a bank account
* @param name
* @param playerName
* @return
*/
public EconomyResponse isBankOwner(String name, String playerName);
/**
* Check if the player is a member of the bank account
* @param name
* @param playerName
* @return
*/
public EconomyResponse isBankMember(String name, String playerName);
} }

View File

@ -24,6 +24,7 @@ import java.util.logging.Logger;
import me.ic3d.eco.ECO; import me.ic3d.eco.ECO;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -97,7 +98,7 @@ public class Economy_3co implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName)); balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
amount = Math.ceil(amount); amount = Math.ceil(amount);
@ -108,7 +109,7 @@ public class Economy_3co implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName)); balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
economy.setMoney(plugin.getServer().getPlayer(playerName), (int) (balance - amount)); economy.setMoney(plugin.getServer().getPlayer(playerName), (int) (balance - amount));
type = EconomyResponse.ResponseType.SUCCESS; type = EconomyResponse.ResponseType.SUCCESS;
@ -129,7 +130,7 @@ public class Economy_3co implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName)); balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
amount = Math.ceil(amount); amount = Math.ceil(amount);
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName)); balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
@ -185,4 +186,39 @@ public class Economy_3co implements Economy {
return String.format("%d %s", (int)amount, getMoneyNamePlural()); return String.format("%d %s", (int)amount, getMoneyNamePlural());
} }
} }
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "3co does not support bank accounts!");
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -35,170 +36,238 @@ import org.bukkit.plugin.PluginManager;
import cosine.boseconomy.BOSEconomy; import cosine.boseconomy.BOSEconomy;
public class Economy_BOSE6 implements Economy { public class Economy_BOSE6 implements Economy {
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
private String name = "BOSEconomy"; private String name = "BOSEconomy";
private Plugin plugin = null; private Plugin plugin = null;
private PluginManager pluginManager = null; private PluginManager pluginManager = null;
private BOSEconomy economy = null; private BOSEconomy economy = null;
private EconomyServerListener economyServerListener = null; private EconomyServerListener economyServerListener = null;
public Economy_BOSE6(Plugin plugin) { public Economy_BOSE6(Plugin plugin) {
this.plugin = plugin; this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager(); pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this); economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin); this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin); this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before // Load Plugin in case it was loaded before
if (economy == null) { if (economy == null) {
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy"); Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) { if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) {
economy = (BOSEconomy) bose; economy = (BOSEconomy) bose;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
} }
} }
} }
@Override @Override
public String getName() { public String getName() {
return name; return name;
} }
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
if (economy == null) { if (economy == null) {
return false; return false;
} else { } else {
return economy.isEnabled(); return economy.isEnabled();
} }
} }
@Override @Override
public double getBalance(String playerName) { public double getBalance(String playerName) {
final double balance; final double balance;
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
final double fBalance = balance; final double fBalance = balance;
return fBalance; return fBalance;
} }
@Override @Override
public EconomyResponse withdrawPlayer(String playerName, double amount) { public boolean has(String playerName, double amount) {
double balance; return getBalance(playerName) >= amount;
EconomyResponse.ResponseType type; }
String errorMessage = null;
if (amount < 0) { @Override
errorMessage = "Cannot withdraw negative funds"; public EconomyResponse withdrawPlayer(String playerName, double amount) {
type = EconomyResponse.ResponseType.FAILURE; double balance;
amount = 0; EconomyResponse.ResponseType type;
balance = (double) economy.getPlayerMoney(playerName); String errorMessage = null;
return new EconomyResponse(balance, balance, type, errorMessage); if (amount < 0) {
} errorMessage = "Cannot withdraw negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
amount = Math.ceil(amount); return new EconomyResponse(balance, balance, type, errorMessage);
balance = (double) economy.getPlayerMoney(playerName); }
if (balance - amount < 0) {
errorMessage = "Insufficient funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); amount = Math.ceil(amount);
} balance = (double) economy.getPlayerMoney(playerName);
if (economy.setPlayerMoney(playerName, (int) (balance - amount), false)) { if (balance - amount < 0) {
type = EconomyResponse.ResponseType.SUCCESS; errorMessage = "Insufficient funds";
balance = (double) economy.getPlayerMoney(playerName); type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(balance, balance, type, errorMessage);
} else { }
errorMessage = "Error withdrawing funds"; if (economy.setPlayerMoney(playerName, (int) (balance - amount), false)) {
type = EconomyResponse.ResponseType.FAILURE; type = EconomyResponse.ResponseType.SUCCESS;
amount = 0; balance = (double) economy.getPlayerMoney(playerName);
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} } else {
} errorMessage = "Error withdrawing funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
@Override return new EconomyResponse(amount, balance, type, errorMessage);
public EconomyResponse depositPlayer(String playerName, double amount) { }
double balance; }
EconomyResponse.ResponseType type;
String errorMessage = null;
if (amount < 0) { @Override
errorMessage = "Cannot deposit negative funds"; public EconomyResponse depositPlayer(String playerName, double amount) {
type = EconomyResponse.ResponseType.FAILURE; double balance;
amount = 0; EconomyResponse.ResponseType type;
balance = (double) economy.getPlayerMoney(playerName); String errorMessage = null;
return new EconomyResponse(balance, balance, type, errorMessage); if (amount < 0) {
} errorMessage = "Cannot deposit negative funds";
amount = Math.ceil(amount); type = EconomyResponse.ResponseType.FAILURE;
balance = (double) economy.getPlayerMoney(playerName); amount = 0;
if (economy.setPlayerMoney(playerName, (int) (balance + amount), false)) { balance = (double) economy.getPlayerMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(balance, balance, type, errorMessage);
} else { }
errorMessage = "Error withdrawing funds"; amount = Math.ceil(amount);
type = EconomyResponse.ResponseType.FAILURE; balance = (double) economy.getPlayerMoney(playerName);
amount = 0; if (economy.setPlayerMoney(playerName, (int) (balance + amount), false)) {
balance = (double) economy.getPlayerMoney(playerName); type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} } else {
} errorMessage = "Error withdrawing funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
public String getMoneyNamePlural() { return new EconomyResponse(balance, balance, type, errorMessage);
return economy.getMoneyNamePlural(); }
} }
public String getMoneyNameSingular() { public String getMoneyNamePlural() {
return economy.getMoneyName(); return economy.getMoneyNamePlural();
} }
private class EconomyServerListener extends ServerListener { public String getMoneyNameSingular() {
Economy_BOSE6 economy = null; return economy.getMoneyName();
}
public EconomyServerListener(Economy_BOSE6 economy) { private class EconomyServerListener extends ServerListener {
this.economy = economy; Economy_BOSE6 economy = null;
}
public void onPluginEnable(PluginEnableEvent event) { public EconomyServerListener(Economy_BOSE6 economy) {
if (economy.economy == null) { this.economy = economy;
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy"); }
if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) { public void onPluginEnable(PluginEnableEvent event) {
economy.economy = (BOSEconomy) bose; if (economy.economy == null) {
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name)); Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
}
}
}
public void onPluginDisable(PluginDisableEvent event) { if (bose != null && bose.isEnabled() && bose.getDescription().getVersion().startsWith("0.6")) {
if (economy.economy != null) { economy.economy = (BOSEconomy) bose;
if (event.getPlugin().getDescription().getName().equals("BOSEconomy") && event.getPlugin().getDescription().getVersion().startsWith("0.6")) { log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
economy.economy = null; }
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name)); }
} }
}
}
}
@Override public void onPluginDisable(PluginDisableEvent event) {
public String format(double amount) { if (economy.economy != null) {
if (amount == 1) { if (event.getPlugin().getDescription().getName().equals("BOSEconomy") && event.getPlugin().getDescription().getVersion().startsWith("0.6")) {
return String.format("%.0f %s", amount, getMoneyNameSingular()); economy.economy = null;
} else { log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
return String.format("%.2f %s", amount, getMoneyNamePlural()); }
} }
} }
}
@Override
public String format(double amount) {
if (amount == 1) {
return String.format("%.0f %s", amount, getMoneyNameSingular());
} else {
return String.format("%.2f %s", amount, getMoneyNamePlural());
}
}
@Override
public EconomyResponse createBank(String name, String player) {
boolean success = economy.addBankOwner(name, player, false);
if (success)
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create that bank account.");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
double bankMoney = economy.getBankMoney(name);
if (bankMoney < amount)
return new EconomyResponse(0, bankMoney, ResponseType.FAILURE, "The bank does not have enough money!");
else
return new EconomyResponse(0, bankMoney, ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
EconomyResponse er = bankHas(name, amount);
if (!er.transactionSuccess())
return er;
else {
economy.addBankMoney(name, (int) -amount, true);
return new EconomyResponse((int) amount, economy.getBankMoney(name), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (!economy.bankExists(name))
return new EconomyResponse(amount, 0, ResponseType.FAILURE, "That bank does not exist!");
else {
economy.addBankMoney(name, (int) amount, true);
return new EconomyResponse((int) amount, economy.getBankMoney(name), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
else if (economy.isBankOwner(name, playerName)) {
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
} else
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a bank owner!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
else if (economy.isBankMember(name, playerName)) {
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
} else
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a bank member!");
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -98,7 +99,7 @@ public class Economy_BOSE7 implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
amount = Math.ceil(amount); amount = Math.ceil(amount);
@ -109,7 +110,7 @@ public class Economy_BOSE7 implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
if (economy.setPlayerMoney(playerName, (int) (balance - amount), false)) { if (economy.setPlayerMoney(playerName, (int) (balance - amount), false)) {
type = EconomyResponse.ResponseType.SUCCESS; type = EconomyResponse.ResponseType.SUCCESS;
@ -138,7 +139,7 @@ public class Economy_BOSE7 implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
amount = Math.ceil(amount); amount = Math.ceil(amount);
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
@ -153,7 +154,7 @@ public class Economy_BOSE7 implements Economy {
amount = 0; amount = 0;
balance = (double) economy.getPlayerMoney(playerName); balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }
@ -201,4 +202,71 @@ public class Economy_BOSE7 implements Economy {
return String.format("%.2f %s", amount, getMoneyNamePlural()); return String.format("%.2f %s", amount, getMoneyNamePlural());
} }
} }
@Override
public EconomyResponse createBank(String name, String player) {
boolean success = economy.addBankOwner(name, player, false);
if (success)
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create that bank account.");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
double bankMoney = economy.getBankMoney(name);
if (bankMoney < amount)
return new EconomyResponse(0, bankMoney, ResponseType.FAILURE, "The bank does not have enough money!");
else
return new EconomyResponse(0, bankMoney, ResponseType.SUCCESS, "");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
EconomyResponse er = bankHas(name, amount);
if (!er.transactionSuccess())
return er;
else {
economy.addBankMoney(name, (int) -amount, true);
return new EconomyResponse((int) amount, economy.getBankMoney(name), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (!economy.bankExists(name))
return new EconomyResponse(amount, 0, ResponseType.FAILURE, "That bank does not exist!");
else {
economy.addBankMoney(name, (int) amount, true);
return new EconomyResponse((int) amount, economy.getBankMoney(name), ResponseType.SUCCESS, "");
}
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
else if (economy.isBankOwner(name, playerName)) {
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
} else
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a bank owner!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
if (!economy.bankExists(name))
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!");
else if (economy.isBankMember(name, playerName)) {
return new EconomyResponse(0, economy.getBankMoney(name), ResponseType.SUCCESS, "");
} else
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a bank member!");
}
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -208,4 +209,39 @@ public class Economy_Essentials implements Economy {
public String format(double amount) { public String format(double amount) {
return com.earth2me.essentials.api.Economy.format(amount); return com.earth2me.essentials.api.Economy.format(amount);
} }
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!");
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -99,7 +100,7 @@ public class Economy_MultiCurrency implements Economy {
amount = 0; amount = 0;
balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
if (!CurrencyList.hasEnough(playerName, amount)) { if (!CurrencyList.hasEnough(playerName, amount)) {
@ -108,7 +109,7 @@ public class Economy_MultiCurrency implements Economy {
amount = 0; amount = 0;
balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
if (CurrencyList.subtract(playerName, amount)) { if (CurrencyList.subtract(playerName, amount)) {
@ -138,7 +139,7 @@ public class Economy_MultiCurrency implements Economy {
amount = 0; amount = 0;
balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
if (CurrencyList.add(playerName, amount)) { if (CurrencyList.add(playerName, amount)) {
@ -152,7 +153,7 @@ public class Economy_MultiCurrency implements Economy {
amount = 0; amount = 0;
balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }
@ -188,4 +189,39 @@ public class Economy_MultiCurrency implements Economy {
public String format(double amount) { public String format(double amount) {
return String.format("%.2f %s", amount, "Currency"); return String.format("%.2f %s", amount, "Currency");
} }
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts");
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -199,4 +200,39 @@ public class Economy_iConomy4 implements Economy {
} }
} }
} }
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy4 does not support bank accounts!");
}
} }

View File

@ -23,6 +23,7 @@ import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -105,13 +106,13 @@ public class Economy_iConomy5 implements Economy {
holdings.subtract(amount); holdings.subtract(amount);
balance = getAccountBalance(playerName); balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS; type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} else { } else {
amount = 0; amount = 0;
balance = getAccountBalance(playerName); balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.FAILURE; type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Insufficient funds"; errorMessage = "Insufficient funds";
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }
@ -162,4 +163,39 @@ public class Economy_iConomy5 implements Economy {
public String format(double amount) { public String format(double amount) {
return iConomy.format(amount); return iConomy.format(amount);
} }
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single account banks!");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single bank accounts!");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single bank accounts!");
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single bank accounts!");
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single bank accounts!");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy5 does not support single bank accounts!");
}
} }

View File

@ -18,6 +18,7 @@ import com.iCo6.system.Holdings;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
public class Economy_iConomy6 implements Economy { public class Economy_iConomy6 implements Economy {
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
@ -117,13 +118,13 @@ public class Economy_iConomy6 implements Economy {
holdings.subtract(amount); holdings.subtract(amount);
balance = holdings.getBalance(); balance = holdings.getBalance();
type = EconomyResponse.ResponseType.SUCCESS; type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} else { } else {
amount = 0; amount = 0;
balance = holdings.getBalance(); balance = holdings.getBalance();
type = EconomyResponse.ResponseType.FAILURE; type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Insufficient funds"; errorMessage = "Insufficient funds";
return new EconomyResponse(balance, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
} }
@ -142,4 +143,50 @@ public class Economy_iConomy6 implements Economy {
return new EconomyResponse(amount, balance, type, errorMessage); return new EconomyResponse(amount, balance, type, errorMessage);
} }
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
}
@Override
public EconomyResponse createBank(String name, String player) {
if (accounts.exists(name))
return new EconomyResponse(0, accounts.get(name).getHoldings().getBalance(), ResponseType.FAILURE, "That account already exists.");
boolean created = accounts.create(name);
if (created)
return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
else
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There was an error creating the account");
}
@Override
public EconomyResponse bankHas(String name, double amount) {
if (has(name, amount))
return new EconomyResponse(0, amount, ResponseType.SUCCESS, "");
else
return new EconomyResponse(0, accounts.get(name).getHoldings().getBalance(), ResponseType.FAILURE, "The account does not have enough!");
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return withdrawPlayer(name, amount);
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return depositPlayer(name, amount);
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank owners.");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank members.");
}
} }