added javadoc & missing negative fund checks to some economy

implementations.
This commit is contained in:
Sleaker 2012-06-06 06:20:04 -07:00
parent db7360a877
commit 7b4b9e4e5d
8 changed files with 83 additions and 16 deletions

View File

@ -110,11 +110,7 @@ Github and we'll get to it at our convenience.
## Implementing Vault
Implementing Vault is quite simple through obtaining an instance through the
Bukkit PluginManager class by using the string "Vault". An example plugin with
limited functionality is located within the VaultExamplePlugin repository
(https://github.com/MilkBowl/VaultExamplePlugin).
Example:
Bukkit PluginManager class by using the string "Vault". See the example below:
```java
package com.example.plugin;
@ -190,7 +186,7 @@ public class ExamplePlugin extends JavaPlugin {
if(command.getLabel().equals("test-economy")) {
// Lets give the player 1.05 currency (note that SOME economic plugins require rounding!
sender.sendMessage(String.format("You have %s", vault.getEconomy().format(vault.getEconomy().getBalance(player.getName()).amount)));
sender.sendMessage(String.format("You have %s", econ.format(econ.getBalance(player.getName()).amount)));
EconomyResponse r = econ.depositPlayer(player.getName(), 1.05);
if(r.transactionSuccess()) {
sender.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance)));

View File

@ -86,14 +86,17 @@ public interface Economy {
public double getBalance(String playerName);
/**
* Checks if the player account has the amount
* Checks if the player account has the amount - DO NOT USE NEGATIVE AMOUNTS
*
* @param playerName
* @param amount
* @return
*/
public boolean has(String playerName, double amount);
/**
* Withdraw an amount from a player
* Withdraw an amount from a player - DO NOT USE NEGATIVE AMOUNTS
*
* @param playerName Name of player
* @param amount Amount to withdraw
* @return Detailed response of transaction
@ -101,7 +104,8 @@ public interface Economy {
public EconomyResponse withdrawPlayer(String playerName, double amount);
/**
* Deposit an amount to a player
* Deposit an amount to a player - DO NOT USE NEGATIVE AMOUNTS
*
* @param playerName Name of player
* @param amount Amount to deposit
* @return Detailed response of transaction
@ -131,7 +135,8 @@ public interface Economy {
public EconomyResponse bankBalance(String name);
/**
* Returns true or false whether the bank has the amount specified
* Returns true or false whether the bank has the amount specified - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return
@ -139,7 +144,8 @@ public interface Economy {
public EconomyResponse bankHas(String name, double amount);
/**
* Withdraw an amount from a bank account
* Withdraw an amount from a bank account - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return
@ -147,7 +153,8 @@ public interface Economy {
public EconomyResponse bankWithdraw(String name, double amount);
/**
* Deposit an amount into a bank account
* Deposit an amount into a bank account - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return

View File

@ -113,7 +113,7 @@ public class Economy_Craftconomy implements Economy {
public String currencyNameSingular() {
return CurrencyHandler.getCurrency(Config.currencyDefault, true).getName();
}
@Override
public String currencyNamePlural() {
return CurrencyHandler.getCurrency(Config.currencyDefault, true).getNamePlural();
@ -130,6 +130,10 @@ public class Economy_Craftconomy implements Economy {
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Cannot withdraw negative funds");
}
double balance;
Account account = AccountHandler.getAccount(playerName);
if (account.hasEnough(amount)) {
@ -142,6 +146,10 @@ public class Economy_Craftconomy implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Cannot desposit negative funds");
}
Account account = AccountHandler.getAccount(playerName);
account.addMoney(amount);
return new EconomyResponse(amount, account.getDefaultBalance(), ResponseType.SUCCESS, null);
@ -188,6 +196,10 @@ public class Economy_Craftconomy implements Economy {
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
EconomyResponse er = bankHas(name, amount);
if (!er.transactionSuccess())
return er;
@ -206,6 +218,10 @@ public class Economy_Craftconomy implements Economy {
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
if (BankHandler.exists(name))
{
Bank bank = BankHandler.getBank(name);

View File

@ -98,12 +98,12 @@ public class Economy_CurrencyCore implements Economy {
public String format(double amount) {
return this.currency.getFormatHelper().format(amount);
}
@Override
public String currencyNamePlural() {
return currency.getCurrencyConfig().getCurrencyMajor().get(1);
}
@Override
public String currencyNameSingular() {
return currency.getCurrencyConfig().getCurrencyMajor().get(0);
@ -129,6 +129,10 @@ public class Economy_CurrencyCore implements Economy {
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null) {
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
@ -142,6 +146,10 @@ public class Economy_CurrencyCore implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
AccountContext account = this.currency.getAccountManager().getAccount(playerName);
if (account == null) {
return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist");
@ -192,6 +200,10 @@ public class Economy_CurrencyCore implements Economy {
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");
@ -205,6 +217,10 @@ public class Economy_CurrencyCore implements Economy {
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
AccountContext account = this.currency.getAccountManager().getAccount(name);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!");

View File

@ -94,6 +94,10 @@ public class Economy_Essentials implements Economy {
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
@ -130,6 +134,10 @@ public class Economy_Essentials implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;

View File

@ -129,7 +129,7 @@ public class Economy_MineConomy implements Economy {
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
try {
balance = MCCom.getBalance(playerName);

View File

@ -81,6 +81,10 @@ public class Economy_iConomy5 implements Economy {
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
Holdings holdings = iConomy.getAccount(playerName).getHoldings();
if (holdings.hasEnough(amount)) {
holdings.subtract(amount);
@ -92,6 +96,10 @@ public class Economy_iConomy5 implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
Holdings holdings = iConomy.getAccount(playerName).getHoldings();
holdings.add(amount);
return new EconomyResponse(amount, holdings.balance(), EconomyResponse.ResponseType.SUCCESS, null);

View File

@ -132,6 +132,10 @@ public class Economy_iConomy6 implements Economy {
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
Holdings holdings = accounts.get(playerName).getHoldings();
if (holdings.hasEnough(amount)) {
holdings.subtract(amount);
@ -143,6 +147,10 @@ public class Economy_iConomy6 implements Economy {
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
Holdings holdings = accounts.get(playerName).getHoldings();
holdings.add(amount);
return new EconomyResponse(amount, holdings.getBalance(), ResponseType.SUCCESS, null);
@ -187,11 +195,19 @@ public class Economy_iConomy6 implements Economy {
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
}
return withdrawPlayer(name, amount);
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
return depositPlayer(name, amount);
}