mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-12-29 12:28:35 +01:00
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:
parent
54252e65a6
commit
deefa25dfb
@ -33,7 +33,6 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.gestern.gringotts.Account;
|
import org.gestern.gringotts.Account;
|
||||||
import org.gestern.gringotts.AccountHolder;
|
import org.gestern.gringotts.AccountHolder;
|
||||||
import org.gestern.gringotts.Gringotts;
|
import org.gestern.gringotts.Gringotts;
|
||||||
import org.gestern.gringotts.PlayerAccountHolder;
|
|
||||||
|
|
||||||
public class Economy_Gringotts implements Economy {
|
public class Economy_Gringotts implements Economy {
|
||||||
|
|
||||||
@ -42,20 +41,20 @@ public class Economy_Gringotts implements Economy {
|
|||||||
private final String name = "Gringotts";
|
private final String name = "Gringotts";
|
||||||
private Plugin plugin = null;
|
private Plugin plugin = null;
|
||||||
private Gringotts gringotts = null;
|
private Gringotts gringotts = null;
|
||||||
|
|
||||||
public Economy_Gringotts(Plugin plugin) {
|
public Economy_Gringotts(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
|
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
|
||||||
// Load Plugin in case it was loaded before
|
// Load Plugin in case it was loaded before
|
||||||
if (gringotts == null) {
|
if (gringotts == null) {
|
||||||
Plugin grngts = plugin.getServer().getPluginManager().getPlugin("Gringotts");
|
Plugin grngts = plugin.getServer().getPluginManager().getPlugin("Gringotts");
|
||||||
if (grngts != null && grngts.isEnabled()) {
|
if (grngts != null && grngts.isEnabled()) {
|
||||||
gringotts = (Gringotts) grngts;
|
gringotts = (Gringotts) grngts;
|
||||||
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EconomyServerListener implements Listener {
|
public class EconomyServerListener implements Listener {
|
||||||
Economy_Gringotts economy = null;
|
Economy_Gringotts economy = null;
|
||||||
|
|
||||||
@ -85,132 +84,76 @@ public class Economy_Gringotts implements Economy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Checks if economy method is enabled.
|
|
||||||
* @return Success or Failure
|
|
||||||
*/
|
|
||||||
public boolean isEnabled(){
|
public boolean isEnabled(){
|
||||||
return gringotts != null && gringotts.isEnabled();
|
return gringotts != null && gringotts.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets name of permission method
|
|
||||||
* @return Name of Permission Method
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns true if the given implementation supports banks.
|
|
||||||
* @return true if the implementation supports banks
|
|
||||||
*/
|
|
||||||
public boolean hasBankSupport(){
|
public boolean hasBankSupport(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public int fractionalDigits(){
|
public int fractionalDigits(){
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public String format(double amount) {
|
public String format(double amount) {
|
||||||
// TODO 2-digit formatting
|
return Double.toString(amount);
|
||||||
return Double.toString(amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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)
|
|
||||||
*/
|
|
||||||
public String currencyNamePlural(){
|
public String currencyNamePlural(){
|
||||||
return org.gestern.gringotts.Configuration.config.currencyNamePlural;
|
return org.gestern.gringotts.Configuration.config.currencyNamePlural;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
*/
|
|
||||||
public String currencyNameSingular(){
|
public String currencyNameSingular(){
|
||||||
return org.gestern.gringotts.Configuration.config.currencyNameSingular;
|
return org.gestern.gringotts.Configuration.config.currencyNameSingular;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public boolean hasAccount(String playerName) {
|
public boolean hasAccount(String playerName) {
|
||||||
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
|
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
|
||||||
if (owner == null) return false;
|
if (owner == null) return false;
|
||||||
|
|
||||||
return gringotts.accounting.getAccount(owner) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return gringotts.accounting.getAccount(owner) != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets balance of a player
|
|
||||||
* @param playerName
|
|
||||||
* @return Amount currently held in players account
|
|
||||||
*/
|
|
||||||
public double getBalance(String playerName){
|
public double getBalance(String playerName){
|
||||||
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
|
AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName);
|
||||||
if (owner == null) return 0;
|
if (owner == null) return 0;
|
||||||
Account account = gringotts.accounting.getAccount(owner);
|
Account account = gringotts.accounting.getAccount(owner);
|
||||||
return account.balance();
|
return account.balance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Checks if the player account has the amount - DO NOT USE NEGATIVE AMOUNTS
|
|
||||||
*
|
|
||||||
* @param playerName
|
|
||||||
* @param amount
|
|
||||||
* @return
|
|
||||||
* @throws UserDoesNotExistException
|
|
||||||
*/
|
|
||||||
public boolean has(String playerName, double amount) {
|
public boolean has(String playerName, double amount) {
|
||||||
return getBalance(playerName) >= amount;
|
return getBalance(playerName) >= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
||||||
|
|
||||||
if( amount < 0 ) {
|
if( amount < 0 ) {
|
||||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw a negative amount.");
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw a negative amount.");
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
|
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
|
||||||
if (accountHolder == null)
|
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 );
|
Account account = gringotts.accounting.getAccount( accountHolder );
|
||||||
|
|
||||||
if(account.balance() >= amount && account.remove(amount)) {
|
if(account.balance() >= amount && account.remove(amount)) {
|
||||||
//We has mulah!
|
//We has mulah!
|
||||||
return new EconomyResponse(amount, account.balance(), ResponseType.SUCCESS, null);
|
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.
|
//Not enough money to withdraw this much.
|
||||||
return new EconomyResponse(0, account.balance(), ResponseType.FAILURE, "Insufficient funds");
|
return new EconomyResponse(0, account.balance(), ResponseType.FAILURE, "Insufficient funds");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public EconomyResponse depositPlayer(String playerName, double amount){
|
public EconomyResponse depositPlayer(String playerName, double amount){
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
|
AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName);
|
||||||
if (accountHolder == null)
|
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 );
|
Account account = gringotts.accounting.getAccount( accountHolder );
|
||||||
|
|
||||||
if (account.add(amount))
|
if (account.add(amount))
|
||||||
return new EconomyResponse( amount, account.balance(), ResponseType.SUCCESS, null);
|
return new EconomyResponse( amount, account.balance(), ResponseType.SUCCESS, null);
|
||||||
else
|
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!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Creates a bank account with the specified name and the player as the owner
|
|
||||||
* @param name
|
|
||||||
* @param player
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse createBank(String name, String player) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Deletes a bank account with the specified name.
|
|
||||||
* @param name
|
|
||||||
* @return if the operation completed successfully
|
|
||||||
*/
|
|
||||||
public EconomyResponse deleteBank(String name) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the amount the bank has
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse bankBalance(String name) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns true or false whether the bank has the amount specified - DO NOT USE NEGATIVE AMOUNTS
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param amount
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse bankHas(String name, double amount) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Withdraw an amount from a bank account - DO NOT USE NEGATIVE AMOUNTS
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param amount
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse bankWithdraw(String name, double amount) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Deposit an amount into a bank account - DO NOT USE NEGATIVE AMOUNTS
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param amount
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse bankDeposit(String name, double amount) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Check if a player is the owner of a bank account
|
|
||||||
* @param name
|
|
||||||
* @param playerName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse isBankOwner(String name, String playerName) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Check if the player is a member of the bank account
|
|
||||||
* @param name
|
|
||||||
* @param playerName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EconomyResponse isBankMember(String name, String playerName) {
|
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!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets the list of banks
|
|
||||||
* @return the List of Banks
|
|
||||||
*/
|
|
||||||
public List<String> getBanks() {
|
public List<String> getBanks() {
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Attempts to create a player account for the given player
|
|
||||||
* @return if the account creation was successful
|
|
||||||
*/
|
|
||||||
public boolean createPlayerAccount(String playerName) {
|
public boolean createPlayerAccount(String playerName) {
|
||||||
return hasAccount(playerName);
|
return hasAccount(playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user