fix improper formatting on gringotts, and incorrect jdocs. Jdocs are

not to be used in implementing classes as the return values MUST match
what the jdoc/parent class defines.
This commit is contained in:
Sleaker 2012-08-08 20:44:27 -07:00
parent 54252e65a6
commit deefa25dfb

View File

@ -33,7 +33,6 @@ import org.bukkit.plugin.Plugin;
import org.gestern.gringotts.Account;
import org.gestern.gringotts.AccountHolder;
import org.gestern.gringotts.Gringotts;
import org.gestern.gringotts.PlayerAccountHolder;
public class Economy_Gringotts implements Economy {
@ -42,20 +41,20 @@ public class Economy_Gringotts implements Economy {
private final String name = "Gringotts";
private Plugin plugin = null;
private Gringotts gringotts = null;
public Economy_Gringotts(Plugin plugin) {
this.plugin = plugin;
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
// Load Plugin in case it was loaded before
if (gringotts == null) {
Plugin grngts = plugin.getServer().getPluginManager().getPlugin("Gringotts");
if (grngts != null && grngts.isEnabled()) {
gringotts = (Gringotts) grngts;
gringotts = (Gringotts) grngts;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
public class EconomyServerListener implements Listener {
Economy_Gringotts economy = null;
@ -85,132 +84,76 @@ public class Economy_Gringotts implements Economy {
}
}
}
/**
* Checks if economy method is enabled.
* @return Success or Failure
*/
@Override
public boolean isEnabled(){
return gringotts != null && gringotts.isEnabled();
return gringotts != null && gringotts.isEnabled();
}
/**
* Gets name of permission method
* @return Name of Permission Method
*/
@Override
public String getName() {
return name;
}
return name;
}
/**
* Returns true if the given implementation supports banks.
* @return true if the implementation supports banks
*/
@Override
public boolean hasBankSupport(){
return false;
return false;
}
/**
* Some economy plugins round off after a certain number of digits.
* This function returns the number of digits the plugin keeps
* or -1 if no rounding occurs.
* @return number of digits after the decimal point kept
*/
@Override
public int fractionalDigits(){
return 2;
return 2;
}
/**
* Format amount into a human readable String This provides translation into
* economy specific formatting to improve consistency between plugins.
*
* @param amount
* @return Human readable string describing amount
*/
@Override
public String format(double amount) {
// TODO 2-digit formatting
return Double.toString(amount);
return Double.toString(amount);
}
/**
* Returns the name of the currency in plural form.
* If the economy being used does not support currency names then an empty string will be returned.
*
* @return name of the currency (plural)
*/
@Override
public String currencyNamePlural(){
return org.gestern.gringotts.Configuration.config.currencyNamePlural;
return org.gestern.gringotts.Configuration.config.currencyNamePlural;
}
/**
* Returns the name of the currency in singular form.
* If the economy being used does not support currency names then an empty string will be returned.
*
* @return name of the currency (singular)
*/
@Override
public String currencyNameSingular(){
return org.gestern.gringotts.Configuration.config.currencyNameSingular;
return org.gestern.gringotts.Configuration.config.currencyNameSingular;
}
/**
* Checks if this player or entity has an account on the server yet.
* This will always return true if the player has joined the server at least once
* as all major economy plugins auto-generate a player account when the player joins the server.
* @param playerName
* @return if the player has an account
*/
@Override
public boolean hasAccount(String playerName) {
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return false;
return gringotts.accounting.getAccount(owner) != null;
}
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return false;
return gringotts.accounting.getAccount(owner) != null;
}
/**
* Gets balance of a player
* @param playerName
* @return Amount currently held in players account
*/
@Override
public double getBalance(String playerName){
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return 0;
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return 0;
Account account = gringotts.accounting.getAccount(owner);
return account.balance();
return account.balance();
}
/**
* Checks if the player account has the amount - DO NOT USE NEGATIVE AMOUNTS
*
* @param playerName
* @param amount
* @return
* @throws UserDoesNotExistException
*/
@Override
public boolean has(String playerName, double amount) {
return getBalance(playerName) >= amount;
return getBalance(playerName) >= amount;
}
/**
* 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
*/
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if( amount < 0 ) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw a negative amount.");
}
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
if (accountHolder == null)
return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder.");
if (accountHolder == null)
return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder.");
Account account = gringotts.accounting.getAccount( accountHolder );
if(account.balance() >= amount && account.remove(amount)) {
//We has mulah!
return new EconomyResponse(amount, account.balance(), ResponseType.SUCCESS, null);
@ -218,128 +161,75 @@ public class Economy_Gringotts implements Economy {
//Not enough money to withdraw this much.
return new EconomyResponse(0, account.balance(), ResponseType.FAILURE, "Insufficient funds");
}
}
/**
* 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
*/
@Override
public EconomyResponse depositPlayer(String playerName, double amount){
if (amount < 0) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
if (accountHolder == null)
return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder.");
return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder.");
Account account = gringotts.accounting.getAccount( accountHolder );
if (account.add(amount))
return new EconomyResponse( amount, account.balance(), ResponseType.SUCCESS, null);
return new EconomyResponse( amount, account.balance(), ResponseType.SUCCESS, null);
else
return new EconomyResponse( 0, account.balance(), ResponseType.FAILURE, "Not enough capacity to store that amount!");
return new EconomyResponse( 0, account.balance(), ResponseType.FAILURE, "Not enough capacity to store that amount!");
}
/**
* Creates a bank account with the specified name and the player as the owner
* @param name
* @param player
* @return
*/
@Override
public EconomyResponse createBank(String name, String player) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Deletes a bank account with the specified name.
* @param name
* @return if the operation completed successfully
*/
@Override
public EconomyResponse deleteBank(String name) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Returns the amount the bank has
* @param name
* @return
*/
@Override
public EconomyResponse bankBalance(String name) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Returns true or false whether the bank has the amount specified - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return
*/
@Override
public EconomyResponse bankHas(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Withdraw an amount from a bank account - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return
*/
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Deposit an amount into a bank account - DO NOT USE NEGATIVE AMOUNTS
*
* @param name
* @param amount
* @return
*/
@Override
public EconomyResponse bankDeposit(String name, double amount) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Check if a player is the owner of a bank account
* @param name
* @param playerName
* @return
*/
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Check if the player is a member of the bank account
* @param name
* @param playerName
* @return
*/
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!");
}
/**
* Gets the list of banks
* @return the List of Banks
*/
@Override
public List<String> getBanks() {
return new ArrayList<String>();
}
/**
* Attempts to create a player account for the given player
* @return if the account creation was successful
*/
@Override
public boolean createPlayerAccount(String playerName) {
return hasAccount(playerName);
return hasAccount(playerName);
}
}