update to gringotts with faction support

This commit is contained in:
jast 2012-08-09 01:37:18 +02:00
parent 70d627266e
commit 54252e65a6
2 changed files with 20 additions and 27 deletions

Binary file not shown.

View File

@ -31,6 +31,7 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
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;
@ -90,11 +91,7 @@ public class Economy_Gringotts implements Economy {
* @return Success or Failure
*/
public boolean isEnabled(){
if (gringotts == null) {
return false;
} else {
return gringotts.isEnabled();
}
return gringotts != null && gringotts.isEnabled();
}
/**
@ -131,6 +128,7 @@ public class Economy_Gringotts implements Economy {
* @return Human readable string describing amount
*/
public String format(double amount) {
// TODO 2-digit formatting
return Double.toString(amount);
}
@ -156,23 +154,17 @@ public class Economy_Gringotts implements Economy {
}
/**
* Checks if this player has an account on the server yet
* 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
* 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
*/
public boolean hasAccount(String playerName) {
try{
Account account = gringotts.accounting.getAccount(new PlayerAccountHolder(playerName));
if(account != null)
return true;
else
return false;
}
catch (Exception e){
return false;
}
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return false;
return gringotts.accounting.getAccount(owner) != null;
}
@ -182,7 +174,9 @@ public class Economy_Gringotts implements Economy {
* @return Amount currently held in players account
*/
public double getBalance(String playerName){
Account account = gringotts.accounting.getAccount(new PlayerAccountHolder(playerName));
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
if (owner == null) return 0;
Account account = gringotts.accounting.getAccount(owner);
return account.balance();
}
@ -211,7 +205,9 @@ public class Economy_Gringotts implements Economy {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw a negative amount.");
}
PlayerAccountHolder accountHolder = new PlayerAccountHolder(playerName);
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
if (accountHolder == null)
return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder.");
Account account = gringotts.accounting.getAccount( accountHolder );
@ -237,7 +233,10 @@ public class Economy_Gringotts implements Economy {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
}
PlayerAccountHolder accountHolder = new PlayerAccountHolder(playerName);
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
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.add(amount))
@ -341,12 +340,6 @@ public class Economy_Gringotts implements Economy {
* @return if the account creation was successful
*/
public boolean createPlayerAccount(String playerName) {
if (hasAccount(playerName)) {
return false;
}
else
return true;
return hasAccount(playerName);
}
}