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,265 +8,321 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import com.earth2me.essentials.register.payment.Method; import com.earth2me.essentials.register.payment.Method;
public class VaultEco implements Method {
private Vault vault; public class VaultEco implements Method
private Economy economy; {
private Vault vault;
private Economy economy;
@Override @Override
public Vault getPlugin() { public Vault getPlugin()
return this.vault; {
} 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 @Override
public String getVersion() { public boolean createAccount(String name, Double amount)
return this.vault.getDescription().getVersion(); {
} if (hasAccount(name))
{
return false;
}
return false;
}
@Override @Override
public int fractionalDigits() { public String getName()
return 0; {
}
return this.vault.getDescription().getName().concat(" - Economy: ").concat(economy == null ? "NoEco" : economy.getName());
}
@Override @Override
public String format(double amount) { public String getVersion()
return this.economy.format(amount); {
} return this.vault.getDescription().getVersion();
}
@Override @Override
public boolean hasBanks() { public int fractionalDigits()
return this.economy.hasBankSupport(); {
} return 0;
}
@Override @Override
public boolean hasBank(String bank) { public String format(double amount)
return this.economy.getBanks().contains(bank); {
} return this.economy.format(amount);
}
@Override @Override
public boolean hasAccount(String name) { public boolean hasBanks()
return this.economy.hasAccount(name); {
} return this.economy.hasBankSupport();
}
@Override @Override
public boolean hasBankAccount(String bank, String name) { public boolean hasBank(String bank)
return this.economy.isBankOwner(bank, name).transactionSuccess() {
|| this.economy.isBankMember(bank, name).transactionSuccess(); return this.economy.getBanks().contains(bank);
} }
@Override @Override
public boolean createAccount(String name) { public boolean hasAccount(String name)
return this.economy.createBank(name, "").transactionSuccess(); {
} return this.economy.hasAccount(name);
}
public boolean createAccount(String name, double balance) {
if(!this.economy.createBank(name, "").transactionSuccess()) {
return false;
}
return this.economy.bankDeposit(name, balance).transactionSuccess();
}
@Override @Override
public MethodAccount getAccount(String name) { public boolean hasBankAccount(String bank, String name)
if(!hasAccount(name)) {
return null; return this.economy.isBankOwner(bank, name).transactionSuccess()
|| this.economy.isBankMember(bank, name).transactionSuccess();
return new VaultAccount(name, this.economy); }
}
@Override @Override
public MethodBankAccount getBankAccount(String bank, String name) { public boolean createAccount(String name)
if(!hasBankAccount(bank, name)) {
return null; return this.economy.createBank(name, "").transactionSuccess();
}
return new VaultBankAccount(bank, economy); public boolean createAccount(String name, double balance)
} {
if (!this.economy.createBank(name, "").transactionSuccess())
{
return false;
}
return this.economy.bankDeposit(name, balance).transactionSuccess();
}
@Override @Override
public boolean isCompatible(Plugin plugin) { public MethodAccount getAccount(String name)
RegisteredServiceProvider<Economy> ecoPlugin = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); {
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"); 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; {
RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); this.vault = (Vault)plugin;
if (economyProvider != null) { RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
this.economy = economyProvider.getProvider(); 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) { public class VaultAccount implements MethodAccount
this.name = name; {
this.economy = economy; private final String name;
} private final Economy economy;
public VaultAccount(String name, Economy economy)
{
this.name = name;
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()) { {
return false; if (!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess())
} {
if(amount == 0) { return false;
return true; }
} if (amount == 0)
return this.economy.depositPlayer(this.name, amount).transactionSuccess(); {
} return true;
}
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(); {
return this.set(balance * amount); double balance = this.balance();
} return this.set(balance * amount);
}
@Override @Override
public boolean divide(double amount) { public boolean divide(double amount)
double balance = this.balance(); {
return this.set(balance / amount); double balance = this.balance();
} 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 {
private final String bank; public class VaultBankAccount implements MethodBankAccount
private final Economy economy; {
private final String bank;
private final Economy economy;
public VaultBankAccount(String bank, Economy economy) { public VaultBankAccount(String bank, Economy economy)
this.bank = bank; {
this.economy = economy; this.bank = bank;
} 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()) { {
return false; if (!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess())
} {
if(amount == 0) { return false;
return true; }
} if (amount == 0)
return this.economy.bankDeposit(this.bank, amount).transactionSuccess(); {
} return true;
}
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(); {
return this.set(balance * amount); double balance = this.balance();
} return this.set(balance * amount);
}
@Override @Override
public boolean divide(double amount) { public boolean divide(double amount)
double balance = this.balance(); {
return this.set(balance / amount); double balance = this.balance();
} 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);
}
} }
} }