diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 3930cba..90213d5 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -44,7 +44,6 @@ public class playerInteract extends PlayerListener{ } Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); - if(action == buy){ player.sendMessage("You are buying!"); diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index e3c3150..d72c243 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Listeners; +import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Items.Odd; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Protection.LWCplugin; import com.Acrobot.ChestShop.Protection.LockettePlugin; import com.Acrobot.ChestShop.Protection.Security; -import com.Acrobot.ChestShop.ChestShop; import com.griefcraft.lwc.LWCPlugin; import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.register.payment.Methods; @@ -22,12 +22,15 @@ import org.yi.acru.bukkit.Lockette.Lockette; */ public class pluginEnable extends ServerListener{ - private Methods Methods = new Methods(); - public void onPluginEnable(PluginEnableEvent event){ + private Methods methods = new Methods(); - if(!this.Methods.hasMethod()){ - if(this.Methods.setMethod(event.getPlugin())){ - Economy.economy = this.Methods.getMethod(); + + public void onPluginEnable(PluginEnableEvent event){ + + //Economy plugins + if(!this.methods.hasMethod()){ + if(methods.setMethod(event.getPlugin())){ + Economy.economy = methods.getMethod(); System.out.println("[ChestShop] " + Economy.economy.getName() + " " + Economy.economy.getVersion() + " loaded."); } } diff --git a/com/nijikokun/register/payment/Method.java b/com/nijikokun/register/payment/Method.java index 5482730..a04b94d 100644 --- a/com/nijikokun/register/payment/Method.java +++ b/com/nijikokun/register/payment/Method.java @@ -2,6 +2,14 @@ package com.nijikokun.register.payment; import org.bukkit.plugin.Plugin; +/** + * Method.java + * Interface for all sub-methods for payment. + * + * @author: Nijikokun (@nijikokun) + * @copyright: Copyright (C) 2011 + * @license: GNUv3 Affero License + */ public interface Method { public Object getPlugin(); public String getName(); diff --git a/com/nijikokun/register/payment/MethodFactory.java b/com/nijikokun/register/payment/MethodFactory.java deleted file mode 100644 index 236eb9f..0000000 --- a/com/nijikokun/register/payment/MethodFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nijikokun.register.payment; - -import java.util.HashSet; -import java.util.Set; -import org.bukkit.plugin.Plugin; - -public class MethodFactory { - - private static Set Methods = new HashSet(); - private static Set Dependencies = new HashSet(); - - public static Method createMethod(Plugin plugin) { - for (Method method: Methods) { - if (method.isCompatible(plugin)) { - method.setPlugin(plugin); - return method; - } - } - - return null; - } - - public static void addMethod(String name, Method method) { - Dependencies.add(name); - Methods.add(method); - } - - public static Set getDependencies() { - return Dependencies; - } -} diff --git a/com/nijikokun/register/payment/Methods.java b/com/nijikokun/register/payment/Methods.java index f89836b..0d9efc4 100644 --- a/com/nijikokun/register/payment/Methods.java +++ b/com/nijikokun/register/payment/Methods.java @@ -3,44 +3,80 @@ package com.nijikokun.register.payment; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +import java.util.HashSet; +import java.util.Set; + +/** + * Methods.java + * Controls the getting / setting of methods & the method of payment used. + * + * @author: Nijikokun (@nijikokun) + * @copyright: Copyright (C) 2011 + * @license: GNUv3 Affero License + */ public class Methods { private Method Method = null; + private Set Methods = new HashSet(); + private Set Dependencies = new HashSet(); - public boolean setMethod(Plugin method) { - PluginManager manager = method.getServer().getPluginManager(); + public Methods() { + this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo4()); + this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo5()); + this.addMethod("BOSEconomy", new com.nijikokun.register.payment.methods.BOSE()); + this.addMethod("Essentials", new com.nijikokun.register.payment.methods.EE17()); + } - if (method != null && method.isEnabled()) { - Method plugin = MethodFactory.createMethod(method); - if (plugin != null) Method = plugin; - } else { - for(String name: MethodFactory.getDependencies()) { - if(hasMethod()) break; + public Set getDependencies() { + return Dependencies; + } - method = manager.getPlugin(name); - if(method == null) continue; - if(!method.isEnabled()) manager.enablePlugin(method); - if(!method.isEnabled()) continue; - - Method plugin = MethodFactory.createMethod(method); - if (plugin != null) Method = plugin; + public Method createMethod(Plugin plugin) { + for (Method method: Methods) { + if (method.isCompatible(plugin)) { + method.setPlugin(plugin); + return method; } } + return null; + } + + private void addMethod(String name, Method method) { + Dependencies.add(name); + Methods.add(method); + } + + public boolean hasMethod() { + return (this.Method != null); + } + + public boolean setMethod(Plugin method) { + if(hasMethod()) return true; + + PluginManager manager = method.getServer().getPluginManager(); + Plugin plugin = null; + + for(String name: this.getDependencies()) { + if(hasMethod()) break; + if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name); + if(plugin == null) continue; + if(!plugin.isEnabled()) continue; + + Method current = this.createMethod(plugin); + if (current != null) this.Method = current; + } + return hasMethod(); } + public Method getMethod() { + return Method; + } + public boolean checkDisabled(Plugin method) { if(!hasMethod()) return true; if (Method.isCompatible(method)) Method = null; return (Method == null); } - - public boolean hasMethod() { - return (Method != null); - } - - public Method getMethod() { - return Method; - } } diff --git a/com/nijikokun/register/payment/methods/BOSE.java b/com/nijikokun/register/payment/methods/BOSE.java index 2c1bd16..a392176 100644 --- a/com/nijikokun/register/payment/methods/BOSE.java +++ b/com/nijikokun/register/payment/methods/BOSE.java @@ -1,18 +1,12 @@ package com.nijikokun.register.payment.methods; import com.nijikokun.register.payment.Method; -import com.nijikokun.register.payment.MethodFactory; import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; public class BOSE implements Method { private BOSEconomy BOSEconomy; - static { - MethodFactory.addMethod("BOSEconomy", new BOSE()); - - } - public BOSEconomy getPlugin() { return this.BOSEconomy; } @@ -74,7 +68,7 @@ public class BOSE implements Method { } public double balance() { - return (double) this.BOSEconomy.getPlayerMoney(this.name); + return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name)); } public boolean set(double amount) { @@ -84,7 +78,7 @@ public class BOSE implements Method { public boolean add(double amount) { int IntAmount = (int)Math.ceil(amount); - //int balance = (int)this.balance(); + int balance = (int)this.balance(); return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false); } @@ -147,7 +141,7 @@ public class BOSE implements Method { } public double balance() { - return (double) this.BOSEconomy.getBankMoney(name); + return Double.valueOf(this.BOSEconomy.getBankMoney(name)); } public boolean set(double amount) { diff --git a/com/nijikokun/register/payment/methods/EE17.java b/com/nijikokun/register/payment/methods/EE17.java index 4dc1f65..2a7ceaf 100644 --- a/com/nijikokun/register/payment/methods/EE17.java +++ b/com/nijikokun/register/payment/methods/EE17.java @@ -4,17 +4,14 @@ import com.earth2me.essentials.Essentials; import com.earth2me.essentials.api.Economy; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; + import com.nijikokun.register.payment.Method; -import com.nijikokun.register.payment.MethodFactory; + import org.bukkit.plugin.Plugin; public class EE17 implements Method { private Essentials Essentials; - static { - MethodFactory.addMethod("Essentials", new EE17()); - } - public Essentials getPlugin() { return this.Essentials; } @@ -57,6 +54,8 @@ public class EE17 implements Method { } 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; } diff --git a/com/nijikokun/register/payment/methods/iCo4.java b/com/nijikokun/register/payment/methods/iCo4.java index 4e216bc..5b27ed1 100644 --- a/com/nijikokun/register/payment/methods/iCo4.java +++ b/com/nijikokun/register/payment/methods/iCo4.java @@ -2,17 +2,14 @@ package com.nijikokun.register.payment.methods; import com.nijiko.coelho.iConomy.iConomy; import com.nijiko.coelho.iConomy.system.Account; + import com.nijikokun.register.payment.Method; -import com.nijikokun.register.payment.MethodFactory; + import org.bukkit.plugin.Plugin; public class iCo4 implements Method { private iConomy iConomy; - static { - MethodFactory.addMethod("iConomy", new iCo4()); - } - public iConomy getPlugin() { return this.iConomy; } @@ -54,7 +51,7 @@ public class iCo4 implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy; + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; } public void setPlugin(Plugin plugin) { diff --git a/com/nijikokun/register/payment/methods/iCo5.java b/com/nijikokun/register/payment/methods/iCo5.java index b7ad0f3..a848ec5 100644 --- a/com/nijikokun/register/payment/methods/iCo5.java +++ b/com/nijikokun/register/payment/methods/iCo5.java @@ -5,17 +5,14 @@ import com.iConomy.system.Account; import com.iConomy.system.BankAccount; import com.iConomy.system.Holdings; import com.iConomy.util.Constants; + import com.nijikokun.register.payment.Method; -import com.nijikokun.register.payment.MethodFactory; + import org.bukkit.plugin.Plugin; public class iCo5 implements Method { private iConomy iConomy; - static { - MethodFactory.addMethod("iConomy", new iCo5()); - } - public iConomy getPlugin() { return this.iConomy; } @@ -37,7 +34,7 @@ public class iCo5 implements Method { } public boolean hasBank(String bank) { - return (hasBanks()) && this.iConomy.Banks.exists(bank); + return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank); } public boolean hasAccount(String name) { @@ -45,7 +42,7 @@ public class iCo5 implements Method { } public boolean hasBankAccount(String bank, String name) { - return (!hasBank(bank)) && this.iConomy.getBank(name).hasAccount(name); + return (hasBank(bank)) ? false : this.iConomy.getBank(name).hasAccount(name); } public MethodAccount getAccount(String name) { @@ -57,7 +54,7 @@ public class iCo5 implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy; + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; } public void setPlugin(Plugin plugin) {