summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Essentials/nbproject/pmd.settings1
-rw-r--r--Essentials/nbproject/project.properties4
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/Methods.java53
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java272
-rw-r--r--lib/Vault.jarbin0 -> 180183 bytes
5 files changed, 306 insertions, 24 deletions
diff --git a/Essentials/nbproject/pmd.settings b/Essentials/nbproject/pmd.settings
index 29baf7ea1..cea9eaa13 100644
--- a/Essentials/nbproject/pmd.settings
+++ b/Essentials/nbproject/pmd.settings
@@ -1,3 +1,4 @@
DoNotUseThreads
LongVariable
SignatureDeclareThrowsException
+LocalVariableCouldBeFinal
diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties
index 87e522254..0c8b44650 100644
--- a/Essentials/nbproject/project.properties
+++ b/Essentials/nbproject/project.properties
@@ -76,6 +76,7 @@ file.reference.MultiCurrency.jar=../lib/MultiCurrency.jar
file.reference.Permissions3.jar=../lib/Permissions3.jar
file.reference.PermissionsBukkit-1.2.jar=../lib/PermissionsBukkit-1.2.jar
file.reference.PermissionsEx.jar=../lib/PermissionsEx.jar
+file.reference.Vault.jar=../lib/Vault.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=true
@@ -93,7 +94,8 @@ javac.classpath=\
${file.reference.lombok-0.10.1.jar}:\
${reference.EssentialsGroupManager.jar}:\
${file.reference.bukkit.jar}:\
- ${file.reference.craftbukkit.jar}
+ ${file.reference.craftbukkit.jar}:\
+ ${file.reference.Vault.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
index 32acc0442..f8729923e 100644
--- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
+++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
@@ -7,23 +7,23 @@ import org.bukkit.plugin.PluginManager;
/**
- * The <code>Methods</code> initializes Methods that utilize the Method interface
- * based on a "first come, first served" basis.
+ * 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.
*
- * Methods also allows you to set a preferred method of payment before it captures
- * payment plugins in the initialization process.
+ * Methods also allows you to set a preferred method of payment before it captures payment plugins in the initialization
+ * process.
*
- * in <code>bukkit.yml</code>:
- * <blockquote><pre>
+ * in
+ * <code>bukkit.yml</code>: <blockquote><pre>
* economy:
* preferred: "iConomy"
* </pre></blockquote>
*
- * @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun)
- * @copyright: Copyright (C) 2011
- * @license: AOL license <http://aol.nexua.org>
+ * @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license
+ * <http://aol.nexua.org>
*/
public class Methods
{
@@ -52,6 +52,7 @@ public class Methods
addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7());
addMethod("Currency", new com.earth2me.essentials.register.payment.methods.MCUR());
Dependencies.add("MultiCurrency");
+ addMethod("Vault", new com.earth2me.essentials.register.payment.methods.VaultEco());
}
/**
@@ -78,6 +79,7 @@ public class Methods
/**
* Use to get version of Register plugin
+ *
* @return version
*/
public static String getVersion()
@@ -86,10 +88,11 @@ public class Methods
}
/**
- * Returns an array of payment method names that have been loaded
- * through the <code>_init</code> method.
+ * 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.
+ * @return
+ * <code>Set<String></code> - Array of payment methods that are loaded.
* @see #setMethod(org.bukkit.plugin.Plugin)
*/
public static Set<String> getDependencies()
@@ -98,8 +101,8 @@ public class Methods
}
/**
- * Interprets Plugin class data to verify whether it is compatible with an existing payment
- * method to use for payments and other various economic activity.
+ * 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
@@ -127,7 +130,8 @@ public class Methods
/**
* Verifies if Register has set a payment method for usage yet.
*
- * @return <code>boolean</code>
+ * @return
+ * <code>boolean</code>
* @see #setMethod(org.bukkit.plugin.Plugin)
* @see #checkDisabled(org.bukkit.plugin.Plugin)
*/
@@ -137,11 +141,11 @@ public class Methods
}
/**
- * Checks Plugin Class against a multitude of checks to verify it's usability
- * as a payment method.
+ * Checks Plugin Class against a multitude of checks to verify it's usability as a payment method.
*
* @param <code>PluginManager</code> the plugin manager for the server
- * @return <code>boolean</code> True on success, False on failure.
+ * @return
+ * <code>boolean</code> True on success, False on failure.
*/
public static boolean setMethod(PluginManager manager)
{
@@ -242,7 +246,8 @@ public class Methods
/**
* Sets the preferred economy
*
- * @return <code>boolean</code>
+ * @return
+ * <code>boolean</code>
*/
public static boolean setPreferred(String check)
{
@@ -258,7 +263,9 @@ public class Methods
/**
* Grab the existing and initialized (hopefully) Method Class.
*
- * @return <code>Method</code> <em>or</em> <code>Null</code>
+ * @return
+ * <code>Method</code> <em>or</em>
+ * <code>Null</code>
*/
public static Method getMethod()
{
@@ -266,11 +273,11 @@ public class Methods
}
/**
- * Verify is a plugin is disabled, only does this if we there is an existing payment
- * method initialized in Register.
+ * 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>
+ * @return
+ * <code>boolean</code>
*/
public static boolean checkDisabled(Plugin method)
{
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java
new file mode 100644
index 000000000..64160891c
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java
@@ -0,0 +1,272 @@
+package com.earth2me.essentials.register.payment.methods;
+
+import net.milkbowl.vault.Vault;
+import net.milkbowl.vault.economy.Economy;
+
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+import com.earth2me.essentials.register.payment.Method;
+
+public class VaultEco implements Method {
+
+ private Vault vault;
+ private Economy economy;
+
+ @Override
+ public Vault getPlugin() {
+ return this.vault;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double amount) {
+ if (hasAccount(name)) {
+ return false;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String getName() {
+
+ return this.vault.getDescription().getName().concat(" - Economy: ").concat(economy == null ? "NoEco" : economy.getName());
+ }
+
+ @Override
+ public String getVersion() {
+ return this.vault.getDescription().getVersion();
+ }
+
+ @Override
+ public int fractionalDigits() {
+ return 0;
+ }
+
+ @Override
+ public String format(double amount) {
+ return this.economy.format(amount);
+ }
+
+ @Override
+ public boolean hasBanks() {
+ return this.economy.hasBankSupport();
+ }
+
+ @Override
+ public boolean hasBank(String bank) {
+ return this.economy.getBanks().contains(bank);
+ }
+
+ @Override
+ public boolean hasAccount(String name) {
+ return this.economy.hasAccount(name);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name) {
+ return this.economy.isBankOwner(bank, name).transactionSuccess()
+ || this.economy.isBankMember(bank, name).transactionSuccess();
+ }
+
+ @Override
+ public boolean createAccount(String name) {
+ return this.economy.createBank(name, "").transactionSuccess();
+ }
+
+ public boolean createAccount(String name, double balance) {
+ if(!this.economy.createBank(name, "").transactionSuccess()) {
+ return false;
+ }
+ return this.economy.bankDeposit(name, balance).transactionSuccess();
+ }
+
+ @Override
+ public MethodAccount getAccount(String name) {
+ if(!hasAccount(name))
+ return null;
+
+ return new VaultAccount(name, this.economy);
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name) {
+ if(!hasBankAccount(bank, name))
+ return null;
+
+ return new VaultBankAccount(bank, economy);
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin) {
+ RegisteredServiceProvider<Economy> ecoPlugin = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
+ return plugin instanceof Vault && ecoPlugin != null && !ecoPlugin.getProvider().getName().equals("Essentials Economy");
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin) {
+ this.vault = (Vault) plugin;
+ RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
+ if (economyProvider != null) {
+ this.economy = economyProvider.getProvider();
+ }
+ }
+
+ public class VaultAccount implements MethodAccount {
+ private final String name;
+ private final Economy economy;
+
+ public VaultAccount(String name, Economy economy) {
+ this.name = name;
+ this.economy = economy;
+ }
+
+ @Override
+ public double balance() {
+ return this.economy.getBalance(this.name);
+ }
+
+ @Override
+ public boolean set(double amount) {
+ if(!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess()) {
+ return false;
+ }
+ if(amount == 0) {
+ return true;
+ }
+ return this.economy.depositPlayer(this.name, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean add(double amount) {
+ return this.economy.depositPlayer(this.name, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean subtract(double amount) {
+ return this.economy.withdrawPlayer(this.name, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean multiply(double amount) {
+ double balance = this.balance();
+ return this.set(balance * amount);
+ }
+
+ @Override
+ public boolean divide(double amount) {
+ double balance = this.balance();
+ return this.set(balance / amount);
+ }
+
+ @Override
+ public boolean hasEnough(double amount) {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount) {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount) {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative() {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove() {
+ return this.set(0.0);
+ }
+ }
+
+ public class VaultBankAccount implements MethodBankAccount {
+
+ private final String bank;
+ private final Economy economy;
+
+ public VaultBankAccount(String bank, Economy economy) {
+ this.bank = bank;
+ this.economy = economy;
+ }
+
+ @Override
+ public String getBankName() {
+ return this.bank;
+ }
+
+ @Override
+ public int getBankId() {
+ return -1;
+ }
+
+ @Override
+ public double balance() {
+ return this.economy.bankBalance(this.bank).balance;
+ }
+
+ @Override
+ public boolean set(double amount) {
+ if(!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess()) {
+ return false;
+ }
+ if(amount == 0) {
+ return true;
+ }
+ return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean add(double amount) {
+ return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean subtract(double amount) {
+ return this.economy.bankWithdraw(this.bank, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean multiply(double amount) {
+ double balance = this.balance();
+ return this.set(balance * amount);
+ }
+
+ @Override
+ public boolean divide(double amount) {
+ double balance = this.balance();
+ return this.set(balance / amount);
+ }
+
+ @Override
+ public boolean hasEnough(double amount) {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount) {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount) {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative() {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove() {
+ return this.set(0.0);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/lib/Vault.jar b/lib/Vault.jar
new file mode 100644
index 000000000..96b1625c4
--- /dev/null
+++ b/lib/Vault.jar
Binary files differ