diff --git a/src/com/nijikokun/register_1_5/payment/Method.java b/src/com/nijikokun/register_1_5/payment/Method.java deleted file mode 100644 index 7b77179..0000000 --- a/src/com/nijikokun/register_1_5/payment/Method.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.nijikokun.register_1_5.payment; - -import org.bukkit.plugin.Plugin; - -/** - * Interface to be implemented by a payment method. - * - * @author Nijikokun (@nijikokun) - * @copyright Copyright (C) 2011 - * @license AOL license - */ -public interface Method { - /** - * Encodes the Plugin into an Object disguised as the Plugin. - * If you want the original Plugin Class you must cast it to the correct - * Plugin, to do so you have to verify the name and or version then cast. - * - *
-     *  if(method.getName().equalsIgnoreCase("iConomy"))
-     *   iConomy plugin = ((iConomy)method.getPlugin());
- * - * @return Object - * @see #getName() - * @see #getVersion() - */ - public Object getPlugin(); - - /** - * Returns the actual name of this method. - * - * @return String Plugin name. - */ - public String getName(); - - /** - * Returns the actual version of this method. - * - * @return String Plugin version. - */ - public String getVersion(); - - /** - * Returns the amount of decimal places that get stored - * NOTE: it will return -1 if there is no rounding - * - * @return int for each decimal place - */ - public int fractionalDigits(); - - /** - * Formats amounts into this payment methods style of currency display. - * - * @param amount Double - * @return String - Formatted Currency Display. - */ - public String format(double amount); - - /** - * Allows the verification of bank API existence in this payment method. - * - * @return boolean - */ - public boolean hasBanks(); - - /** - * Determines the existence of a bank via name. - * - * @param bank Bank name - * @return boolean - * @see #hasBanks - */ - public boolean hasBank(String bank); - - /** - * Determines the existence of an account via name. - * - * @param name Account name - * @return boolean - */ - public boolean hasAccount(String name); - - /** - * Check to see if an account name is tied to a bank. - * - * @param bank Bank name - * @param name Account name - * @return boolean - */ - public boolean hasBankAccount(String bank, String name); - - /** - * Forces an account creation - * - * @param name Account name - * @return boolean - */ - public boolean createAccount(String name); - - /** - * Forces an account creation - * - * @param name Account name - * @param balance Initial account balance - * @return boolean - */ - public boolean createAccount(String name, double balance); - - /** - * Returns a MethodAccount class for an account name. - * - * @param name Account name - * @return MethodAccount or Null - */ - public MethodAccount getAccount(String name); - - - /** - * Returns a MethodBankAccount class for an account name. - * - * @param bank Bank name - * @param name Account name - * @return MethodBankAccount or Null - */ - public MethodBankAccount getBankAccount(String bank, String name); - - /** - * Checks to verify the compatibility between this Method and a plugin. - * Internal usage only, for the most part. - * - * @param plugin Plugin - * @return boolean - */ - public boolean isCompatible(Plugin plugin); - - /** - * Set Plugin data. - * - * @param plugin Plugin - */ - public void setPlugin(Plugin plugin); - - /** - * Contains Calculator and Balance functions for Accounts. - */ - public interface MethodAccount { - public double balance(); - public boolean set(double amount); - public boolean add(double amount); - public boolean subtract(double amount); - public boolean multiply(double amount); - public boolean divide(double amount); - public boolean hasEnough(double amount); - public boolean hasOver(double amount); - public boolean hasUnder(double amount); - public boolean isNegative(); - public boolean remove(); - - @Override - public String toString(); - } - - /** - * Contains Calculator and Balance functions for Bank Accounts. - */ - public interface MethodBankAccount { - public double balance(); - public String getBankName(); - public int getBankId(); - public boolean set(double amount); - public boolean add(double amount); - public boolean subtract(double amount); - public boolean multiply(double amount); - public boolean divide(double amount); - public boolean hasEnough(double amount); - public boolean hasOver(double amount); - public boolean hasUnder(double amount); - public boolean isNegative(); - public boolean remove(); - - @Override - public String toString(); - } -} diff --git a/src/com/nijikokun/register_1_5/payment/Methods.java b/src/com/nijikokun/register_1_5/payment/Methods.java deleted file mode 100644 index 3943d2c..0000000 --- a/src/com/nijikokun/register_1_5/payment/Methods.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.nijikokun.register_1_5.payment; - -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - -import java.util.HashSet; -import java.util.Set; - -/** - * The Methods initializes Methods that utilize the Method interface - * based on a "first come, first served" basis. - *

- * Allowing you to check whether a payment method exists or not. - *

- * Methods also allows you to set a preferred method of payment before it captures - * payment plugins in the initialization process. - *

- * in bukkit.yml: - *

- *  economy:
- *      preferred: "iConomy"
- * 
- * - * @author: Nijikokun (@nijikokun) - * @copyright: Copyright (C) 2011 - * @license: AOL license - */ -public class Methods { - private static String version = null; - private static boolean self = false; - private static Method Method = null; - private static String preferred = ""; - private static Set Methods = new HashSet(); - private static Set Dependencies = new HashSet(); - private static Set Attachables = new HashSet(); - - static { - _init(); - } - - /** - * Implement all methods along with their respective name & class. - */ - private static void _init() { - addMethod("iConomy", new com.nijikokun.register_1_5.payment.methods.iCo6()); - addMethod("iConomy", new com.nijikokun.register_1_5.payment.methods.iCo5()); - addMethod("iConomy", new com.nijikokun.register_1_5.payment.methods.iCo4()); - addMethod("BOSEconomy", new com.nijikokun.register_1_5.payment.methods.BOSE6()); - addMethod("BOSEconomy", new com.nijikokun.register_1_5.payment.methods.BOSE7()); - addMethod("Essentials", new com.nijikokun.register_1_5.payment.methods.EE17()); - addMethod("Currency", new com.nijikokun.register_1_5.payment.methods.MCUR()); - addMethod("3co", new com.nijikokun.register_1_5.payment.methods.ECO3()); - Dependencies.add("MultiCurrency"); - } - - /** - * Used by the plugin to setup version - * - * @param v version - */ - public static void setVersion(String v) { - version = v; - } - - /** - * Use to reset methods during disable - */ - public static void reset() { - version = null; - self = false; - Method = null; - preferred = ""; - Attachables.clear(); - } - - /** - * Use to get version of Register plugin - * - * @return version - */ - public static String getVersion() { - return version; - } - - /** - * Returns an array of payment method names that have been loaded - * through the _init method. - * - * @return Set - Array of payment methods that are loaded. - * @see #setMethod(org.bukkit.plugin.PluginManager) - */ - public static Set getDependencies() { - return Dependencies; - } - - /** - * Interprets Plugin class data to verify whether it is compatible with an existing payment - * method to use for payments and other various economic activity. - * - * @param plugin Plugin data from bukkit, Internal Class file. - * @return Method or Null - */ - public static Method createMethod(Plugin plugin) { - for (Method method : Methods) - if (method.isCompatible(plugin)) { - method.setPlugin(plugin); - return method; - } - - return null; - } - - private static void addMethod(String name, Method method) { - Dependencies.add(name); - Methods.add(method); - } - - /** - * Verifies if Register has set a payment method for usage yet. - * - * @return boolean - * @see #setMethod(org.bukkit.plugin.PluginManager) - * @see #checkDisabled(org.bukkit.plugin.Plugin) - */ - public static boolean hasMethod() { - return (Method != null); - } - - /** - * Checks Plugin Class against a multitude of checks to verify it's usability - * as a payment method. - * - * @param manager the plugin manager for the server - * @return boolean True on success, False on failure. - */ - public static boolean setMethod(PluginManager manager) { - if (hasMethod()) - return true; - - if (self) { - self = false; - return false; - } - - int count = 0; - boolean match = false; - Plugin plugin = null; - - for (String name : getDependencies()) { - if (hasMethod()) - break; - - plugin = manager.getPlugin(name); - if (plugin == null || !plugin.isEnabled()) - continue; - - Method current = createMethod(plugin); - if (current == null) - continue; - - if (preferred.isEmpty()) - Method = current; - else - Attachables.add(current); - } - - if (!preferred.isEmpty()) { - do { - if (hasMethod()) - match = true; - else { - for (Method attached : Attachables) { - if (attached == null) continue; - - if (hasMethod()) { - match = true; break; - } - - if (preferred.isEmpty()) - Method = attached; - - if (count == 0) { - if (preferred.equalsIgnoreCase(attached.getName())) Method = attached; - } else { - Method = attached; - } - } - - count++; - } - } while (!match); - } - - return hasMethod(); - } - - /** - * Sets the preferred economy - * - * @param check The plugin name to check - * @return boolean - */ - public static boolean setPreferred(String check) { - if (getDependencies().contains(check)) { - preferred = check; - return true; - } - - return false; - } - - /** - * Grab the existing and initialized (hopefully) Method Class. - * - * @return Method or Null - */ - public static Method getMethod() { - return Method; - } - - /** - * Verify is a plugin is disabled, only does this if we there is an existing payment - * method initialized in register_1_5. - * - * @param method Plugin data from bukkit, Internal Class file. - * @return boolean - */ - public static boolean checkDisabled(Plugin method) { - if (!hasMethod()) - return true; - - if (Method.isCompatible(method)) - Method = null; - - return (Method == null); - } -} diff --git a/src/com/nijikokun/register_1_5/payment/methods/BOSE6.java b/src/com/nijikokun/register_1_5/payment/methods/BOSE6.java deleted file mode 100644 index f62b52b..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/BOSE6.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; - -import cosine.boseconomy.BOSEconomy; -import org.bukkit.plugin.Plugin; - -/** - * BOSEconomy 6 Implementation of Method - * - * @author Nijikokun (@nijikokun) - * @copyright (c) 2011 - * @license AOL license - */ -@SuppressWarnings("deprecation") -public class BOSE6 implements Method { - private BOSEconomy BOSEconomy; - - public BOSEconomy getPlugin() { - return this.BOSEconomy; - } - - public String getName() { - return "BOSEconomy"; - } - - public String getVersion() { - return "0.6.2"; - } - - public int fractionalDigits() { - return 0; - } - - public String format(double amount) { - String currency = this.BOSEconomy.getMoneyNamePlural(); - - if(amount == 1) - currency = this.BOSEconomy.getMoneyName(); - - return amount + " " + currency; - } - - public boolean hasBanks() { - return true; - } - - public boolean hasBank(String bank) { - return this.BOSEconomy.bankExists(bank); - } - - public boolean hasAccount(String name) { - return this.BOSEconomy.playerRegistered(name, false); - } - - public boolean hasBankAccount(String bank, String name) { - return this.BOSEconomy.isBankOwner(bank, name) - || this.BOSEconomy.isBankMember(bank, name); - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - this.BOSEconomy.registerPlayer(name); - return true; - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - this.BOSEconomy.registerPlayer(name); - this.BOSEconomy.setPlayerMoney(name, balance, false); - return true; - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) - return null; - - return new BOSEAccount(name, this.BOSEconomy); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - if(!hasBankAccount(bank, name)) - return null; - - return new BOSEBankAccount(bank, BOSEconomy); - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") - && plugin instanceof BOSEconomy - && plugin.getDescription().getVersion().equals("0.6.2"); - } - - public void setPlugin(Plugin plugin) { - BOSEconomy = (BOSEconomy) plugin; - } - - public class BOSEAccount implements MethodAccount { - private final String name; - private final BOSEconomy BOSEconomy; - - public BOSEAccount(String name, BOSEconomy bOSEconomy) { - this.name = name; - this.BOSEconomy = bOSEconomy; - } - - public double balance() { - return (double) this.BOSEconomy.getPlayerMoney(this.name); - } - - public boolean set(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false); - } - - public boolean add(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false); - } - - public boolean subtract(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false); - } - - public boolean multiply(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false); - } - - public boolean divide(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return false; - } - } - - public class BOSEBankAccount implements MethodBankAccount { - private final String bank; - private final BOSEconomy BOSEconomy; - - public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { - this.bank = bank; - this.BOSEconomy = bOSEconomy; - } - - public String getBankName() { - return this.bank; - } - - public int getBankId() { - return -1; - } - - public double balance() { - return (double) this.BOSEconomy.getBankMoney(bank); - } - - public boolean set(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.setBankMoney(bank, IntAmount, true); - } - - public boolean add(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false); - } - - public boolean subtract(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false); - } - - public boolean multiply(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false); - } - - public boolean divide(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.BOSEconomy.removeBank(bank); - } - } -} \ No newline at end of file diff --git a/src/com/nijikokun/register_1_5/payment/methods/BOSE7.java b/src/com/nijikokun/register_1_5/payment/methods/BOSE7.java deleted file mode 100644 index 7c8179e..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/BOSE7.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; - -import cosine.boseconomy.BOSEconomy; -import org.bukkit.plugin.Plugin; - -/** - * BOSEconomy 7 Implementation of Method - * - * @author Acrobot - * @author Nijikokun (@nijikokun) - * @copyright (c) 2011 - * @license AOL license - */ -public class BOSE7 implements Method { - private BOSEconomy BOSEconomy; - - public BOSEconomy getPlugin() { - return this.BOSEconomy; - } - - public String getName() { - return "BOSEconomy"; - } - - public String getVersion() { - return "0.7.0"; - } - - public int fractionalDigits() { - return this.BOSEconomy.getFractionalDigits(); - } - - public String format(double amount) { - String currency = this.BOSEconomy.getMoneyNamePlural(); - - if(amount == 1) - currency = this.BOSEconomy.getMoneyName(); - - return amount + " " + currency; - } - - public boolean hasBanks() { - return true; - } - - public boolean hasBank(String bank) { - return this.BOSEconomy.bankExists(bank); - } - - public boolean hasAccount(String name) { - return this.BOSEconomy.playerRegistered(name, false); - } - - public boolean hasBankAccount(String bank, String name) { - return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - this.BOSEconomy.registerPlayer(name); - return true; - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - this.BOSEconomy.registerPlayer(name); - this.BOSEconomy.setPlayerMoney(name, balance, false); - return true; - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) - return null; - - return new BOSEAccount(name, this.BOSEconomy); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - if(!hasBankAccount(bank, name)) - return null; - - return new BOSEBankAccount(bank, BOSEconomy); - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") - && plugin instanceof BOSEconomy - && !plugin.getDescription().getVersion().equals("0.6.2"); - } - - public void setPlugin(Plugin plugin) { - BOSEconomy = (BOSEconomy)plugin; - } - - public class BOSEAccount implements MethodAccount { - private String name; - private BOSEconomy BOSEconomy; - - public BOSEAccount(String name, BOSEconomy bOSEconomy) { - this.name = name; - this.BOSEconomy = bOSEconomy; - } - - public double balance() { - return this.BOSEconomy.getPlayerMoneyDouble(this.name); - } - - public boolean set(double amount) { - return this.BOSEconomy.setPlayerMoney(this.name, amount, false); - } - - public boolean add(double amount) { - return this.BOSEconomy.addPlayerMoney(this.name, amount, false); - } - - public boolean subtract(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return false; - } - } - - public class BOSEBankAccount implements MethodBankAccount { - private String bank; - private BOSEconomy BOSEconomy; - - public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { - this.bank = bank; - this.BOSEconomy = bOSEconomy; - } - - public String getBankName() { - return this.bank; - } - - public int getBankId() { - return -1; - } - - public double balance() { - return this.BOSEconomy.getBankMoneyDouble(bank); - } - - public boolean set(double amount) { - return this.BOSEconomy.setBankMoney(bank, amount, true); - } - - public boolean add(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance + amount), false); - } - - public boolean subtract(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance - amount), false); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance * amount), false); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance / amount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.BOSEconomy.removeBank(bank); - } - } -} \ No newline at end of file diff --git a/src/com/nijikokun/register_1_5/payment/methods/ECO3.java b/src/com/nijikokun/register_1_5/payment/methods/ECO3.java deleted file mode 100644 index c0873fa..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/ECO3.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; -import me.ic3d.eco.ECO; -import org.bukkit.plugin.Plugin; - -/** - * 3co implementation of Method. - * - * @copyright (c) 2011 - * @license AOL license - */ -public class ECO3 implements Method { - private ECO eco; - - public Object getPlugin() { - return this.eco; - } - - public String getName() { - return "3co"; - } - - public String getVersion() { - return "2.0"; - } - - public int fractionalDigits() { - return 0; - } - - public String format(double amount) { - return (int) Math.ceil(amount) + " " + (amount == 1 ? eco.singularCurrency : eco.pluralCurrency); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return eco.hasAccount(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public boolean createAccount(String name) { - if (hasAccount(name)) return false; - eco.createAccount(name, 0); - return true; - } - - public boolean createAccount(String name, double balance) { - if (hasAccount(name)) return false; - eco.createAccount(name, (int) balance); - return true; - } - - public MethodAccount getAccount(String name) { - if (!hasAccount(name)) createAccount(name); //Still somehow fails - it's 3co's issue - return new ECO3Account(name); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equals("3co") && plugin.getClass().getName().equals("me.ic3d.eco.ECO") && plugin instanceof ECO; - } - - public void setPlugin(Plugin plugin) { - this.eco = (ECO) plugin; - } - - public class ECO3Account implements MethodAccount { - private String name; - - public ECO3Account(String name) { - this.name = name; - } - - public double balance() { - return eco.getMoney(name); - } - - public boolean set(double amount) { - eco.setMoney(name, (int) Math.ceil(amount)); - return true; - } - - public boolean add(double amount) { - set(balance() + amount); - return true; - } - - public boolean subtract(double amount) { - set(balance() - amount); - return true; - } - - public boolean multiply(double amount) { - set(balance() * amount); - return true; - } - - public boolean divide(double amount) { - set(balance() / amount); - return true; - } - - public boolean hasEnough(double amount) { - return eco.hasEnough(name, (int) Math.ceil(amount)); - } - - public boolean hasOver(double amount) { - return balance() > amount; - } - - public boolean hasUnder(double amount) { - return balance() < amount; - } - - public boolean isNegative() { - return balance() < 0; - } - - public boolean remove() { - return false; - } - } -} diff --git a/src/com/nijikokun/register_1_5/payment/methods/EE17.java b/src/com/nijikokun/register_1_5/payment/methods/EE17.java deleted file mode 100644 index c8578e4..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/EE17.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.api.Economy; - -import org.bukkit.plugin.Plugin; - -/** - * Essentials 17 Implementation of Method - * - * @author Nijikokun (@nijikokun) - * @author Snowleo - * @author Acrobot - * @author KHobbits - * @copyright (c) 2011 - * @license AOL license - */ -public class EE17 implements Method { - private Essentials Essentials; - - public Essentials getPlugin() { - return this.Essentials; - } - - public String getName() { - return "Essentials"; - } - - public String getVersion() { - return "2.2"; - } - - public int fractionalDigits() { - return -1; - } - - public String format(double amount) { - return Economy.format(amount); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return Economy.playerExists(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - Economy.createNPC(name); - return true; - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - Economy.createNPC(name); - - try { - Economy.setMoney(name, balance); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) - return null; - - return new EEcoAccount(name); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - try { Class.forName("com.earth2me.essentials.api.Economy"); } - catch(Exception e) { return false; } - - return plugin.getDescription().getName().equalsIgnoreCase("essentials") - && plugin instanceof Essentials; - } - - public void setPlugin(Plugin plugin) { - Essentials = (Essentials)plugin; - } - - public class EEcoAccount implements MethodAccount { - private String name; - - public EEcoAccount(String name) { - this.name = name; - } - - public double balance() { - Double balance = 0.0; - - try { - balance = Economy.getMoney(this.name); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - } - - return balance; - } - - public boolean set(double amount) { - try { - Economy.setMoney(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public boolean add(double amount) { - try { - Economy.add(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public boolean subtract(double amount) { - try { - Economy.subtract(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public boolean multiply(double amount) { - try { - Economy.multiply(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public boolean divide(double amount) { - try { - Economy.divide(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - return false; - } - - return true; - } - - public boolean hasEnough(double amount) { - try { - return Economy.hasEnough(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - } - - return false; - } - - public boolean hasOver(double amount) { - try { - return Economy.hasMore(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - } - - return false; - } - - public boolean hasUnder(double amount) { - try { - return Economy.hasLess(name, amount); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - } - - return false; - } - - public boolean isNegative() { - try { - return Economy.isNegative(name); - } catch (Exception ex) { - System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage()); - } - - return false; - } - - public boolean remove() { - return false; - } - } -} \ No newline at end of file diff --git a/src/com/nijikokun/register_1_5/payment/methods/MCUR.java b/src/com/nijikokun/register_1_5/payment/methods/MCUR.java deleted file mode 100644 index 890b9ee..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/MCUR.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; - -import me.ashtheking.currency.Currency; -import me.ashtheking.currency.CurrencyList; - -import org.bukkit.plugin.Plugin; - -/** - * MultiCurrency Method implementation. - * - * @author Acrobot - * @copyright (c) 2011 - * @license AOL license - */ -public class MCUR implements Method { - private Currency currencyList; - - public Object getPlugin() { - return this.currencyList; - } - - public String getName() { - return "MultiCurrency"; - } - - public String getVersion() { - return "0.09"; - } - - public int fractionalDigits() { - return -1; - } - - public String format(double amount) { - return amount + " Currency"; - } - - public boolean hasBanks() { - return true; - } - - public boolean hasBank(String bank) { - return CurrencyList.getAllCurrencys().contains(bank); - } - - public boolean hasAccount(String name) { - return true; - } - - public boolean hasBankAccount(String bank, String name) { - return CurrencyList.getAllCurrencys().contains(bank); - } - - public boolean createAccount(String name) { - CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, 0); - return true; - } - - public boolean createAccount(String name, double balance) { - CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, balance); - return true; - } - - public MethodAccount getAccount(String name) { - return new MCurrencyAccount(name); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return new MCurrencyAccount(name, bank); - } - - public boolean isCompatible(Plugin plugin) { - return (plugin.getDescription().getName().equalsIgnoreCase("Currency") - || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency")) - && plugin instanceof Currency; - } - - public void setPlugin(Plugin plugin) { - currencyList = (Currency) plugin; - } - - public class MCurrencyAccount implements MethodAccount, MethodBankAccount{ - private String name; - private String currency; - - public MCurrencyAccount(String name) { - this.name = name; - this.currency = (String) CurrencyList.maxCurrency(name)[0]; - } - public MCurrencyAccount(String name, String currency) { - this.name = name; - this.currency = currency; - } - - public double balance() { - return CurrencyList.getValue(currency, name); - } - - public String getBankName() { - return currency; - } - - public int getBankId() { - return -1; - } - - public boolean set(double amount) { - CurrencyList.setValue(currency, name, amount); - return true; - } - - public boolean add(double amount) { - return CurrencyList.add(name, amount, currency); - } - - public boolean subtract(double amount) { - return CurrencyList.subtract(name, amount, currency); - } - - public boolean multiply(double amount) { - return CurrencyList.multiply(name, amount, currency); - } - - public boolean divide(double amount) { - return CurrencyList.divide(name, amount, currency); - } - - public boolean hasEnough(double amount) { - return CurrencyList.hasEnough(name, amount, currency); - } - - public boolean hasOver(double amount) { - return CurrencyList.hasOver(name, amount, currency); - } - - public boolean hasUnder(double amount) { - return CurrencyList.hasUnder(name, amount, currency); - } - - public boolean isNegative() { - return CurrencyList.isNegative(name, currency); - } - - public boolean remove() { - return CurrencyList.remove(name, currency); - } - } -} diff --git a/src/com/nijikokun/register_1_5/payment/methods/iCo4.java b/src/com/nijikokun/register_1_5/payment/methods/iCo4.java deleted file mode 100644 index 0d488a2..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/iCo4.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; -import com.nijiko.coelho.iConomy.iConomy; -import com.nijiko.coelho.iConomy.system.Account; - - -import org.bukkit.plugin.Plugin; - -/** - * iConomy 4 Implementation of Method - * - * @author Nijikokun (@nijikokun) - * @copyright (c) 2011 - * @license AOL license - */ -public class iCo4 implements Method { - private iConomy iConomy; - - public iConomy getPlugin() { - return this.iConomy; - } - - public String getName() { - return "iConomy"; - } - - public String getVersion() { - return "4"; - } - - public int fractionalDigits() { - return 2; - } - - public String format(double amount) { - return com.nijiko.coelho.iConomy.iConomy.getBank().format(amount); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return com.nijiko.coelho.iConomy.iConomy.getBank().hasAccount(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - try { - com.nijiko.coelho.iConomy.iConomy.getBank().addAccount(name); - } catch(Exception E) { - return false; - } - - return true; - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - try { - com.nijiko.coelho.iConomy.iConomy.getBank().addAccount(name, balance); - } catch(Exception E) { - return false; - } - - return true; - } - - public MethodAccount getAccount(String name) { - return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name)); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") - && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") - && plugin instanceof iConomy; - } - - public void setPlugin(Plugin plugin) { - iConomy = (iConomy)plugin; - } - - public class iCoAccount implements MethodAccount { - private Account account; - - public iCoAccount(Account account) { - this.account = account; - } - - public Account getiCoAccount() { - return account; - } - - public double balance() { - return this.account.getBalance(); - } - - public boolean set(double amount) { - if(this.account == null) return false; - this.account.setBalance(amount); - return true; - } - - public boolean add(double amount) { - if(this.account == null) return false; - this.account.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.account == null) return false; - this.account.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.account == null) return false; - this.account.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.account == null) return false; - this.account.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.account.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.account.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return this.account.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } -} diff --git a/src/com/nijikokun/register_1_5/payment/methods/iCo5.java b/src/com/nijikokun/register_1_5/payment/methods/iCo5.java deleted file mode 100644 index 47ab56c..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/iCo5.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; -import com.iConomy.iConomy; -import com.iConomy.system.Account; -import com.iConomy.system.BankAccount; -import com.iConomy.system.Holdings; -import com.iConomy.util.Constants; - - -import org.bukkit.plugin.Plugin; - -/** - * iConomy 5 Implementation of Method - * - * @author Nijikokun (@nijikokun) - * @copyright (c) 2011 - * @license AOL license - */ -public class iCo5 implements Method { - private iConomy iConomy; - - public iConomy getPlugin() { - return this.iConomy; - } - - public String getName() { - return "iConomy"; - } - - public String getVersion() { - return "5"; - } - - public int fractionalDigits() { - return 2; - } - - public String format(double amount) { - return com.iConomy.iConomy.format(amount); - } - - public boolean hasBanks() { - return Constants.Banking; - } - - public boolean hasBank(String bank) { - return (hasBanks()) && com.iConomy.iConomy.Banks.exists(bank); - } - - public boolean hasAccount(String name) { - return com.iConomy.iConomy.hasAccount(name); - } - - public boolean hasBankAccount(String bank, String name) { - return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name); - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - return com.iConomy.iConomy.Accounts.create(name); - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - if(!com.iConomy.iConomy.Accounts.create(name)) - return false; - - getAccount(name).set(balance); - - return true; - } - - public MethodAccount getAccount(String name) { - return new iCoAccount(com.iConomy.iConomy.getAccount(name)); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return new iCoBankAccount(com.iConomy.iConomy.getBank(bank).getAccount(name)); - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") - && plugin.getClass().getName().equals("com.iConomy.iConomy") - && plugin instanceof iConomy; - } - - public void setPlugin(Plugin plugin) { - iConomy = (iConomy)plugin; - } - - public class iCoAccount implements MethodAccount { - private Account account; - private Holdings holdings; - - public iCoAccount(Account account) { - this.account = account; - this.holdings = account.getHoldings(); - } - - public Account getiCoAccount() { - return account; - } - - public double balance() { - return this.holdings.balance(); - } - - public boolean set(double amount) { - if(this.holdings == null) return false; - this.holdings.set(amount); - return true; - } - - public boolean add(double amount) { - if(this.holdings == null) return false; - this.holdings.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.holdings == null) return false; - this.holdings.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.holdings == null) return false; - this.holdings.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.holdings == null) return false; - this.holdings.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.holdings.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.holdings.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return this.holdings.hasUnder(amount); - } - - public boolean isNegative() { - return this.holdings.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } - - public class iCoBankAccount implements MethodBankAccount { - private BankAccount account; - private Holdings holdings; - - public iCoBankAccount(BankAccount account) { - this.account = account; - this.holdings = account.getHoldings(); - } - - public BankAccount getiCoBankAccount() { - return account; - } - - public String getBankName() { - return this.account.getBankName(); - } - - public int getBankId() { - return this.account.getBankId(); - } - - public double balance() { - return this.holdings.balance(); - } - - public boolean set(double amount) { - if(this.holdings == null) return false; - this.holdings.set(amount); - return true; - } - - public boolean add(double amount) { - if(this.holdings == null) return false; - this.holdings.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.holdings == null) return false; - this.holdings.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.holdings == null) return false; - this.holdings.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.holdings == null) return false; - this.holdings.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.holdings.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.holdings.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return this.holdings.hasUnder(amount); - } - - public boolean isNegative() { - return this.holdings.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } -} \ No newline at end of file diff --git a/src/com/nijikokun/register_1_5/payment/methods/iCo6.java b/src/com/nijikokun/register_1_5/payment/methods/iCo6.java deleted file mode 100644 index 9a5200e..0000000 --- a/src/com/nijikokun/register_1_5/payment/methods/iCo6.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.nijikokun.register_1_5.payment.methods; - -import com.nijikokun.register_1_5.payment.Method; -import com.iCo6.iConomy; -import com.iCo6.system.Account; -import com.iCo6.system.Accounts; -import com.iCo6.system.Holdings; - - -import org.bukkit.plugin.Plugin; - -/** - * iConomy 6 Implementation of Method - * - * @author Nijikokun (@nijikokun) - * @copyright (c) 2011 - * @license AOL license - */ -public class iCo6 implements Method { - private iConomy iConomy; - - public iConomy getPlugin() { - return this.iConomy; - } - - public String getName() { - return "iConomy"; - } - - public String getVersion() { - return "6"; - } - - public int fractionalDigits() { - return 2; - } - - public String format(double amount) { - return com.iCo6.iConomy.format(amount); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return (new Accounts()).exists(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public boolean createAccount(String name) { - if(hasAccount(name)) - return false; - - return (new Accounts()).create(name); - } - - public boolean createAccount(String name, double balance) { - if(hasAccount(name)) - return false; - - return (new Accounts()).create(name, balance); - } - - public MethodAccount getAccount(String name) { - return new iCoAccount((new Accounts()).get(name)); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") - && plugin.getClass().getName().equals("com.iCo6.iConomy") - && plugin instanceof iConomy; - } - - public void setPlugin(Plugin plugin) { - iConomy = (iConomy)plugin; - } - - public class iCoAccount implements MethodAccount { - private Account account; - private Holdings holdings; - - public iCoAccount(Account account) { - this.account = account; - this.holdings = account.getHoldings(); - } - - public Account getiCoAccount() { - return account; - } - - public double balance() { - return this.holdings.getBalance(); - } - - public boolean set(double amount) { - if(this.holdings == null) return false; - this.holdings.setBalance(amount); - return true; - } - - public boolean add(double amount) { - if(this.holdings == null) return false; - this.holdings.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.holdings == null) return false; - this.holdings.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.holdings == null) return false; - this.holdings.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.holdings == null) return false; - this.holdings.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.holdings.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.holdings.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return this.holdings.hasUnder(amount); - } - - public boolean isNegative() { - return this.holdings.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } -} diff --git a/src/me/jascotty2/bettershop/BSConfig.java b/src/me/jascotty2/bettershop/BSConfig.java index df75826..7deba6c 100644 --- a/src/me/jascotty2/bettershop/BSConfig.java +++ b/src/me/jascotty2/bettershop/BSConfig.java @@ -709,7 +709,7 @@ private void extractFile(File dest, String fname) { } public void setCurrency() { - try { + //try { // if (BetterShop.iConomy != null) { // String t = BetterShop.iConomy.format(1.); // defaultCurrency = t.substring(t.indexOf(" ") + 1); @@ -732,7 +732,7 @@ public void setCurrency() { // pluralCurrency = config.getString("currency-name-plural", pluralCurrency); // } // } - String eco = BSEcon.economyMethod.getName(); +/* String eco = BSEcon.economyMethod.getName(); if (eco.equalsIgnoreCase("iConomy") @@ -760,7 +760,10 @@ public void setCurrency() { BetterShopLogger.Log(Level.SEVERE, "Error Extracting Currency Name", e, false); - } + }*/ + defaultCurrency = BSEcon.econ.currencyNameSingular(); + pluralCurrency = BSEcon.econ.currencyNamePlural(); + } public boolean useMySQL() { diff --git a/src/me/jascotty2/bettershop/BSEcon.java b/src/me/jascotty2/bettershop/BSEcon.java index 5fdb59e..c573e76 100644 --- a/src/me/jascotty2/bettershop/BSEcon.java +++ b/src/me/jascotty2/bettershop/BSEcon.java @@ -17,8 +17,6 @@ */ package me.jascotty2.bettershop; -import com.nijikokun.register_1_5.payment.Method; -import com.nijikokun.register_1_5.payment.Methods; import java.util.Map.Entry; import me.jascotty2.bettershop.enums.EconMethod; import me.jascotty2.bettershop.utils.BSPermissions; @@ -26,24 +24,15 @@ import net.milkbowl.vault.Vault; import net.milkbowl.vault.economy.Economy; import org.bukkit.entity.Player; -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; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredServiceProvider; public class BSEcon implements Listener { - protected static Method economyMethod = null; - protected static Methods _econMethods = new Methods(); protected static String methodName = null; protected static Economy econ = null; - // iconomy seems to throw alot of errors... - // this is to only display one - static boolean _pastBalanceErr = false; static BetterShop plugin; final PluginManager pm; @@ -54,7 +43,10 @@ public BSEcon(BetterShop plugin) { methodName = econ.getName(); BetterShopLogger.Log("Using " + methodName + " (via Vault) for economy"); } - Methods.setMethod(pm); + else { + BetterShopLogger.Severe("[BetterShop] Error: Vault not found or Vault failed to register economy. Disabling plugin."); + pm.disablePlugin(plugin); + } } private boolean setupEconomy() { @@ -70,34 +62,8 @@ private boolean setupEconomy() { return econ != null; } - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (econ != null) { - return; - } - if (!Methods.hasMethod() && Methods.setMethod(plugin.getServer().getPluginManager())) { - economyMethod = Methods.getMethod(); - methodName = economyMethod.getName() + " v" + economyMethod.getVersion(); - BetterShopLogger.Log("Using " + methodName + " for economy"); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (econ != null) { - return; - } - // Check to see if the plugin thats being disabled is the one we are using - if (_econMethods != null && Methods.hasMethod() && Methods.checkDisabled(event.getPlugin())) { - economyMethod = null; - methodName = null; - Methods.reset(); - BetterShopLogger.Log(" Economy Plugin was disabled."); - } - } - public static boolean active() { - return BetterShop.config.econ != EconMethod.AUTO || econ != null || economyMethod != null; + return BetterShop.config.econ != EconMethod.AUTO || econ != null; } public static String getMethodName() { @@ -112,8 +78,7 @@ public static String getMethodName() { public static boolean hasAccount(Player pl) { return pl != null && (BetterShop.config.econ != EconMethod.AUTO - || (econ != null && econ.hasAccount(pl.getName())) - || (economyMethod != null && economyMethod.hasAccount(pl.getName()))); + || (econ != null && econ.hasAccount(pl.getName()))); } public static boolean canAfford(Player pl, double amt) { @@ -151,15 +116,9 @@ public static double getBalance(String playerName) { try { if (econ != null && econ.hasAccount(playerName)) { return econ.getBalance(playerName); - } else if (economyMethod != null && economyMethod.hasAccount(playerName)) { - return economyMethod.getAccount(playerName).balance(); } } catch (Exception e) { - if (!_pastBalanceErr) { - BetterShopLogger.Severe("Error looking up player balance \n" - + "(this error will only show once)", e, false); - _pastBalanceErr = true; - } + BetterShopLogger.Severe("Error looking up player balance.", e, false); } return 0; } @@ -195,12 +154,6 @@ public static void addMoney(String playerName, double amt) { return; } econ.depositPlayer(playerName, amt); - } else if (economyMethod != null) { - if (!economyMethod.hasAccount(playerName)) { - // TODO? add methods for creating an account - return; - } - economyMethod.getAccount(playerName).add(amt); } } @@ -253,12 +206,6 @@ public static void subtractMoney(String playerName, double amt) { return; } econ.withdrawPlayer(playerName, amt); - } else if (economyMethod != null) { - if (!economyMethod.hasAccount(playerName)) { - // TODO? add methods for creating an account - return; - } - economyMethod.getAccount(playerName).subtract(amt); } } @@ -276,139 +223,46 @@ public static double getPlayerDiscount(Player p) { } public static boolean credit(Player player, double amount) { - if (amount <= 0) { - return amount == 0 || debit(player, -amount); - } - if (BSEcon.active()) { - try { - if (bankTransaction(player.getName(), amount)) { - return true; - } - } catch (Exception ex) { - BetterShopLogger.Severe("Failed to credit player", ex, false); - return true; - } - BetterShopLogger.Severe("Failed to credit player", false); - // something seems to be wrong with iConomy: reload it -// BetterShopLogger.Log(Level.SEVERE, "Failed to credit player: attempting iConomy reload", false); -// if (reloadIConomy(player.getServer())) { -// try { -// if (bankTransaction(player.getName(), amount)) { -// return true; -// } -// } catch (Exception ex) { -// } -// } -// BetterShopLogger.Log(Level.SEVERE, "iConomy reload failed to resolve issue.", false); - } else { - BetterShopLogger.Severe("Failed to credit player: no economy plugin", false); - return false; - } - return true; + return execTransaction(player,amount); } public static boolean debit(Player player, double amount) { - if (amount <= 0) { - return amount == 0 || credit(player, -amount); - } else if (getBalance(player) < amount) { - return false; - } - if (BSEcon.active()) { - try { - if (bankTransaction(player.getName(), -amount)) { - return true; - } - } catch (Exception ex) { - BetterShopLogger.Severe("Failed to debit player", ex, false); - return true; - } - BetterShopLogger.Severe("Failed to debit player", false); + return execTransaction(player,-amount); + } - // something seems to be wrong with iConomy: reload it -// BetterShopLogger.Log(Level.SEVERE, "Failed to debit player: attempting iConomy reload", false); -// if (reloadIConomy(player.getServer())) { -// try { -// if (bankTransaction(player.getName(), -amount)) { -// return true; -// } -// } catch (Exception ex) { -// } -// } -// BetterShopLogger.Log(Level.SEVERE, "iConomy reload failed to resolve issue.", false); - } else { - BetterShopLogger.Severe("Failed to debit player: no economy plugin", false); + private static boolean execTransaction(Player player, double amount) { + if (econ == null) return false; + if ((BetterShop.config.econ == EconMethod.AUTO + && BetterShop.getSettings().BOSBank != null + && !BetterShop.getSettings().BOSBank.trim().isEmpty() + && hasBank(BetterShop.getSettings().BOSBank))) { + return bankTransaction(amount); + } + if (amount < 0) { + if (econ.has(player.getName(), amount)) return econ.withdrawPlayer(player.getName(), -amount).transactionSuccess(); return false; } - return true; + return econ.depositPlayer(player.getName(), amount).transactionSuccess(); } - private static boolean bankTransaction(String player, double amount) { - // don't allow account to go negative - double preAmt = BSEcon.getBalance(player); - if (amount > 0 || preAmt >= -amount) { - BSEcon.addMoney(player, amount); - if (BetterShop.config.econ == EconMethod.AUTO - && BetterShop.getSettings().BOSBank != null - && !BetterShop.getSettings().BOSBank.trim().isEmpty() - && hasBank(BetterShop.getSettings().BOSBank)) { - if (economyMethod != null) { - BSEcon.addMoney(BetterShop.getSettings().BOSBank, -amount); - } else if (econ != null) { - if (amount < 0) { - econ.bankWithdraw(BetterShop.getSettings().BOSBank, -amount); - } else { - econ.bankDeposit(BetterShop.getSettings().BOSBank, -amount); - } - } + private static boolean bankTransaction(double amount) { + if (amount < 0) { + if (econ.bankHas(BetterShop.getSettings().BOSBank,amount).transactionSuccess()) { + return econ.bankWithdraw(BetterShop.getSettings().BOSBank, -amount).transactionSuccess(); } - return BSEcon.getBalance(player) != preAmt; + return false; } - return false; + return econ.bankDeposit(BetterShop.getSettings().BOSBank, amount).transactionSuccess(); } public static String format(double amt) { - try { - if (econ != null) { - return econ.format(amt); - } else if (economyMethod != null) { - return economyMethod.format(amt); - } - return String.format("%.2f", amt) + " " - + (amt > 1 || amt < 1 ? BetterShop.getSettings().pluralCurrency - : BetterShop.getSettings().defaultCurrency); - } catch (Exception ex) { - BetterShopLogger.Warning("Error Formatting Currency", ex, false); - } - return String.format("%.2f", amt); + return econ.format(amt); } public static boolean hasBank(String bank) { -// return economyMethod != null -// ? economyMethod.hasBanks() && economyMethod.hasBank(bank) -// : econ != null ? econ.hasBankSupport() && econ.getBanks().contains(bank) : false; - - if (economyMethod != null) { - return economyMethod.hasBanks() && economyMethod.hasBank(bank); - } else if (econ != null && econ.hasBankSupport()) { + if (econ != null && econ.hasBankSupport()) { return econ.bankBalance(bank).transactionSuccess(); } return false; } -// -// static boolean reloadIConomy(Server serv) { -// try { -// PluginManager m = serv.getPluginManager(); -// Plugin icon = m.getPlugin("iConomy"); -// if (icon != null) { -// m.disablePlugin(icon); -// m.enablePlugin(icon); -// -// return true; -// } -// } catch (Exception ex) { -// BetterShopLogger.Log(Level.SEVERE, "Error reloading iConomy", ex); -// } -// return false; -// } -} // end class BSEcon - +} \ No newline at end of file diff --git a/src/me/jascotty2/bettershop/BSPluginListener.java b/src/me/jascotty2/bettershop/BSPluginListener.java index 7911f11..d13d547 100644 --- a/src/me/jascotty2/bettershop/BSPluginListener.java +++ b/src/me/jascotty2/bettershop/BSPluginListener.java @@ -29,8 +29,6 @@ import org.bukkit.plugin.java.JavaPlugin; import com.jascotty2.minecraftim.MinecraftIM; -import com.nijikokun.bukkit.Permissions.Permissions; -import me.taylorkelly.help.Help; import net.milkbowl.vault.Vault; import net.milkbowl.vault.permission.Permission; import org.bukkit.event.EventHandler; @@ -49,10 +47,9 @@ public BSPluginListener(BetterShop plugin) { shop = plugin; PluginManager pm = plugin.getServer().getPluginManager(); checkVaultPermissions(pm.getPlugin("Vault")); - checkPermissions(pm.getPlugin("Permissions")); checkMIM(pm.getPlugin("MinecraftIM")); checkSpout(pm.getPlugin("Spout")); - checkHelp(pm.getPlugin("Help")); + //checkHelp(pm.getPlugin("Help")); } @EventHandler(priority = EventPriority.MONITOR) @@ -60,15 +57,13 @@ public void onPluginEnable(PluginEnableEvent event) { if (event.getPlugin().isEnabled()) { // double-checking if enabled String pName = event.getPlugin().getDescription().getName(); if (pName.equals("Help")) { - checkHelp(event.getPlugin()); + //checkHelp(event.getPlugin()); } else if (pName.equals("MinecraftIM")) { checkMIM(event.getPlugin()); - } else if (pName.equals("Permissions")) { - checkPermissions(event.getPlugin()); } else if (pName.equals("Spout")) { checkSpout(event.getPlugin()); } else { - BetterShop.economy.onPluginEnable(event); + //BetterShop.economy.onPluginEnable(event); } } } @@ -80,12 +75,12 @@ public final void checkMIM(Plugin p) { } } - public final void checkHelp(Plugin p) { + /*public final void checkHelp(Plugin p) { if (!HelpCommands.helpPluginEnabled && p instanceof Help) { HelpCommands.registerHelp(p); BetterShopLogger.Info("'Help' support enabled."); } - } + }*/ public final void checkVaultPermissions(Plugin p) { if (BSPermissions.vaultPerms == null && p instanceof Vault) { @@ -99,14 +94,6 @@ public final void checkVaultPermissions(Plugin p) { } } - public final void checkPermissions(Plugin p) { - if (BSPermissions.vaultPerms == null && - BSPermissions.permissionsPlugin == null && p instanceof Permissions) { - BSPermissions.permissionsPlugin = (Permissions) p; - BetterShopLogger.Log("Attached to Permissions."); - } - } - public final void checkSpout(Plugin p) { if (BetterShop.keyListener == null && p instanceof Spout) { @@ -143,18 +130,13 @@ public void onPluginDisable(PluginDisableEvent event) { BetterShopLogger.Info("MinecraftIM link disabled"); } else if (pName.equals("Help")) { HelpCommands.helpPluginEnabled = false; - } else if (pName.equals("Permissions")) { - if (event.getPlugin() instanceof Permissions) { - BSPermissions.permissionsPlugin = (Permissions) event.getPlugin(); - BetterShopLogger.Log("Permissions disabled."); - } } else if (pName.equals("Spout")) { BetterShop.keyListener = null; BetterShop.buttonListener = null; BetterShop.chestShop.registerSpout(false); BetterShopLogger.Log("Spout disabled."); } else { - BetterShop.economy.onPluginDisable(event); + //BetterShop.economy.onPluginDisable(event); } } } diff --git a/src/me/jascotty2/bettershop/BetterShop.java b/src/me/jascotty2/bettershop/BetterShop.java index aca6fd6..fd96edc 100644 --- a/src/me/jascotty2/bettershop/BetterShop.java +++ b/src/me/jascotty2/bettershop/BetterShop.java @@ -28,7 +28,6 @@ import me.jascotty2.bettershop.utils.BetterShopErrorTracker; import me.jascotty2.bettershop.utils.BetterShopLogger; import me.jascotty2.bettershop.commands.BSCommandManager; -import me.jascotty2.bettershop.commands.HelpCommands; import me.jascotty2.bettershop.regionshops.RegionShopManager; import me.jascotty2.bettershop.signshop.BSSignShop; import me.jascotty2.bettershop.chestshop.BSChestShop; @@ -55,7 +54,6 @@ import me.jascotty2.lib.bukkit.commands.CommandUsageException; import me.jascotty2.lib.bukkit.commands.MissingNestedCommandException; import me.jascotty2.lib.bukkit.commands.WrappedCommandException; -import me.jascotty2.lib.util.ArrayManip; import me.jascotty2.lib.util.Str; /** diff --git a/src/me/jascotty2/bettershop/chestshop/BSChestShop.java b/src/me/jascotty2/bettershop/chestshop/BSChestShop.java index 4ba8fbe..43edd9a 100644 --- a/src/me/jascotty2/bettershop/chestshop/BSChestShop.java +++ b/src/me/jascotty2/bettershop/chestshop/BSChestShop.java @@ -514,6 +514,7 @@ private class UpdateTask implements Runnable { player = p; } + @SuppressWarnings("deprecation") public void run() { playerUpdate.remove(player); player.updateInventory(); diff --git a/src/me/jascotty2/bettershop/chestshop/InventorySmallChest.java b/src/me/jascotty2/bettershop/chestshop/InventorySmallChest.java index cf24362..3b36949 100644 --- a/src/me/jascotty2/bettershop/chestshop/InventorySmallChest.java +++ b/src/me/jascotty2/bettershop/chestshop/InventorySmallChest.java @@ -133,5 +133,11 @@ public InventoryHolder getOwner() { public void setMaxStackSize(int i) { } + @Override + public void startOpen() { + // TODO Auto-generated method stub + + } + } // end class InventorySmallChest diff --git a/src/me/jascotty2/bettershop/commands/HelpCommands.java b/src/me/jascotty2/bettershop/commands/HelpCommands.java index 7dc248c..5ffa095 100644 --- a/src/me/jascotty2/bettershop/commands/HelpCommands.java +++ b/src/me/jascotty2/bettershop/commands/HelpCommands.java @@ -18,17 +18,12 @@ package me.jascotty2.bettershop.commands; -import me.jascotty2.bettershop.BSConfig; import me.jascotty2.bettershop.BSutils; -import me.jascotty2.bettershop.BetterShop; import me.jascotty2.bettershop.enums.BetterShopPermission; import me.jascotty2.bettershop.utils.BSPermissions; import me.jascotty2.lib.bukkit.commands.Command; import me.jascotty2.lib.util.Str; -//import me.taylorkelly.help.Help; -import me.taylorkelly.help.Help; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; /** * @author jacob @@ -188,7 +183,7 @@ public static boolean help(CommandSender player, String[] s) { return true; } - public static void registerHelp(Plugin p) { + /*public static void registerHelp(Plugin p) { if (!helpPluginEnabled && p != null && p instanceof Help) { Help helpPlugin = (Help)p; Plugin plugin = BetterShop.getPlugin(); @@ -259,7 +254,7 @@ public static void registerHelp(Plugin p) { "OP"); } // else Log("HelpCommands not yet found."); helpPluginEnabled = p != null; - } + }*/ } // end class HelpCommands diff --git a/src/me/jascotty2/bettershop/signshop/BSSignShop.java b/src/me/jascotty2/bettershop/signshop/BSSignShop.java index cf956cb..c229392 100644 --- a/src/me/jascotty2/bettershop/signshop/BSSignShop.java +++ b/src/me/jascotty2/bettershop/signshop/BSSignShop.java @@ -75,6 +75,7 @@ public void registerEvents() { pm.registerEvents(checkSigns, bs); } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerInteract(PlayerInteractEvent event) { if (event.isCancelled() || !BetterShop.getSettings().signShopEnabled) { diff --git a/src/me/jascotty2/bettershop/utils/BSPermissions.java b/src/me/jascotty2/bettershop/utils/BSPermissions.java index 85d9753..b0becc7 100644 --- a/src/me/jascotty2/bettershop/utils/BSPermissions.java +++ b/src/me/jascotty2/bettershop/utils/BSPermissions.java @@ -17,7 +17,6 @@ */ package me.jascotty2.bettershop.utils; -import com.nijikokun.bukkit.Permissions.Permissions; import me.jascotty2.bettershop.BSutils; import me.jascotty2.bettershop.BetterShop; import me.jascotty2.bettershop.enums.BetterShopPermission; @@ -31,7 +30,6 @@ */ public class BSPermissions { - public static Permissions permissionsPlugin = null; public static Permission vaultPerms = null; public static boolean hasPermission(CommandSender player, BetterShopPermission node) { @@ -65,8 +63,6 @@ public static boolean has(Player player, String node) { try { if (vaultPerms != null) { return vaultPerms.has(player, node); - } else if (permissionsPlugin != null) { - return permissionsPlugin.getHandler().has(player, node); } // System.out.println("no perm: checking superperm for " + player.getName() + ": " + node); // System.out.println(player.hasPermission(node)); diff --git a/src/me/jascotty2/lib/util/ArrayManip.java b/src/me/jascotty2/lib/util/ArrayManip.java index 77cc3bf..2cd940e 100644 --- a/src/me/jascotty2/lib/util/ArrayManip.java +++ b/src/me/jascotty2/lib/util/ArrayManip.java @@ -150,7 +150,6 @@ public static T[] arraySub(T arr[], int startIndex, int endIndex) { return ret; } - @SuppressWarnings("unchecked") public synchronized static int indexOf(T array[], T search) { if (array == null || array.length == 0) { return -1; diff --git a/src/plugin.yml b/src/plugin.yml index 1551db8..27abb2e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: BetterShop main: me.jascotty2.bettershop.BetterShop -version: 2.1.4 +version: 2.1.4SP website: http://github.com/BetterShop/BetterShop author: jascotty2 softdepend: [Spout, Vault]