summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-08-08 10:17:13 +0100
committerKHobbits <rob@khobbits.co.uk>2011-08-08 10:17:13 +0100
commit614b7b84f779a725fdebb64618764cab01a53844 (patch)
tree3ad5fb86c93298a31a44bc6a11dff49a5d49eed8
parenta04e0533d6492acf1196889f2db86c4305fa5da3 (diff)
downloadEssentials-614b7b84f779a725fdebb64618764cab01a53844.tar
Essentials-614b7b84f779a725fdebb64618764cab01a53844.tar.gz
Essentials-614b7b84f779a725fdebb64618764cab01a53844.tar.lz
Essentials-614b7b84f779a725fdebb64618764cab01a53844.tar.xz
Essentials-614b7b84f779a725fdebb64618764cab01a53844.zip
Adding new register methods.
-rw-r--r--Essentials/nbproject/project.properties4
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/Methods.java382
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java120
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java142
4 files changed, 524 insertions, 124 deletions
diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties
index f6fb2770f..8df8ef4d2 100644
--- a/Essentials/nbproject/project.properties
+++ b/Essentials/nbproject/project.properties
@@ -65,7 +65,9 @@ file.reference.BOSEconomy7.jar=../lib/BOSEconomy7.jar
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
file.reference.iCo4.jar=../lib/iCo4.jar
file.reference.iCo5.jar=../lib/iCo5.jar
+file.reference.iCo6.jar=../lib/iCo6.jar
file.reference.junit-4.5.jar=..\\lib\\junit_4\\junit-4.5.jar
+file.reference.MultiCurrency.jar=../lib/MultiCurrency.jar
file.reference.Permissions3.jar=../lib/Permissions3.jar
file.reference.PermissionsEx.jar=../lib/PermissionsEx.jar
includes=**
@@ -77,6 +79,8 @@ javac.classpath=\
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
${file.reference.iCo4.jar}:\
${file.reference.iCo5.jar}:\
+ ${file.reference.iCo6.jar}:\
+ ${file.reference.MultiCurrency.jar}:\
${file.reference.BOSEconomy7.jar}:\
${file.reference.PermissionsEx.jar}
# Space-separated list of extra javac options
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
index 0ebbcfb84..3dc7a2c63 100644
--- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
+++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
@@ -1,137 +1,271 @@
package com.earth2me.essentials.register.payment;
+import java.util.HashSet;
+import java.util.Set;
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.
+ * The <code>Methods</code> 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.
*
- * @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
+ * <blockquote><pre>
+ * Methods methods = new Methods();
+ * </pre></blockquote>
+ *
+ * Methods also allows you to set a preferred method of payment before it captures
+ * payment plugins in the initialization process.
+ *
+ * <blockquote><pre>
+ * Methods methods = new Methods("iConomy");
+ * </pre></blockquote>
+ *
+ * @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
- * @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
+ * @license: AOL license <http://aol.nexua.org>
*/
-public class Methods {
- private boolean self = false;
- private Method Method = null;
- private String preferred = "";
- private Set<Method> Methods = new HashSet<Method>();
- private Set<String> Dependencies = new HashSet<String>();
- private Set<Method> Attachables = new HashSet<Method>();
-
- public Methods() {
- this._init();
- }
-
- /**
- * Allows you to set which economy plugin is most preferred.
- *
- * @param preferred - preferred economy plugin
- */
- public Methods(String preferred) {
- this._init();
-
- if(this.Dependencies.contains(preferred)) {
- this.preferred = preferred;
- }
- }
-
- private void _init() {
- 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.BOSE6());
- this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7());
- }
-
- public Set<String> 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) {
- if(hasMethod()) return true;
- if(self) { self = false; return false; }
-
- int count = 0;
- boolean match = false;
- Plugin plugin;
- PluginManager manager = method.getServer().getPluginManager();
-
- 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;
-
- Method current = this.createMethod(plugin);
- if(current == null) continue;
-
- if(this.preferred.isEmpty())
- this.Method = current;
- else {
- this.Attachables.add(current);
- }
- }
-
- if(!this.preferred.isEmpty()) {
- do {
- if(hasMethod()) {
- match = true;
- } else {
- for(Method attached: this.Attachables) {
- if(attached == null) continue;
-
- if(hasMethod()) {
- match = true;
- break;
- }
-
- if(this.preferred.isEmpty()) this.Method = attached;
-
- if(count == 0) {
- if(this.preferred.equalsIgnoreCase(attached.getName()))
- this.Method = attached;
- } else {
- this.Method = attached;
- }
- }
-
- count++;
- }
- } while(!match);
- }
-
- 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 class Methods
+{
+ private boolean self = false;
+ private Method Method = null;
+ private String preferred = "";
+ private Set<Method> Methods = new HashSet<Method>();
+ private Set<String> Dependencies = new HashSet<String>();
+ private Set<Method> Attachables = new HashSet<Method>();
+
+ /**
+ * Initialize Method class
+ */
+ public Methods()
+ {
+ this._init();
+ }
+
+ /**
+ * Initializes <code>Methods</code> class utilizing a "preferred" payment method check before
+ * returning the first method that was initialized.
+ *
+ * @param preferred Payment method that is most preferred for this setup.
+ */
+ public Methods(String preferred)
+ {
+ this._init();
+
+ if (this.Dependencies.contains(preferred))
+ {
+ this.preferred = preferred;
+ }
+ }
+
+ /**
+ * Implement all methods along with their respective name & class.
+ *
+ * @see #Methods()
+ * @see #Methods(java.lang.String)
+ */
+ private void _init()
+ {
+ this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4());
+ this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5());
+ this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo6());
+ this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE6());
+ this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7());
+ this.addMethod("MultiCurrency", new com.earth2me.essentials.register.payment.methods.MCUR());
+ }
+
+ /**
+ * Returns an array of payment method names that have been loaded
+ * through the <code>_init</code> method.
+ *
+ * @return <code>Set<String></code> - Array of payment methods that are loaded.
+ * @see #setMethod(org.bukkit.plugin.Plugin)
+ */
+ public Set<String> 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 <em>or</em> Null
+ */
+ 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);
+ }
+
+ /**
+ * Verifies if Register has set a payment method for usage yet.
+ *
+ * @return <code>boolean</code>
+ * @see #setMethod(org.bukkit.plugin.Plugin)
+ * @see #checkDisabled(org.bukkit.plugin.Plugin)
+ */
+ public boolean hasMethod()
+ {
+ return (Method != null);
+ }
+
+ /**
+ * Checks Plugin Class against a multitude of checks to verify it's usability
+ * as a payment method.
+ *
+ * @param method Plugin data from bukkit, Internal Class file.
+ * @return <code>boolean</code> True on success, False on failure.
+ */
+ public boolean setMethod(Plugin method)
+ {
+ if (hasMethod())
+ {
+ return true;
+ }
+ if (self)
+ {
+ self = false;
+ return false;
+ }
+
+ int count = 0;
+ boolean match = false;
+ Plugin plugin = null;
+ PluginManager manager = method.getServer().getPluginManager();
+
+ 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;
+ }
+
+ Method current = this.createMethod(plugin);
+ if (current == null)
+ {
+ continue;
+ }
+
+ if (this.preferred.isEmpty())
+ {
+ this.Method = current;
+ }
+ else
+ {
+ this.Attachables.add(current);
+ }
+ }
+
+ if (!this.preferred.isEmpty())
+ {
+ do
+ {
+ if (hasMethod())
+ {
+ match = true;
+ }
+ else
+ {
+ for (Method attached : this.Attachables)
+ {
+ if (attached == null)
+ {
+ continue;
+ }
+
+ if (hasMethod())
+ {
+ match = true;
+ break;
+ }
+
+ if (this.preferred.isEmpty())
+ {
+ this.Method = attached;
+ }
+
+ if (count == 0)
+ {
+ if (this.preferred.equalsIgnoreCase(attached.getName()))
+ {
+ this.Method = attached;
+ }
+ }
+ else
+ {
+ this.Method = attached;
+ }
+ }
+
+ count++;
+ }
+ }
+ while (!match);
+ }
+
+ return hasMethod();
+ }
+
+ /**
+ * Grab the existing and initialized (hopefully) Method Class.
+ *
+ * @return <code>Method</code> <em>or</em> <code>Null</code>
+ */
+ public Method getMethod()
+ {
+ return Method;
+ }
+
+ /**
+ * Verify is a plugin is disabled, only does this if we there is an existing payment
+ * method initialized in Register.
+ *
+ * @param method Plugin data from bukkit, Internal Class file.
+ * @return <code>boolean</code>
+ */
+ public boolean checkDisabled(Plugin method)
+ {
+ if (!hasMethod())
+ {
+ return true;
+ }
+ if (Method.isCompatible(method))
+ {
+ Method = null;
+ }
+ return (Method == null);
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java
new file mode 100644
index 000000000..8ea709c19
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java
@@ -0,0 +1,120 @@
+package com.earth2me.essentials.register.payment.methods;
+
+import com.earth2me.essentials.register.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 <http://aol.nexua.org>
+ */
+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 String format(double amount) {
+ return amount + " Currency";
+ }
+
+ public boolean hasBanks() {
+ return false;
+ }
+
+ public boolean hasBank(String bank) {
+ return false;
+ }
+
+ public boolean hasAccount(String name) {
+ return true;
+ }
+
+ public boolean hasBankAccount(String bank, String name) {
+ return false;
+ }
+
+ public MethodAccount getAccount(String name) {
+ return new MCurrencyAccount(name);
+ }
+
+ public MethodBankAccount getBankAccount(String bank, String name) {
+ return null;
+ }
+
+ public boolean isCompatible(Plugin plugin) {
+ return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency;
+ }
+
+ public void setPlugin(Plugin plugin) {
+ currencyList = (Currency) plugin;
+ }
+
+ public class MCurrencyAccount implements MethodAccount{
+ private String name;
+
+ public MCurrencyAccount(String name) {
+ this.name = name;
+ }
+
+ public double balance() {
+ return CurrencyList.getValue((String) CurrencyList.maxCurrency(name)[0], name);
+ }
+
+ public boolean set(double amount) {
+ CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, amount);
+ return true;
+ }
+
+ public boolean add(double amount) {
+ return CurrencyList.add(name, amount);
+ }
+
+ public boolean subtract(double amount) {
+ return CurrencyList.subtract(name, amount);
+ }
+
+ public boolean multiply(double amount) {
+ return CurrencyList.multiply(name, amount);
+ }
+
+ public boolean divide(double amount) {
+ return CurrencyList.divide(name, amount);
+ }
+
+ public boolean hasEnough(double amount) {
+ return CurrencyList.hasEnough(name, amount);
+ }
+
+ public boolean hasOver(double amount) {
+ return CurrencyList.hasOver(name, amount);
+ }
+
+ public boolean hasUnder(double amount) {
+ return CurrencyList.hasUnder(name, amount);
+ }
+
+ public boolean isNegative() {
+ return CurrencyList.isNegative(name);
+ }
+
+ public boolean remove() {
+ return CurrencyList.remove(name);
+ }
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java
new file mode 100644
index 000000000..d890bc6df
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java
@@ -0,0 +1,142 @@
+package com.earth2me.essentials.register.payment.methods;
+
+import com.iCo6.iConomy;
+import com.iCo6.system.Account;
+import com.iCo6.system.Accounts;
+import com.iCo6.system.Holdings;
+
+import com.earth2me.essentials.register.payment.Method;
+
+import org.bukkit.plugin.Plugin;
+
+/**
+ * iConomy 6 Implementation of Method
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
+ * @copyright (c) 2011
+ * @license AOL license <http://aol.nexua.org>
+ */
+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 String format(double amount) {
+ return this.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 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) {
+ try { Class.forName("com.iCo6.IO"); }
+ catch(Exception e) { return false; }
+
+ 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;
+ }
+ }
+}