Updating register to latest build.

This commit is contained in:
KHobbits 2011-08-08 10:20:04 +01:00
parent 614b7b84f7
commit 65702ea0bf
5 changed files with 443 additions and 212 deletions

View file

@ -2,58 +2,181 @@ package com.earth2me.essentials.register.payment;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
/** /**
* Method.java * Method.java
* Interface for all sub-methods for payment.
* *
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun) * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011 * @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 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.
*
* <pre>
* if(method.getName().equalsIgnoreCase("iConomy"))
* iConomy plugin = ((iConomy)method.getPlugin());</pre>
*
* @return <code>Object</code>
* @see #getName()
* @see #getVersion()
*/ */
public interface Method {
public Object getPlugin(); public Object getPlugin();
/**
* Returns the actual name of this method.
*
* @return <code>String</code> Plugin name.
*/
public String getName(); public String getName();
/**
* Returns the actual version of this method.
*
* @return <code>String</code> Plugin version.
*/
public String getVersion(); public String getVersion();
/**
* Formats amounts into this payment methods style of currency display.
*
* @param amount Double
* @return <code>String</code> - Formatted Currency Display.
*/
public String format(double amount); public String format(double amount);
/**
* Allows the verification of bank API existence in this payment method.
*
* @return <code>boolean</code>
*/
public boolean hasBanks(); public boolean hasBanks();
/**
* Determines the existence of a bank via name.
*
* @param bank Bank name
* @return <code>boolean</code>
* @see #hasBanks
*/
public boolean hasBank(String bank); public boolean hasBank(String bank);
/**
* Determines the existence of an account via name.
*
* @param name Account name
* @return <code>boolean</code>
*/
public boolean hasAccount(String name); public boolean hasAccount(String name);
/**
* Check to see if an account <code>name</code> is tied to a <code>bank</code>.
*
* @param bank Bank name
* @param name Account name
* @return <code>boolean</code>
*/
public boolean hasBankAccount(String bank, String name); public boolean hasBankAccount(String bank, String name);
/**
* Returns a <code>MethodAccount</code> class for an account <code>name</code>.
*
* @param name Account name
* @return <code>MethodAccount</code> <em>or</em> <code>Null</code>
*/
public MethodAccount getAccount(String name); public MethodAccount getAccount(String name);
/**
* Returns a <code>MethodBankAccount</code> class for an account <code>name</code>.
*
* @param bank Bank name
* @param name Account name
* @return <code>MethodBankAccount</code> <em>or</em> <code>Null</code>
*/
public MethodBankAccount getBankAccount(String bank, String name); 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 <code>boolean</code>
*/
public boolean isCompatible(Plugin plugin); public boolean isCompatible(Plugin plugin);
/**
* Set Plugin data.
*
* @param plugin Plugin
*/
public void setPlugin(Plugin plugin); public void setPlugin(Plugin plugin);
public interface MethodAccount {
/**
* Contains Calculator and Balance functions for Accounts.
*/
public interface MethodAccount
{
public double balance(); public double balance();
public boolean set(double amount); public boolean set(double amount);
public boolean add(double amount); public boolean add(double amount);
public boolean subtract(double amount); public boolean subtract(double amount);
public boolean multiply(double amount); public boolean multiply(double amount);
public boolean divide(double amount); public boolean divide(double amount);
public boolean hasEnough(double amount); public boolean hasEnough(double amount);
public boolean hasOver(double amount); public boolean hasOver(double amount);
public boolean hasUnder(double amount); public boolean hasUnder(double amount);
public boolean isNegative(); public boolean isNegative();
public boolean remove(); public boolean remove();
@Override @Override
public String toString(); public String toString();
} }
public interface MethodBankAccount {
/**
* Contains Calculator and Balance functions for Bank Accounts.
*/
public interface MethodBankAccount
{
public double balance(); public double balance();
public String getBankName(); public String getBankName();
public int getBankId(); public int getBankId();
public boolean set(double amount); public boolean set(double amount);
public boolean add(double amount); public boolean add(double amount);
public boolean subtract(double amount); public boolean subtract(double amount);
public boolean multiply(double amount); public boolean multiply(double amount);
public boolean divide(double amount); public boolean divide(double amount);
public boolean hasEnough(double amount); public boolean hasEnough(double amount);
public boolean hasOver(double amount); public boolean hasOver(double amount);
public boolean hasUnder(double amount); public boolean hasUnder(double amount);
public boolean isNegative(); public boolean isNegative();
public boolean remove(); public boolean remove();
@Override @Override

View file

@ -4,6 +4,13 @@ import com.earth2me.essentials.register.payment.Method;
import cosine.boseconomy.BOSEconomy; import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
/**
* BOSEconomy 6 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class BOSE6 implements Method { public class BOSE6 implements Method {
private BOSEconomy BOSEconomy; private BOSEconomy BOSEconomy;
@ -69,7 +76,7 @@ public class BOSE6 implements Method {
} }
public double balance() { public double balance() {
return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name)); return (double) this.BOSEconomy.getPlayerMoney(this.name);
} }
public boolean set(double amount) { public boolean set(double amount) {
@ -122,8 +129,8 @@ public class BOSE6 implements Method {
} }
public class BOSEBankAccount implements MethodBankAccount { public class BOSEBankAccount implements MethodBankAccount {
private String bank; private final String bank;
private BOSEconomy BOSEconomy; private final BOSEconomy BOSEconomy;
public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) {
this.bank = bank; this.bank = bank;
@ -139,7 +146,7 @@ public class BOSE6 implements Method {
} }
public double balance() { public double balance() {
return Double.valueOf(this.BOSEconomy.getBankMoney(bank)); return (double) this.BOSEconomy.getBankMoney(bank);
} }
public boolean set(double amount) { public boolean set(double amount) {

View file

@ -5,7 +5,12 @@ import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
/** /**
* BOSEconomy 7 Implementation of Method
*
* @author Acrobot * @author Acrobot
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/ */
public class BOSE7 implements Method { public class BOSE7 implements Method {

View file

@ -7,6 +7,13 @@ import com.earth2me.essentials.register.payment.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
/**
* iConomy 4 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class iCo4 implements Method { public class iCo4 implements Method {
private iConomy iConomy; private iConomy iConomy;
@ -51,7 +58,7 @@ public class iCo4 implements Method {
} }
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") && plugin instanceof iConomy;
} }
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin) {

View file

@ -10,200 +10,289 @@ import com.earth2me.essentials.register.payment.Method;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class iCo5 implements Method {
/**
* iConomy 5 Implementation of Method
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright (c) 2011
* @license AOL license <http://aol.nexua.org>
*/
public class iCo5 implements Method
{
private iConomy iConomy; private iConomy iConomy;
public iConomy getPlugin() { public iConomy getPlugin()
{
return this.iConomy; return this.iConomy;
} }
public String getName() { public String getName()
{
return "iConomy"; return "iConomy";
} }
public String getVersion() { public String getVersion()
{
return "5"; return "5";
} }
public String format(double amount) { public String format(double amount)
{
return this.iConomy.format(amount); return this.iConomy.format(amount);
} }
public boolean hasBanks() { public boolean hasBanks()
{
return Constants.Banking; return Constants.Banking;
} }
public boolean hasBank(String bank) { public boolean hasBank(String bank)
return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank); {
return (hasBanks()) && this.iConomy.Banks.exists(bank);
} }
public boolean hasAccount(String name) { public boolean hasAccount(String name)
{
return this.iConomy.hasAccount(name); return this.iConomy.hasAccount(name);
} }
public boolean hasBankAccount(String bank, String name) { public boolean hasBankAccount(String bank, String name)
return (!hasBank(bank)) ? false : this.iConomy.getBank(bank).hasAccount(name); {
return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name);
} }
public MethodAccount getAccount(String name) { public MethodAccount getAccount(String name)
{
return new iCoAccount(this.iConomy.getAccount(name)); return new iCoAccount(this.iConomy.getAccount(name));
} }
public MethodBankAccount getBankAccount(String bank, String name) { public MethodBankAccount getBankAccount(String bank, String name)
{
return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name)); return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name));
} }
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin)
{
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.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) { public void setPlugin(Plugin plugin)
{
iConomy = (iConomy)plugin; iConomy = (iConomy)plugin;
} }
public class iCoAccount implements MethodAccount {
public class iCoAccount implements MethodAccount
{
private Account account; private Account account;
private Holdings holdings; private Holdings holdings;
public iCoAccount(Account account) { public iCoAccount(Account account)
{
this.account = account; this.account = account;
this.holdings = account.getHoldings(); this.holdings = account.getHoldings();
} }
public Account getiCoAccount() { public Account getiCoAccount()
{
return account; return account;
} }
public double balance() { public double balance()
{
return this.holdings.balance(); return this.holdings.balance();
} }
public boolean set(double amount) { public boolean set(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.set(amount); this.holdings.set(amount);
return true; return true;
} }
public boolean add(double amount) { public boolean add(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.add(amount); this.holdings.add(amount);
return true; return true;
} }
public boolean subtract(double amount) { public boolean subtract(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.subtract(amount); this.holdings.subtract(amount);
return true; return true;
} }
public boolean multiply(double amount) { public boolean multiply(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.multiply(amount); this.holdings.multiply(amount);
return true; return true;
} }
public boolean divide(double amount) { public boolean divide(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.divide(amount); this.holdings.divide(amount);
return true; return true;
} }
public boolean hasEnough(double amount) { public boolean hasEnough(double amount)
{
return this.holdings.hasEnough(amount); return this.holdings.hasEnough(amount);
} }
public boolean hasOver(double amount) { public boolean hasOver(double amount)
{
return this.holdings.hasOver(amount); return this.holdings.hasOver(amount);
} }
public boolean hasUnder(double amount) { public boolean hasUnder(double amount)
{
return this.holdings.hasUnder(amount); return this.holdings.hasUnder(amount);
} }
public boolean isNegative() { public boolean isNegative()
{
return this.holdings.isNegative(); return this.holdings.isNegative();
} }
public boolean remove() { public boolean remove()
if(this.account == null) return false; {
if (this.account == null)
{
return false;
}
this.account.remove(); this.account.remove();
return true; return true;
} }
} }
public class iCoBankAccount implements MethodBankAccount {
public class iCoBankAccount implements MethodBankAccount
{
private BankAccount account; private BankAccount account;
private Holdings holdings; private Holdings holdings;
public iCoBankAccount(BankAccount account) { public iCoBankAccount(BankAccount account)
{
this.account = account; this.account = account;
this.holdings = account.getHoldings(); this.holdings = account.getHoldings();
} }
public BankAccount getiCoBankAccount() { public BankAccount getiCoBankAccount()
{
return account; return account;
} }
public String getBankName() { public String getBankName()
{
return this.account.getBankName(); return this.account.getBankName();
} }
public int getBankId() { public int getBankId()
{
return this.account.getBankId(); return this.account.getBankId();
} }
public double balance() { public double balance()
{
return this.holdings.balance(); return this.holdings.balance();
} }
public boolean set(double amount) { public boolean set(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.set(amount); this.holdings.set(amount);
return true; return true;
} }
public boolean add(double amount) { public boolean add(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.add(amount); this.holdings.add(amount);
return true; return true;
} }
public boolean subtract(double amount) { public boolean subtract(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.subtract(amount); this.holdings.subtract(amount);
return true; return true;
} }
public boolean multiply(double amount) { public boolean multiply(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.multiply(amount); this.holdings.multiply(amount);
return true; return true;
} }
public boolean divide(double amount) { public boolean divide(double amount)
if(this.holdings == null) return false; {
if (this.holdings == null)
{
return false;
}
this.holdings.divide(amount); this.holdings.divide(amount);
return true; return true;
} }
public boolean hasEnough(double amount) { public boolean hasEnough(double amount)
{
return this.holdings.hasEnough(amount); return this.holdings.hasEnough(amount);
} }
public boolean hasOver(double amount) { public boolean hasOver(double amount)
{
return this.holdings.hasOver(amount); return this.holdings.hasOver(amount);
} }
public boolean hasUnder(double amount) { public boolean hasUnder(double amount)
{
return this.holdings.hasUnder(amount); return this.holdings.hasUnder(amount);
} }
public boolean isNegative() { public boolean isNegative()
{
return this.holdings.isNegative(); return this.holdings.isNegative();
} }
public boolean remove() { public boolean remove()
if(this.account == null) return false; {
if (this.account == null)
{
return false;
}
this.account.remove(); this.account.remove();
return true; return true;
} }