diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Method.java b/Essentials/src/com/earth2me/essentials/register/payment/Method.java index 6d6426c36..d892ea5da 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Method.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Method.java @@ -2,6 +2,14 @@ package com.earth2me.essentials.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/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java b/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java deleted file mode 100644 index 655d392e8..000000000 --- a/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.earth2me.essentials.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/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index f93b29a6e..6bef3c6b8 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -1,20 +1,63 @@ package com.earth2me.essentials.register.payment; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +/** + * 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 Methods() { + this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4()); + this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5()); + this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE()); + } + + public Set getDependencies() { + return Dependencies; + } + + 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 (Method != null); + } public boolean setMethod(Plugin method) { PluginManager manager = method.getServer().getPluginManager(); if (method != null && method.isEnabled()) { - Method plugin = MethodFactory.createMethod(method); + Method plugin = this.createMethod(method); if (plugin != null) Method = plugin; } else { - for(String name: MethodFactory.getDependencies()) { + for(String name: this.getDependencies()) { if(hasMethod()) break; method = manager.getPlugin(name); @@ -22,7 +65,7 @@ public class Methods { if(!method.isEnabled()) manager.enablePlugin(method); if(!method.isEnabled()) continue; - Method plugin = MethodFactory.createMethod(method); + Method plugin = this.createMethod(method); if (plugin != null) Method = plugin; } } @@ -30,17 +73,13 @@ public class Methods { 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/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java index ba7b727b7..444735b65 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java @@ -1,18 +1,12 @@ package com.earth2me.essentials.register.payment.methods; import com.earth2me.essentials.register.payment.Method; -import com.earth2me.essentials.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; } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java index 5eb3ae9a9..27c71d362 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java @@ -2,17 +2,14 @@ package com.earth2me.essentials.register.payment.methods; import com.nijiko.coelho.iConomy.iConomy; import com.nijiko.coelho.iConomy.system.Account; + import com.earth2me.essentials.register.payment.Method; -import com.earth2me.essentials.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/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java index 0956e0556..5cf62cfb9 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java +++ b/Essentials/src/com/earth2me/essentials/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.earth2me.essentials.register.payment.Method; -import com.earth2me.essentials.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; } @@ -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) {