This commit is contained in:
snowleo 2012-01-16 19:11:41 +01:00
parent 149ce7d74d
commit cd2f819c29
2 changed files with 235 additions and 180 deletions

View File

@ -1,4 +1,3 @@
DoNotUseThreads DoNotUseThreads
LongVariable LongVariable
SignatureDeclareThrowsException SignatureDeclareThrowsException
LocalVariableCouldBeFinal

View File

@ -8,19 +8,23 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import com.earth2me.essentials.register.payment.Method; import com.earth2me.essentials.register.payment.Method;
public class VaultEco implements Method {
public class VaultEco implements Method
{
private Vault vault; private Vault vault;
private Economy economy; private Economy economy;
@Override @Override
public Vault getPlugin() { public Vault getPlugin()
{
return this.vault; return this.vault;
} }
@Override @Override
public boolean createAccount(String name, Double amount) { public boolean createAccount(String name, Double amount)
if (hasAccount(name)) { {
if (hasAccount(name))
{
return false; return false;
} }
@ -28,245 +32,297 @@ public class VaultEco implements Method {
} }
@Override @Override
public String getName() { public String getName()
{
return this.vault.getDescription().getName().concat(" - Economy: ").concat(economy == null ? "NoEco" : economy.getName()); return this.vault.getDescription().getName().concat(" - Economy: ").concat(economy == null ? "NoEco" : economy.getName());
} }
@Override @Override
public String getVersion() { public String getVersion()
{
return this.vault.getDescription().getVersion(); return this.vault.getDescription().getVersion();
} }
@Override @Override
public int fractionalDigits() { public int fractionalDigits()
{
return 0; return 0;
} }
@Override @Override
public String format(double amount) { public String format(double amount)
{
return this.economy.format(amount); return this.economy.format(amount);
} }
@Override @Override
public boolean hasBanks() { public boolean hasBanks()
{
return this.economy.hasBankSupport(); return this.economy.hasBankSupport();
} }
@Override @Override
public boolean hasBank(String bank) { public boolean hasBank(String bank)
{
return this.economy.getBanks().contains(bank); return this.economy.getBanks().contains(bank);
} }
@Override @Override
public boolean hasAccount(String name) { public boolean hasAccount(String name)
{
return this.economy.hasAccount(name); return this.economy.hasAccount(name);
} }
@Override @Override
public boolean hasBankAccount(String bank, String name) { public boolean hasBankAccount(String bank, String name)
{
return this.economy.isBankOwner(bank, name).transactionSuccess() return this.economy.isBankOwner(bank, name).transactionSuccess()
|| this.economy.isBankMember(bank, name).transactionSuccess(); || this.economy.isBankMember(bank, name).transactionSuccess();
} }
@Override @Override
public boolean createAccount(String name) { public boolean createAccount(String name)
{
return this.economy.createBank(name, "").transactionSuccess(); return this.economy.createBank(name, "").transactionSuccess();
} }
public boolean createAccount(String name, double balance) { public boolean createAccount(String name, double balance)
if(!this.economy.createBank(name, "").transactionSuccess()) { {
if (!this.economy.createBank(name, "").transactionSuccess())
{
return false; return false;
} }
return this.economy.bankDeposit(name, balance).transactionSuccess(); return this.economy.bankDeposit(name, balance).transactionSuccess();
} }
@Override @Override
public MethodAccount getAccount(String name) { public MethodAccount getAccount(String name)
{
if (!hasAccount(name)) if (!hasAccount(name))
{
return null; return null;
}
return new VaultAccount(name, this.economy); return new VaultAccount(name, this.economy);
} }
@Override @Override
public MethodBankAccount getBankAccount(String bank, String name) { public MethodBankAccount getBankAccount(String bank, String name)
{
if (!hasBankAccount(bank, name)) if (!hasBankAccount(bank, name))
{
return null; return null;
}
return new VaultBankAccount(bank, economy); return new VaultBankAccount(bank, economy);
} }
@Override @Override
public boolean isCompatible(Plugin plugin) { public boolean isCompatible(Plugin plugin)
{
RegisteredServiceProvider<Economy> ecoPlugin = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); 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"); return plugin instanceof Vault && ecoPlugin != null && !ecoPlugin.getProvider().getName().equals("Essentials Economy");
} }
@Override @Override
public void setPlugin(Plugin plugin) { public void setPlugin(Plugin plugin)
{
this.vault = (Vault)plugin; this.vault = (Vault)plugin;
RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) { if (economyProvider != null)
{
this.economy = economyProvider.getProvider(); this.economy = economyProvider.getProvider();
} }
} }
public class VaultAccount implements MethodAccount {
public class VaultAccount implements MethodAccount
{
private final String name; private final String name;
private final Economy economy; private final Economy economy;
public VaultAccount(String name, Economy economy) { public VaultAccount(String name, Economy economy)
{
this.name = name; this.name = name;
this.economy = economy; this.economy = economy;
} }
@Override @Override
public double balance() { public double balance()
{
return this.economy.getBalance(this.name); return this.economy.getBalance(this.name);
} }
@Override @Override
public boolean set(double amount) { public boolean set(double amount)
if(!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess()) { {
if (!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess())
{
return false; return false;
} }
if(amount == 0) { if (amount == 0)
{
return true; return true;
} }
return this.economy.depositPlayer(this.name, amount).transactionSuccess(); return this.economy.depositPlayer(this.name, amount).transactionSuccess();
} }
@Override @Override
public boolean add(double amount) { public boolean add(double amount)
{
return this.economy.depositPlayer(this.name, amount).transactionSuccess(); return this.economy.depositPlayer(this.name, amount).transactionSuccess();
} }
@Override @Override
public boolean subtract(double amount) { public boolean subtract(double amount)
{
return this.economy.withdrawPlayer(this.name, amount).transactionSuccess(); return this.economy.withdrawPlayer(this.name, amount).transactionSuccess();
} }
@Override @Override
public boolean multiply(double amount) { public boolean multiply(double amount)
{
double balance = this.balance(); double balance = this.balance();
return this.set(balance * amount); return this.set(balance * amount);
} }
@Override @Override
public boolean divide(double amount) { public boolean divide(double amount)
{
double balance = this.balance(); double balance = this.balance();
return this.set(balance / amount); return this.set(balance / amount);
} }
@Override @Override
public boolean hasEnough(double amount) { public boolean hasEnough(double amount)
{
return (this.balance() >= amount); return (this.balance() >= amount);
} }
@Override @Override
public boolean hasOver(double amount) { public boolean hasOver(double amount)
{
return (this.balance() > amount); return (this.balance() > amount);
} }
@Override @Override
public boolean hasUnder(double amount) { public boolean hasUnder(double amount)
{
return (this.balance() < amount); return (this.balance() < amount);
} }
@Override @Override
public boolean isNegative() { public boolean isNegative()
{
return (this.balance() < 0); return (this.balance() < 0);
} }
@Override @Override
public boolean remove() { public boolean remove()
{
return this.set(0.0); return this.set(0.0);
} }
} }
public class VaultBankAccount implements MethodBankAccount {
public class VaultBankAccount implements MethodBankAccount
{
private final String bank; private final String bank;
private final Economy economy; private final Economy economy;
public VaultBankAccount(String bank, Economy economy) { public VaultBankAccount(String bank, Economy economy)
{
this.bank = bank; this.bank = bank;
this.economy = economy; this.economy = economy;
} }
@Override @Override
public String getBankName() { public String getBankName()
{
return this.bank; return this.bank;
} }
@Override @Override
public int getBankId() { public int getBankId()
{
return -1; return -1;
} }
@Override @Override
public double balance() { public double balance()
{
return this.economy.bankBalance(this.bank).balance; return this.economy.bankBalance(this.bank).balance;
} }
@Override @Override
public boolean set(double amount) { public boolean set(double amount)
if(!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess()) { {
if (!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess())
{
return false; return false;
} }
if(amount == 0) { if (amount == 0)
{
return true; return true;
} }
return this.economy.bankDeposit(this.bank, amount).transactionSuccess(); return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
} }
@Override @Override
public boolean add(double amount) { public boolean add(double amount)
{
return this.economy.bankDeposit(this.bank, amount).transactionSuccess(); return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
} }
@Override @Override
public boolean subtract(double amount) { public boolean subtract(double amount)
{
return this.economy.bankWithdraw(this.bank, amount).transactionSuccess(); return this.economy.bankWithdraw(this.bank, amount).transactionSuccess();
} }
@Override @Override
public boolean multiply(double amount) { public boolean multiply(double amount)
{
double balance = this.balance(); double balance = this.balance();
return this.set(balance * amount); return this.set(balance * amount);
} }
@Override @Override
public boolean divide(double amount) { public boolean divide(double amount)
{
double balance = this.balance(); double balance = this.balance();
return this.set(balance / amount); return this.set(balance / amount);
} }
@Override @Override
public boolean hasEnough(double amount) { public boolean hasEnough(double amount)
{
return (this.balance() >= amount); return (this.balance() >= amount);
} }
@Override @Override
public boolean hasOver(double amount) { public boolean hasOver(double amount)
{
return (this.balance() > amount); return (this.balance() > amount);
} }
@Override @Override
public boolean hasUnder(double amount) { public boolean hasUnder(double amount)
{
return (this.balance() < amount); return (this.balance() < amount);
} }
@Override @Override
public boolean isNegative() { public boolean isNegative()
{
return (this.balance() < 0); return (this.balance() < 0);
} }
@Override @Override
public boolean remove() { public boolean remove()
{
return this.set(0.0); return this.set(0.0);
} }
} }
} }