mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-09-21 02:01:10 +02:00
update to gringotts with faction support
This commit is contained in:
parent
70d627266e
commit
54252e65a6
Binary file not shown.
@ -31,6 +31,7 @@ import org.bukkit.event.server.PluginDisableEvent;
|
|||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.gestern.gringotts.Account;
|
import org.gestern.gringotts.Account;
|
||||||
|
import org.gestern.gringotts.AccountHolder;
|
||||||
import org.gestern.gringotts.Gringotts;
|
import org.gestern.gringotts.Gringotts;
|
||||||
import org.gestern.gringotts.PlayerAccountHolder;
|
import org.gestern.gringotts.PlayerAccountHolder;
|
||||||
|
|
||||||
@ -90,11 +91,7 @@ public class Economy_Gringotts implements Economy {
|
|||||||
* @return Success or Failure
|
* @return Success or Failure
|
||||||
*/
|
*/
|
||||||
public boolean isEnabled(){
|
public boolean isEnabled(){
|
||||||
if (gringotts == null) {
|
return gringotts != null && gringotts.isEnabled();
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return gringotts.isEnabled();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,6 +128,7 @@ public class Economy_Gringotts implements Economy {
|
|||||||
* @return Human readable string describing amount
|
* @return Human readable string describing amount
|
||||||
*/
|
*/
|
||||||
public String format(double amount) {
|
public String format(double amount) {
|
||||||
|
// TODO 2-digit formatting
|
||||||
return Double.toString(amount);
|
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
|
* 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
|
* @param playerName
|
||||||
* @return if the player has an account
|
* @return if the player has an account
|
||||||
*/
|
*/
|
||||||
public boolean hasAccount(String playerName) {
|
public boolean hasAccount(String playerName) {
|
||||||
try{
|
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
|
||||||
Account account = gringotts.accounting.getAccount(new PlayerAccountHolder(playerName));
|
if (owner == null) return false;
|
||||||
if(account != null)
|
|
||||||
return true;
|
return gringotts.accounting.getAccount(owner) != null;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -182,7 +174,9 @@ public class Economy_Gringotts implements Economy {
|
|||||||
* @return Amount currently held in players account
|
* @return Amount currently held in players account
|
||||||
*/
|
*/
|
||||||
public double getBalance(String playerName){
|
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();
|
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.");
|
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 );
|
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");
|
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 );
|
Account account = gringotts.accounting.getAccount( accountHolder );
|
||||||
|
|
||||||
if (account.add(amount))
|
if (account.add(amount))
|
||||||
@ -341,12 +340,6 @@ public class Economy_Gringotts implements Economy {
|
|||||||
* @return if the account creation was successful
|
* @return if the account creation was successful
|
||||||
*/
|
*/
|
||||||
public boolean createPlayerAccount(String playerName) {
|
public boolean createPlayerAccount(String playerName) {
|
||||||
if (hasAccount(playerName)) {
|
return hasAccount(playerName);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user