From fc8ffc0b81ad8a5adb9468e996340bb7466bfa9e Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sat, 15 Jun 2019 20:59:34 -0400 Subject: [PATCH 01/25] Added Reserve Support, and tested. --- Essentials/pom.xml | 6 + .../com/earth2me/essentials/Essentials.java | 29 +- .../essentials/Reserve_Essentials.java | 1865 +++++++++++++++++ .../essentials/register/payment/Methods.java | 1 + .../register/payment/methods/ReserveEco.java | 289 +++ Essentials/src/plugin.yml | 2 +- pom.xml | 4 + 7 files changed, 2191 insertions(+), 5 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/Reserve_Essentials.java create mode 100644 Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 6c886407718..423398e9153 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -48,6 +48,12 @@ + + net.tnemc + Reserve + 0.1.2.0 + provided + net.milkbowl.vault VaultAPI diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 31db97ee3d5..dcb9b852ec7 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -17,7 +17,11 @@ */ package com.earth2me.essentials; -import com.earth2me.essentials.commands.*; +import com.earth2me.essentials.commands.EssentialsCommand; +import com.earth2me.essentials.commands.IEssentialsCommand; +import com.earth2me.essentials.commands.NoChargeException; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import com.earth2me.essentials.commands.QuietAbortException; import com.earth2me.essentials.items.AbstractItemDb; import com.earth2me.essentials.items.FlatItemDb; import com.earth2me.essentials.items.LegacyItemDb; @@ -35,8 +39,10 @@ import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; -import net.ess3.api.*; +import net.ess3.api.Economy; import net.ess3.api.IEssentials; +import net.ess3.api.IItemDb; +import net.ess3.api.IJails; import net.ess3.api.ISettings; import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; @@ -55,7 +61,11 @@ import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.command.*; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -80,7 +90,14 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -183,6 +200,10 @@ public void onEnable() { } } + if(pm.isPluginEnabled("Reserve")) { + Reserve_Essentials.register(this); + } + for (Method method : Server.class.getDeclaredMethods()) { if (method.getName().endsWith("getOnlinePlayers") && method.getReturnType() == Player[].class) { oldGetOnlinePlayers = method; diff --git a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java new file mode 100644 index 00000000000..7a0575ef417 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java @@ -0,0 +1,1865 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.api.NoLoanPermittedException; +import com.earth2me.essentials.api.UserDoesNotExistException; +import net.ess3.api.Economy; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import net.tnemc.core.economy.currency.Currency; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.math.BigDecimal; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * @author creatorfromhell + */ +public class Reserve_Essentials implements EconomyAPI { + + private Essentials plugin; + + public Reserve_Essentials(Essentials plugin) { + this.plugin = plugin; + } + + public static void register(Essentials plugin) { + //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. + if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + Reserve.instance().registerProvider(new Reserve_Essentials(plugin)); + } + } + + /** + * @return The name of the Economy implementation. + */ + @Override + public String name() { + return "Essentials Economy"; + } + + /** + * @return The version of Reserve the Economy implementation supports. + */ + @Override + public String version() { + return "0.1.2.0"; + } + + //This is our method to convert UUID -> username for use with Essentials' create account methods. + private String getName(UUID identifier) { + final User user = plugin.getUser(identifier); + return ((user == null)? identifier.toString() : user.getName()); + } + + /** + * @return Whether or not this implementation is enabled. + */ + @Override + public boolean enabled() { + return true; + } + + /** + * @return Whether or not this implementation should have a default Vault implementation. + */ + @Override + public boolean vault() { + return false; + } + + /** + * Used to get the plural name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural() { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular() { + return "Dollar"; + } + + /** + * Used to get the plural name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural(String world) { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular(String world) { + return "Dollar"; + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name, String world) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name, String world) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(String identifier) { + return Economy.playerExists(identifier); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(UUID identifier) { + return Economy.playerExists(getName(identifier)); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(String identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(identifier); + } + }); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(UUID identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(getName(identifier)); + } + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(String identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(UUID identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(String identifier) { + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(UUID identifier) { + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(identifier); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(getName(identifier)); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(identifier, amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(identifier, amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(getName(identifier), amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @param currency The {@link Currency} associated with the balance. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world, String currency) { + return Economy.format(amount); + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccounts() { + return false; + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccountsUnder(BigDecimal amount) { + return false; + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccounts() { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { + return CompletableFuture.supplyAsync(()->false); + } +} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index 458501ef1ed..3c5802cba94 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -42,6 +42,7 @@ public class Methods { * Implement all methods along with their respective name & class. */ private static void _init() { + addMethod("Reserve", new com.earth2me.essentials.register.payment.methods.ReserveEco()); addMethod("Vault", new com.earth2me.essentials.register.payment.methods.VaultEco()); } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java new file mode 100644 index 00000000000..6d4d852786f --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -0,0 +1,289 @@ +package com.earth2me.essentials.register.payment.methods; + + +import com.earth2me.essentials.register.payment.Method; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import org.bukkit.plugin.Plugin; + +import java.math.BigDecimal; + +public class ReserveEco implements Method { + + Plugin plugin; + EconomyAPI economy; + + /** + * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin + * Class you must cast it to the correct Plugin, to do so you have to verify the name and or + * version then cast. + *

+ *

+   *  if(method.getName().equalsIgnoreCase("iConomy"))
+   *   iConomy plugin = ((iConomy)method.getPlugin());
+ * + * @return Object + * + * @see #getName() + * @see #getVersion() + */ + @Override + public Plugin getPlugin() { + return plugin; + } + + /** + * Returns the actual name of this method. + * + * @return String Plugin name. + */ + @Override + public String getName() { + return "Reserve"; + } + + public String getProvider() { + return economy == null ? "No Provider" : economy.name(); + } + + /** + * Returns the reported name of this method. + * + * @return String Plugin name. + */ + @Override + public String getLongName() { + return "Reserve Economy: " + getProvider(); + } + + /** + * Returns the actual version of this method. + * + * @return String Plugin version. + */ + @Override + public String getVersion() { + return plugin.getDescription().getVersion(); + } + + /** + * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no + * rounding + * + * @return int for each decimal place + */ + @Override + public int fractionalDigits() { + return 0; + } + + /** + * Formats amounts into this payment methods style of currency display. + * + * @param amount Double + * + * @return String - Formatted Currency Display. + */ + @Override + public String format(double amount) { + return economy.format(BigDecimal.valueOf(amount)); + } + + /** + * Allows the verification of bank API existence in this payment method. + * + * @return boolean + */ + @Override + public boolean hasBanks() { + return false; + } + + /** + * Determines the existence of a bank via name. + * + * @param bank Bank name + * + * @return boolean + * + * @see #hasBanks + */ + @Override + public boolean hasBank(String bank) { + return false; + } + + /** + * Determines the existence of an account via name. + * + * @param name Account name + * + * @return boolean + */ + @Override + public boolean hasAccount(String name) { + return economy.hasAccount(name); + } + + /** + * Check to see if an account name is tied to a bank. + * + * @param bank Bank name + * @param name Account name + * + * @return boolean + */ + @Override + public boolean hasBankAccount(String bank, String name) { + return false; + } + + /** + * Forces an account creation + * + * @param name Account name + * + * @return boolean + */ + @Override + public boolean createAccount(String name) { + return economy.createAccount(name); + } + + /** + * Forces an account creation + * + * @param name Account name + * @param balance Initial account balance + * + * @return boolean + */ + @Override + public boolean createAccount(String name, Double balance) { + return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); + } + + /** + * Returns a MethodAccount class for an account name. + * + * @param name Account name + * + * @return MethodAccount or Null + */ + @Override + public MethodAccount getAccount(String name) { + if(!hasAccount(name)) return null; + return new ReserveAccount(name, economy); + } + + /** + * Returns a MethodBankAccount class for an account name. + * + * @param bank Bank name + * @param name Account name + * + * @return MethodBankAccount or Null + */ + @Override + public MethodBankAccount getBankAccount(String bank, String name) { + return null; + } + + /** + * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for + * the most part. + * + * @param plugin Plugin + * + * @return boolean + */ + @Override + public boolean isCompatible(Plugin plugin) { + try { + EconomyAPI economyAPI = ((Reserve)plugin).economy(); + return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); + } catch (LinkageError | Exception e) { + return false; + } + } + + /** + * Set Plugin data. + * + * @param plugin Plugin + */ + @Override + public void setPlugin(Plugin plugin) { + this.plugin = plugin; + + if(((Reserve)plugin).economyProvided()) { + this.economy = ((Reserve)plugin).economy(); + } + } + + public class ReserveAccount implements MethodAccount { + + private String identifier; + private EconomyAPI economy; + + public ReserveAccount(String identifier, EconomyAPI economy) { + this.identifier = identifier; + this.economy = economy; + } + + @Override + public double balance() { + return economy.getHoldings(identifier).doubleValue(); + } + + @Override + public boolean set(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean add(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + } + + @Override + public boolean subtract(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + } + + @Override + public boolean multiply(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + } + + @Override + public boolean divide(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + } + + @Override + public boolean hasEnough(double amount) { + return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean hasOver(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + } + + @Override + public boolean hasUnder(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean isNegative() { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean remove() { + return economy.deleteAccount(identifier); + } + } +} \ No newline at end of file diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 019f8e70cda..6cfacc841f3 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -5,7 +5,7 @@ main: com.earth2me.essentials.Essentials version: ${full.version} website: http://tiny.cc/EssentialsCommands description: Provides an essential, core set of commands for Bukkit. -softdepend: [Vault] +softdepend: [Vault, Reserve] authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Iaccidentally, drtshock, vemacs, SupaHam, md678685] api-version: 1.13 commands: diff --git a/pom.xml b/pom.xml index 182d4494430..d8500b6748d 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,10 @@ + + reserve-repo + https://dl.bintray.com/theneweconomy/java/ + ess-repo https://ci.ender.zone/plugin/repository/everything/ From 6528b37d097f90c57fa42e0bbfd96317af1f7327 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 19 Jun 2019 22:41:50 -0400 Subject: [PATCH 02/25] Modified to address PR requested modifications. --- .../com/earth2me/essentials/Essentials.java | 2 +- .../essentials/ReserveEssentials.java | 1865 +++++++++++++++++ .../essentials/Reserve_Essentials.java | 1865 ----------------- .../register/payment/methods/ReserveEco.java | 474 ++--- 4 files changed, 2103 insertions(+), 2103 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/ReserveEssentials.java delete mode 100644 Essentials/src/com/earth2me/essentials/Reserve_Essentials.java diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index dcb9b852ec7..405f69e8cf1 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -201,7 +201,7 @@ public void onEnable() { } if(pm.isPluginEnabled("Reserve")) { - Reserve_Essentials.register(this); + ReserveEssentials.register(this); } for (Method method : Server.class.getDeclaredMethods()) { diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java new file mode 100644 index 00000000000..bc04eab4664 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -0,0 +1,1865 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.api.NoLoanPermittedException; +import com.earth2me.essentials.api.UserDoesNotExistException; +import net.ess3.api.Economy; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import net.tnemc.core.economy.currency.Currency; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.math.BigDecimal; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * @author creatorfromhell + */ +public class ReserveEssentials implements EconomyAPI { + + private Essentials plugin; + + public ReserveEssentials(Essentials plugin) { + this.plugin = plugin; + } + + public static void register(Essentials plugin) { + //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. + if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + Reserve.instance().registerProvider(new ReserveEssentials(plugin)); + } + } + + /** + * @return The name of the Economy implementation. + */ + @Override + public String name() { + return "Essentials Economy"; + } + + /** + * @return The version of Reserve the Economy implementation supports. + */ + @Override + public String version() { + return "0.1.2.0"; + } + + //This is our method to convert UUID -> username for use with Essentials' create account methods. + private String getName(UUID identifier) { + final User user = plugin.getUser(identifier); + return ((user == null)? identifier.toString() : user.getName()); + } + + /** + * @return Whether or not this implementation is enabled. + */ + @Override + public boolean enabled() { + return true; + } + + /** + * @return Whether or not this implementation should have a default Vault implementation. + */ + @Override + public boolean vault() { + return false; + } + + /** + * Used to get the plural name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural() { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular() { + return "Dollar"; + } + + /** + * Used to get the plural name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural(String world) { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular(String world) { + return "Dollar"; + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name, String world) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name, String world) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(String identifier) { + return Economy.playerExists(identifier); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(UUID identifier) { + return Economy.playerExists(getName(identifier)); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(String identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(identifier); + } + }); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(UUID identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(getName(identifier)); + } + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(String identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(UUID identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(String identifier) { + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(UUID identifier) { + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(identifier); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(getName(identifier)); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(identifier, amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(identifier, amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(getName(identifier), amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @param currency The {@link Currency} associated with the balance. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world, String currency) { + return Economy.format(amount); + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccounts() { + return false; + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccountsUnder(BigDecimal amount) { + return false; + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccounts() { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { + return CompletableFuture.supplyAsync(()->false); + } +} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java deleted file mode 100644 index 7a0575ef417..00000000000 --- a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java +++ /dev/null @@ -1,1865 +0,0 @@ -package com.earth2me.essentials; - -import com.earth2me.essentials.api.NoLoanPermittedException; -import com.earth2me.essentials.api.UserDoesNotExistException; -import net.ess3.api.Economy; -import net.tnemc.core.Reserve; -import net.tnemc.core.economy.EconomyAPI; -import net.tnemc.core.economy.currency.Currency; -import org.bukkit.Bukkit; -import org.bukkit.World; - -import java.math.BigDecimal; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** - * @author creatorfromhell - */ -public class Reserve_Essentials implements EconomyAPI { - - private Essentials plugin; - - public Reserve_Essentials(Essentials plugin) { - this.plugin = plugin; - } - - public static void register(Essentials plugin) { - //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { - Reserve.instance().registerProvider(new Reserve_Essentials(plugin)); - } - } - - /** - * @return The name of the Economy implementation. - */ - @Override - public String name() { - return "Essentials Economy"; - } - - /** - * @return The version of Reserve the Economy implementation supports. - */ - @Override - public String version() { - return "0.1.2.0"; - } - - //This is our method to convert UUID -> username for use with Essentials' create account methods. - private String getName(UUID identifier) { - final User user = plugin.getUser(identifier); - return ((user == null)? identifier.toString() : user.getName()); - } - - /** - * @return Whether or not this implementation is enabled. - */ - @Override - public boolean enabled() { - return true; - } - - /** - * @return Whether or not this implementation should have a default Vault implementation. - */ - @Override - public boolean vault() { - return false; - } - - /** - * Used to get the plural name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural() { - return "Dollars"; - } - - /** - * Used to get the singular name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular() { - return "Dollar"; - } - - /** - * Used to get the plural name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural(String world) { - return "Dollars"; - } - - /** - * Used to get the singular name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular(String world) { - return "Dollar"; - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name) { - return true; //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name, String world) { - return true; //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(String identifier) { - return Economy.playerExists(identifier); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(UUID identifier) { - return Economy.playerExists(getName(identifier)); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(identifier); - } - }); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(getName(identifier)); - } - }); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(String identifier) { - if(hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(UUID identifier) { - if(hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - }); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - }); - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(String identifier) { - try { - Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(UUID identifier) { - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ - try { - Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier) { - if(hasAccount(identifier)) { - try { - return Economy.getMoneyExact(identifier); - } catch(UserDoesNotExistException ignore) { } - } - return plugin.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier) { - if(hasAccount(identifier)) { - try { - return Economy.getMoneyExact(getName(identifier)); - } catch(UserDoesNotExistException ignore) { } - } - return plugin.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(identifier, amount); - } catch(UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); - } catch(UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; - try { - Economy.setMoney(identifier, amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; - try { - Economy.setMoney(getName(identifier), amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @param currency The {@link Currency} associated with the balance. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world, String currency) { - return Economy.format(amount); - } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccounts() { - return false; - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccountsUnder(BigDecimal amount) { - return false; - } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(()->false); - } -} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java index 6d4d852786f..a39c2d02f4a 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -10,280 +10,280 @@ public class ReserveEco implements Method { - Plugin plugin; - EconomyAPI economy; - - /** - * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin - * Class you must cast it to the correct Plugin, to do so you have to verify the name and or - * version then cast. - *

- *

-   *  if(method.getName().equalsIgnoreCase("iConomy"))
-   *   iConomy plugin = ((iConomy)method.getPlugin());
- * - * @return Object - * - * @see #getName() - * @see #getVersion() - */ - @Override - public Plugin getPlugin() { - return plugin; - } - - /** - * Returns the actual name of this method. - * - * @return String Plugin name. - */ - @Override - public String getName() { - return "Reserve"; - } - - public String getProvider() { - return economy == null ? "No Provider" : economy.name(); - } - - /** - * Returns the reported name of this method. - * - * @return String Plugin name. - */ - @Override - public String getLongName() { - return "Reserve Economy: " + getProvider(); - } - - /** - * Returns the actual version of this method. - * - * @return String Plugin version. - */ - @Override - public String getVersion() { - return plugin.getDescription().getVersion(); - } - - /** - * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no - * rounding - * - * @return int for each decimal place - */ - @Override - public int fractionalDigits() { - return 0; - } - - /** - * Formats amounts into this payment methods style of currency display. - * - * @param amount Double - * - * @return String - Formatted Currency Display. - */ - @Override - public String format(double amount) { - return economy.format(BigDecimal.valueOf(amount)); - } - - /** - * Allows the verification of bank API existence in this payment method. - * - * @return boolean - */ - @Override - public boolean hasBanks() { - return false; - } - - /** - * Determines the existence of a bank via name. - * - * @param bank Bank name - * - * @return boolean - * - * @see #hasBanks - */ - @Override - public boolean hasBank(String bank) { - return false; - } - - /** - * Determines the existence of an account via name. - * - * @param name Account name - * - * @return boolean - */ - @Override - public boolean hasAccount(String name) { - return economy.hasAccount(name); - } - - /** - * Check to see if an account name is tied to a bank. - * - * @param bank Bank name - * @param name Account name - * - * @return boolean - */ - @Override - public boolean hasBankAccount(String bank, String name) { - return false; - } - - /** - * Forces an account creation - * - * @param name Account name - * - * @return boolean - */ - @Override - public boolean createAccount(String name) { - return economy.createAccount(name); - } - - /** - * Forces an account creation - * - * @param name Account name - * @param balance Initial account balance - * - * @return boolean - */ - @Override - public boolean createAccount(String name, Double balance) { - return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); - } - - /** - * Returns a MethodAccount class for an account name. - * - * @param name Account name - * - * @return MethodAccount or Null - */ - @Override - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) return null; - return new ReserveAccount(name, economy); - } - - /** - * Returns a MethodBankAccount class for an account name. - * - * @param bank Bank name - * @param name Account name - * - * @return MethodBankAccount or Null - */ - @Override - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - /** - * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for - * the most part. - * - * @param plugin Plugin - * - * @return boolean - */ - @Override - public boolean isCompatible(Plugin plugin) { - try { - EconomyAPI economyAPI = ((Reserve)plugin).economy(); - return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); - } catch (LinkageError | Exception e) { - return false; + Plugin plugin; + EconomyAPI economy; + + /** + * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin + * Class you must cast it to the correct Plugin, to do so you have to verify the name and or + * version then cast. + *

+ *

+     *    if(method.getName().equalsIgnoreCase("iConomy"))
+     *     iConomy plugin = ((iConomy)method.getPlugin());
+ * + * @return Object + * + * @see #getName() + * @see #getVersion() + */ + @Override + public Plugin getPlugin() { + return plugin; } - } - - /** - * Set Plugin data. - * - * @param plugin Plugin - */ - @Override - public void setPlugin(Plugin plugin) { - this.plugin = plugin; - - if(((Reserve)plugin).economyProvided()) { - this.economy = ((Reserve)plugin).economy(); + + /** + * Returns the actual name of this method. + * + * @return String Plugin name. + */ + @Override + public String getName() { + return "Reserve"; } - } - public class ReserveAccount implements MethodAccount { + public String getProvider() { + return economy == null ? "No Provider" : economy.name(); + } - private String identifier; - private EconomyAPI economy; + /** + * Returns the reported name of this method. + * + * @return String Plugin name. + */ + @Override + public String getLongName() { + return "Reserve Economy: " + getProvider(); + } - public ReserveAccount(String identifier, EconomyAPI economy) { - this.identifier = identifier; - this.economy = economy; + /** + * Returns the actual version of this method. + * + * @return String Plugin version. + */ + @Override + public String getVersion() { + return plugin.getDescription().getVersion(); } + /** + * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no + * rounding + * + * @return int for each decimal place + */ @Override - public double balance() { - return economy.getHoldings(identifier).doubleValue(); + public int fractionalDigits() { + return 0; } + /** + * Formats amounts into this payment methods style of currency display. + * + * @param amount Double + * + * @return String - Formatted Currency Display. + */ @Override - public boolean set(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + public String format(double amount) { + return economy.format(BigDecimal.valueOf(amount)); } + /** + * Allows the verification of bank API existence in this payment method. + * + * @return boolean + */ @Override - public boolean add(double amount) { - return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + public boolean hasBanks() { + return false; } + /** + * Determines the existence of a bank via name. + * + * @param bank Bank name + * + * @return boolean + * + * @see #hasBanks + */ @Override - public boolean subtract(double amount) { - return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + public boolean hasBank(String bank) { + return false; } + /** + * Determines the existence of an account via name. + * + * @param name Account name + * + * @return boolean + */ @Override - public boolean multiply(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + public boolean hasAccount(String name) { + return economy.hasAccount(name); } + /** + * Check to see if an account name is tied to a bank. + * + * @param bank Bank name + * @param name Account name + * + * @return boolean + */ @Override - public boolean divide(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + public boolean hasBankAccount(String bank, String name) { + return false; } + /** + * Forces an account creation + * + * @param name Account name + * + * @return boolean + */ @Override - public boolean hasEnough(double amount) { - return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + public boolean createAccount(String name) { + return economy.createAccount(name); } + /** + * Forces an account creation + * + * @param name Account name + * @param balance Initial account balance + * + * @return boolean + */ @Override - public boolean hasOver(double amount) { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + public boolean createAccount(String name, Double balance) { + return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); } + /** + * Returns a MethodAccount class for an account name. + * + * @param name Account name + * + * @return MethodAccount or Null + */ @Override - public boolean hasUnder(double amount) { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + public MethodAccount getAccount(String name) { + if(!hasAccount(name)) return null; + return new ReserveAccount(name, economy); } + /** + * Returns a MethodBankAccount class for an account name. + * + * @param bank Bank name + * @param name Account name + * + * @return MethodBankAccount or Null + */ @Override - public boolean isNegative() { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + public MethodBankAccount getBankAccount(String bank, String name) { + return null; } + /** + * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for + * the most part. + * + * @param plugin Plugin + * + * @return boolean + */ @Override - public boolean remove() { - return economy.deleteAccount(identifier); + public boolean isCompatible(Plugin plugin) { + try { + EconomyAPI economyAPI = ((Reserve)plugin).economy(); + return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); + } catch (LinkageError | Exception e) { + return false; + } + } + + /** + * Set Plugin data. + * + * @param plugin Plugin + */ + @Override + public void setPlugin(Plugin plugin) { + this.plugin = plugin; + + if(((Reserve)plugin).economyProvided()) { + this.economy = ((Reserve)plugin).economy(); + } + } + + public class ReserveAccount implements MethodAccount { + + private String identifier; + private EconomyAPI economy; + + public ReserveAccount(String identifier, EconomyAPI economy) { + this.identifier = identifier; + this.economy = economy; + } + + @Override + public double balance() { + return economy.getHoldings(identifier).doubleValue(); + } + + @Override + public boolean set(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean add(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + } + + @Override + public boolean subtract(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + } + + @Override + public boolean multiply(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + } + + @Override + public boolean divide(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + } + + @Override + public boolean hasEnough(double amount) { + return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean hasOver(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + } + + @Override + public boolean hasUnder(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean isNegative() { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean remove() { + return economy.deleteAccount(identifier); + } } - } } \ No newline at end of file From 2140f77d03aec54944ef56d8d49b2409bb53989c Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sat, 15 Jun 2019 20:59:34 -0400 Subject: [PATCH 03/25] Added Reserve Support, and tested. --- Essentials/pom.xml | 6 + .../com/earth2me/essentials/Essentials.java | 29 +- .../essentials/Reserve_Essentials.java | 1865 +++++++++++++++++ .../essentials/register/payment/Methods.java | 1 + .../register/payment/methods/ReserveEco.java | 289 +++ Essentials/src/plugin.yml | 2 +- pom.xml | 4 + 7 files changed, 2191 insertions(+), 5 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/Reserve_Essentials.java create mode 100644 Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 5d98af0cc34..6ce32ffb4dd 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -48,6 +48,12 @@ + + net.tnemc + Reserve + 0.1.2.0 + provided + net.milkbowl.vault VaultAPI diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index b165ad42394..18e6eae391e 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -17,7 +17,11 @@ */ package com.earth2me.essentials; -import com.earth2me.essentials.commands.*; +import com.earth2me.essentials.commands.EssentialsCommand; +import com.earth2me.essentials.commands.IEssentialsCommand; +import com.earth2me.essentials.commands.NoChargeException; +import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import com.earth2me.essentials.commands.QuietAbortException; import com.earth2me.essentials.items.AbstractItemDb; import com.earth2me.essentials.items.FlatItemDb; import com.earth2me.essentials.items.LegacyItemDb; @@ -35,8 +39,10 @@ import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; -import net.ess3.api.*; +import net.ess3.api.Economy; import net.ess3.api.IEssentials; +import net.ess3.api.IItemDb; +import net.ess3.api.IJails; import net.ess3.api.ISettings; import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; @@ -55,7 +61,11 @@ import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.command.*; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -80,7 +90,14 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -183,6 +200,10 @@ public void onEnable() { } } + if(pm.isPluginEnabled("Reserve")) { + Reserve_Essentials.register(this); + } + for (Method method : Server.class.getDeclaredMethods()) { if (method.getName().endsWith("getOnlinePlayers") && method.getReturnType() == Player[].class) { oldGetOnlinePlayers = method; diff --git a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java new file mode 100644 index 00000000000..7a0575ef417 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java @@ -0,0 +1,1865 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.api.NoLoanPermittedException; +import com.earth2me.essentials.api.UserDoesNotExistException; +import net.ess3.api.Economy; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import net.tnemc.core.economy.currency.Currency; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.math.BigDecimal; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * @author creatorfromhell + */ +public class Reserve_Essentials implements EconomyAPI { + + private Essentials plugin; + + public Reserve_Essentials(Essentials plugin) { + this.plugin = plugin; + } + + public static void register(Essentials plugin) { + //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. + if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + Reserve.instance().registerProvider(new Reserve_Essentials(plugin)); + } + } + + /** + * @return The name of the Economy implementation. + */ + @Override + public String name() { + return "Essentials Economy"; + } + + /** + * @return The version of Reserve the Economy implementation supports. + */ + @Override + public String version() { + return "0.1.2.0"; + } + + //This is our method to convert UUID -> username for use with Essentials' create account methods. + private String getName(UUID identifier) { + final User user = plugin.getUser(identifier); + return ((user == null)? identifier.toString() : user.getName()); + } + + /** + * @return Whether or not this implementation is enabled. + */ + @Override + public boolean enabled() { + return true; + } + + /** + * @return Whether or not this implementation should have a default Vault implementation. + */ + @Override + public boolean vault() { + return false; + } + + /** + * Used to get the plural name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural() { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular() { + return "Dollar"; + } + + /** + * Used to get the plural name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural(String world) { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular(String world) { + return "Dollar"; + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name, String world) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name, String world) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(String identifier) { + return Economy.playerExists(identifier); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(UUID identifier) { + return Economy.playerExists(getName(identifier)); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(String identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(identifier); + } + }); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(UUID identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(getName(identifier)); + } + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(String identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(UUID identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(String identifier) { + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(UUID identifier) { + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(identifier); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(getName(identifier)); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(identifier, amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(identifier, amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(getName(identifier), amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @param currency The {@link Currency} associated with the balance. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world, String currency) { + return Economy.format(amount); + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccounts() { + return false; + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccountsUnder(BigDecimal amount) { + return false; + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccounts() { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { + return CompletableFuture.supplyAsync(()->false); + } +} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index 458501ef1ed..3c5802cba94 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -42,6 +42,7 @@ public class Methods { * Implement all methods along with their respective name & class. */ private static void _init() { + addMethod("Reserve", new com.earth2me.essentials.register.payment.methods.ReserveEco()); addMethod("Vault", new com.earth2me.essentials.register.payment.methods.VaultEco()); } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java new file mode 100644 index 00000000000..6d4d852786f --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -0,0 +1,289 @@ +package com.earth2me.essentials.register.payment.methods; + + +import com.earth2me.essentials.register.payment.Method; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import org.bukkit.plugin.Plugin; + +import java.math.BigDecimal; + +public class ReserveEco implements Method { + + Plugin plugin; + EconomyAPI economy; + + /** + * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin + * Class you must cast it to the correct Plugin, to do so you have to verify the name and or + * version then cast. + *

+ *

+   *  if(method.getName().equalsIgnoreCase("iConomy"))
+   *   iConomy plugin = ((iConomy)method.getPlugin());
+ * + * @return Object + * + * @see #getName() + * @see #getVersion() + */ + @Override + public Plugin getPlugin() { + return plugin; + } + + /** + * Returns the actual name of this method. + * + * @return String Plugin name. + */ + @Override + public String getName() { + return "Reserve"; + } + + public String getProvider() { + return economy == null ? "No Provider" : economy.name(); + } + + /** + * Returns the reported name of this method. + * + * @return String Plugin name. + */ + @Override + public String getLongName() { + return "Reserve Economy: " + getProvider(); + } + + /** + * Returns the actual version of this method. + * + * @return String Plugin version. + */ + @Override + public String getVersion() { + return plugin.getDescription().getVersion(); + } + + /** + * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no + * rounding + * + * @return int for each decimal place + */ + @Override + public int fractionalDigits() { + return 0; + } + + /** + * Formats amounts into this payment methods style of currency display. + * + * @param amount Double + * + * @return String - Formatted Currency Display. + */ + @Override + public String format(double amount) { + return economy.format(BigDecimal.valueOf(amount)); + } + + /** + * Allows the verification of bank API existence in this payment method. + * + * @return boolean + */ + @Override + public boolean hasBanks() { + return false; + } + + /** + * Determines the existence of a bank via name. + * + * @param bank Bank name + * + * @return boolean + * + * @see #hasBanks + */ + @Override + public boolean hasBank(String bank) { + return false; + } + + /** + * Determines the existence of an account via name. + * + * @param name Account name + * + * @return boolean + */ + @Override + public boolean hasAccount(String name) { + return economy.hasAccount(name); + } + + /** + * Check to see if an account name is tied to a bank. + * + * @param bank Bank name + * @param name Account name + * + * @return boolean + */ + @Override + public boolean hasBankAccount(String bank, String name) { + return false; + } + + /** + * Forces an account creation + * + * @param name Account name + * + * @return boolean + */ + @Override + public boolean createAccount(String name) { + return economy.createAccount(name); + } + + /** + * Forces an account creation + * + * @param name Account name + * @param balance Initial account balance + * + * @return boolean + */ + @Override + public boolean createAccount(String name, Double balance) { + return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); + } + + /** + * Returns a MethodAccount class for an account name. + * + * @param name Account name + * + * @return MethodAccount or Null + */ + @Override + public MethodAccount getAccount(String name) { + if(!hasAccount(name)) return null; + return new ReserveAccount(name, economy); + } + + /** + * Returns a MethodBankAccount class for an account name. + * + * @param bank Bank name + * @param name Account name + * + * @return MethodBankAccount or Null + */ + @Override + public MethodBankAccount getBankAccount(String bank, String name) { + return null; + } + + /** + * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for + * the most part. + * + * @param plugin Plugin + * + * @return boolean + */ + @Override + public boolean isCompatible(Plugin plugin) { + try { + EconomyAPI economyAPI = ((Reserve)plugin).economy(); + return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); + } catch (LinkageError | Exception e) { + return false; + } + } + + /** + * Set Plugin data. + * + * @param plugin Plugin + */ + @Override + public void setPlugin(Plugin plugin) { + this.plugin = plugin; + + if(((Reserve)plugin).economyProvided()) { + this.economy = ((Reserve)plugin).economy(); + } + } + + public class ReserveAccount implements MethodAccount { + + private String identifier; + private EconomyAPI economy; + + public ReserveAccount(String identifier, EconomyAPI economy) { + this.identifier = identifier; + this.economy = economy; + } + + @Override + public double balance() { + return economy.getHoldings(identifier).doubleValue(); + } + + @Override + public boolean set(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean add(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + } + + @Override + public boolean subtract(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + } + + @Override + public boolean multiply(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + } + + @Override + public boolean divide(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + } + + @Override + public boolean hasEnough(double amount) { + return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean hasOver(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + } + + @Override + public boolean hasUnder(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean isNegative() { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean remove() { + return economy.deleteAccount(identifier); + } + } +} \ No newline at end of file diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 26add785aef..2f62138add6 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -5,7 +5,7 @@ main: com.earth2me.essentials.Essentials version: ${full.version} website: http://tiny.cc/EssentialsCommands description: Provides an essential, core set of commands for Bukkit. -softdepend: [Vault] +softdepend: [Vault, Reserve] authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Iaccidentally, drtshock, vemacs, SupaHam, md678685] api-version: 1.13 commands: diff --git a/pom.xml b/pom.xml index e036d3b7e57..78193266890 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,10 @@ + + reserve-repo + https://dl.bintray.com/theneweconomy/java/ + ess-repo https://ci.ender.zone/plugin/repository/everything/ From fdf5781a0482e402c6d447441e1e5224974fc711 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 19 Jun 2019 22:41:50 -0400 Subject: [PATCH 04/25] Modified to address PR requested modifications. --- .../com/earth2me/essentials/Essentials.java | 2 +- .../essentials/ReserveEssentials.java | 1865 +++++++++++++++++ .../essentials/Reserve_Essentials.java | 1865 ----------------- .../register/payment/methods/ReserveEco.java | 474 ++--- 4 files changed, 2103 insertions(+), 2103 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/ReserveEssentials.java delete mode 100644 Essentials/src/com/earth2me/essentials/Reserve_Essentials.java diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 18e6eae391e..ec518ad2a94 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -201,7 +201,7 @@ public void onEnable() { } if(pm.isPluginEnabled("Reserve")) { - Reserve_Essentials.register(this); + ReserveEssentials.register(this); } for (Method method : Server.class.getDeclaredMethods()) { diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java new file mode 100644 index 00000000000..bc04eab4664 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -0,0 +1,1865 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.api.NoLoanPermittedException; +import com.earth2me.essentials.api.UserDoesNotExistException; +import net.ess3.api.Economy; +import net.tnemc.core.Reserve; +import net.tnemc.core.economy.EconomyAPI; +import net.tnemc.core.economy.currency.Currency; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.math.BigDecimal; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * @author creatorfromhell + */ +public class ReserveEssentials implements EconomyAPI { + + private Essentials plugin; + + public ReserveEssentials(Essentials plugin) { + this.plugin = plugin; + } + + public static void register(Essentials plugin) { + //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. + if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + Reserve.instance().registerProvider(new ReserveEssentials(plugin)); + } + } + + /** + * @return The name of the Economy implementation. + */ + @Override + public String name() { + return "Essentials Economy"; + } + + /** + * @return The version of Reserve the Economy implementation supports. + */ + @Override + public String version() { + return "0.1.2.0"; + } + + //This is our method to convert UUID -> username for use with Essentials' create account methods. + private String getName(UUID identifier) { + final User user = plugin.getUser(identifier); + return ((user == null)? identifier.toString() : user.getName()); + } + + /** + * @return Whether or not this implementation is enabled. + */ + @Override + public boolean enabled() { + return true; + } + + /** + * @return Whether or not this implementation should have a default Vault implementation. + */ + @Override + public boolean vault() { + return false; + } + + /** + * Used to get the plural name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural() { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular() { + return "Dollar"; + } + + /** + * Used to get the plural name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultPlural(String world) { + return "Dollars"; + } + + /** + * Used to get the singular name of the default currency for a world. + * @param world The world to be used in this check. + * @return The plural name of the default currency. + */ + @Override + public String currencyDefaultSingular(String world) { + return "Dollar"; + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public boolean hasCurrency(String name, String world) { + return true; //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if a {@link Currency} exists with this name. + * @param name The name of the {@link Currency} to search for. + * @param world The name of the {@link World} to check for this {@link Currency} in. + * @return True if the currency exists, else false. + */ + @Override + public CompletableFuture asyncHasCurrency(String name, String world) { + return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(String identifier) { + return Economy.playerExists(identifier); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public boolean hasAccount(UUID identifier) { + return Economy.playerExists(getName(identifier)); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(String identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(identifier); + } + }); + } + + /** + * Checks to see if an account exists for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account exists for this player, else false. + */ + @Override + public CompletableFuture asyncHasAccount(UUID identifier) { + return CompletableFuture.supplyAsync(new Supplier() { + + /** + * Gets a result. + * + * @return a result + */ + @Override + public Boolean get() { + return Economy.playerExists(getName(identifier)); + } + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(String identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public boolean createAccount(UUID identifier) { + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + } + + /** + * Attempts to create an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(identifier); + }); + } + + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was created, else false. + */ + @Override + public CompletableFuture asyncCreateAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + if(hasAccount(identifier)) return false; + return Economy.createNPC(getName(identifier)); + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(String identifier) { + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public boolean deleteAccount(UUID identifier) { + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + } + + /** + * Attempts to delete an account for this identifier. This method should be used for non-player accounts. + * @param identifier The identifier of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(String identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(identifier); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Attempts to delete an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @return True if an account was deleted, else false. + */ + @Override + public CompletableFuture asyncDeleteAccount(UUID identifier) { + return CompletableFuture.supplyAsync(()->{ + try { + Economy.resetBalance(getName(identifier)); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + return true; + }); + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to access this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to access this account. + */ + @Override + public boolean isAccessor(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public boolean canWithdraw(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to withdraw holdings from this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to withdraw holdings from this account. + */ + @Override + public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(String identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, String accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public boolean canDeposit(UUID identifier, UUID accessor) { + return false; + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Determines whether or not a player is able to deposit holdings into this account. + * @param identifier The identifier of the account that is associated with this call. + * @param accessor The identifier of the user attempting to access this account. + * @return Whether or not the player is able to deposit holdings into this account. + */ + @Override + public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(identifier); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier) { + if(hasAccount(identifier)) { + try { + return Economy.getMoneyExact(getName(identifier)); + } catch(UserDoesNotExistException ignore) { } + } + return plugin.getSettings().getStartingBalance(); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(String identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public BigDecimal getHoldings(UUID identifier, String world, String currency) { + return getHoldings(identifier); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to get the balance of an account. + * @param identifier The identifier of the account that is associated with this call. + * @param world The name of the {@link World} associated with the balance. + * @param currency The {@link Currency} associated with the balance. + * @return The balance of the account. + */ + @Override + public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { + return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(identifier, amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount) { + try { + return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); + } catch(UserDoesNotExistException ignore) { + return false; + } + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return hasHoldings(identifier, amount); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to determine if an account has at least an amount of funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to use for this check. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the account has at least the specified amount of funds, otherwise false. + */ + @Override + public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(identifier, amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount) { + if(!hasAccount(identifier)) return false; + try { + Economy.setMoney(getName(identifier), amount); + return true; + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldings(identifier, amount); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to set funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to set from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were set for the account, otherwise false. + */ + @Override + public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + try { + Economy.add(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldings(identifier, amount); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to add funds to an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were added to the account, otherwise false. + */ + @Override + public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to add to this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + */ + @Override + public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(identifier, amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount) { + if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + try { + Economy.substract(getName(identifier), amount); + } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + return false; + } + } + return false; + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldings(identifier, amount); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to remove funds from an account. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were removed from the account, otherwise false. + */ + @Override + public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldings(identifier, amount); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not + * affect an account's funds. + * @param identifier The identifier of the account that is associated with this call. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to transfer funds from one account to another. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if the funds were transferred. + */ + @Override + public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not + * affect an account's funds. + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + } + + /** + * Used to determine if a call to the corresponding transferHoldings method would be successful. + * This method does not affect an account's funds. + * + * @param fromIdentifier The identifier of the account that the holdings will be coming from. + * @param toIdentifier The identifier of the account that the holdings will be going to. + * @param amount The amount you wish to remove from this account. + * @param world The name of the {@link World} associated with the amount. + * @param currency The {@link Currency} associated with the balance. + * + * @return True if a call to the corresponding transferHoldings method would return true, + * otherwise false. + */ + @Override + public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { + return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world) { + return Economy.format(amount); + } + + /** + * Formats a monetary amount into a more text-friendly version. + * @param amount The amount of currency to format. + * @param world The {@link World} in which this format operation is occurring. + * @param currency The {@link Currency} associated with the balance. + * @return The formatted amount. + */ + @Override + public String format(BigDecimal amount, String world, String currency) { + return Economy.format(amount); + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccounts() { + return false; + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public boolean purgeAccountsUnder(BigDecimal amount) { + return false; + } + + /** + * Purges the database of accounts with the default balance. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccounts() { + return CompletableFuture.supplyAsync(()->false); + } + + /** + * Purges the database of accounts with a balance under the specified one. + * @param amount The amount that an account's balance has to be under in order to be removed. + * @return True if the purge was completed successfully. + */ + @Override + public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { + return CompletableFuture.supplyAsync(()->false); + } +} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java b/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java deleted file mode 100644 index 7a0575ef417..00000000000 --- a/Essentials/src/com/earth2me/essentials/Reserve_Essentials.java +++ /dev/null @@ -1,1865 +0,0 @@ -package com.earth2me.essentials; - -import com.earth2me.essentials.api.NoLoanPermittedException; -import com.earth2me.essentials.api.UserDoesNotExistException; -import net.ess3.api.Economy; -import net.tnemc.core.Reserve; -import net.tnemc.core.economy.EconomyAPI; -import net.tnemc.core.economy.currency.Currency; -import org.bukkit.Bukkit; -import org.bukkit.World; - -import java.math.BigDecimal; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** - * @author creatorfromhell - */ -public class Reserve_Essentials implements EconomyAPI { - - private Essentials plugin; - - public Reserve_Essentials(Essentials plugin) { - this.plugin = plugin; - } - - public static void register(Essentials plugin) { - //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { - Reserve.instance().registerProvider(new Reserve_Essentials(plugin)); - } - } - - /** - * @return The name of the Economy implementation. - */ - @Override - public String name() { - return "Essentials Economy"; - } - - /** - * @return The version of Reserve the Economy implementation supports. - */ - @Override - public String version() { - return "0.1.2.0"; - } - - //This is our method to convert UUID -> username for use with Essentials' create account methods. - private String getName(UUID identifier) { - final User user = plugin.getUser(identifier); - return ((user == null)? identifier.toString() : user.getName()); - } - - /** - * @return Whether or not this implementation is enabled. - */ - @Override - public boolean enabled() { - return true; - } - - /** - * @return Whether or not this implementation should have a default Vault implementation. - */ - @Override - public boolean vault() { - return false; - } - - /** - * Used to get the plural name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural() { - return "Dollars"; - } - - /** - * Used to get the singular name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular() { - return "Dollar"; - } - - /** - * Used to get the plural name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural(String world) { - return "Dollars"; - } - - /** - * Used to get the singular name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular(String world) { - return "Dollar"; - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name) { - return true; //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name, String world) { - return true; //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(String identifier) { - return Economy.playerExists(identifier); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(UUID identifier) { - return Economy.playerExists(getName(identifier)); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(identifier); - } - }); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(getName(identifier)); - } - }); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(String identifier) { - if(hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(UUID identifier) { - if(hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - }); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - }); - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(String identifier) { - try { - Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(UUID identifier) { - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ - try { - Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier) { - if(hasAccount(identifier)) { - try { - return Economy.getMoneyExact(identifier); - } catch(UserDoesNotExistException ignore) { } - } - return plugin.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier) { - if(hasAccount(identifier)) { - try { - return Economy.getMoneyExact(getName(identifier)); - } catch(UserDoesNotExistException ignore) { } - } - return plugin.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(identifier, amount); - } catch(UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); - } catch(UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; - try { - Economy.setMoney(identifier, amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; - try { - Economy.setMoney(getName(identifier), amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @param currency The {@link Currency} associated with the balance. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world, String currency) { - return Economy.format(amount); - } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccounts() { - return false; - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccountsUnder(BigDecimal amount) { - return false; - } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(()->false); - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(()->false); - } -} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java index 6d4d852786f..a39c2d02f4a 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -10,280 +10,280 @@ public class ReserveEco implements Method { - Plugin plugin; - EconomyAPI economy; - - /** - * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin - * Class you must cast it to the correct Plugin, to do so you have to verify the name and or - * version then cast. - *

- *

-   *  if(method.getName().equalsIgnoreCase("iConomy"))
-   *   iConomy plugin = ((iConomy)method.getPlugin());
- * - * @return Object - * - * @see #getName() - * @see #getVersion() - */ - @Override - public Plugin getPlugin() { - return plugin; - } - - /** - * Returns the actual name of this method. - * - * @return String Plugin name. - */ - @Override - public String getName() { - return "Reserve"; - } - - public String getProvider() { - return economy == null ? "No Provider" : economy.name(); - } - - /** - * Returns the reported name of this method. - * - * @return String Plugin name. - */ - @Override - public String getLongName() { - return "Reserve Economy: " + getProvider(); - } - - /** - * Returns the actual version of this method. - * - * @return String Plugin version. - */ - @Override - public String getVersion() { - return plugin.getDescription().getVersion(); - } - - /** - * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no - * rounding - * - * @return int for each decimal place - */ - @Override - public int fractionalDigits() { - return 0; - } - - /** - * Formats amounts into this payment methods style of currency display. - * - * @param amount Double - * - * @return String - Formatted Currency Display. - */ - @Override - public String format(double amount) { - return economy.format(BigDecimal.valueOf(amount)); - } - - /** - * Allows the verification of bank API existence in this payment method. - * - * @return boolean - */ - @Override - public boolean hasBanks() { - return false; - } - - /** - * Determines the existence of a bank via name. - * - * @param bank Bank name - * - * @return boolean - * - * @see #hasBanks - */ - @Override - public boolean hasBank(String bank) { - return false; - } - - /** - * Determines the existence of an account via name. - * - * @param name Account name - * - * @return boolean - */ - @Override - public boolean hasAccount(String name) { - return economy.hasAccount(name); - } - - /** - * Check to see if an account name is tied to a bank. - * - * @param bank Bank name - * @param name Account name - * - * @return boolean - */ - @Override - public boolean hasBankAccount(String bank, String name) { - return false; - } - - /** - * Forces an account creation - * - * @param name Account name - * - * @return boolean - */ - @Override - public boolean createAccount(String name) { - return economy.createAccount(name); - } - - /** - * Forces an account creation - * - * @param name Account name - * @param balance Initial account balance - * - * @return boolean - */ - @Override - public boolean createAccount(String name, Double balance) { - return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); - } - - /** - * Returns a MethodAccount class for an account name. - * - * @param name Account name - * - * @return MethodAccount or Null - */ - @Override - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) return null; - return new ReserveAccount(name, economy); - } - - /** - * Returns a MethodBankAccount class for an account name. - * - * @param bank Bank name - * @param name Account name - * - * @return MethodBankAccount or Null - */ - @Override - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - /** - * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for - * the most part. - * - * @param plugin Plugin - * - * @return boolean - */ - @Override - public boolean isCompatible(Plugin plugin) { - try { - EconomyAPI economyAPI = ((Reserve)plugin).economy(); - return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); - } catch (LinkageError | Exception e) { - return false; + Plugin plugin; + EconomyAPI economy; + + /** + * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin + * Class you must cast it to the correct Plugin, to do so you have to verify the name and or + * version then cast. + *

+ *

+     *    if(method.getName().equalsIgnoreCase("iConomy"))
+     *     iConomy plugin = ((iConomy)method.getPlugin());
+ * + * @return Object + * + * @see #getName() + * @see #getVersion() + */ + @Override + public Plugin getPlugin() { + return plugin; } - } - - /** - * Set Plugin data. - * - * @param plugin Plugin - */ - @Override - public void setPlugin(Plugin plugin) { - this.plugin = plugin; - - if(((Reserve)plugin).economyProvided()) { - this.economy = ((Reserve)plugin).economy(); + + /** + * Returns the actual name of this method. + * + * @return String Plugin name. + */ + @Override + public String getName() { + return "Reserve"; } - } - public class ReserveAccount implements MethodAccount { + public String getProvider() { + return economy == null ? "No Provider" : economy.name(); + } - private String identifier; - private EconomyAPI economy; + /** + * Returns the reported name of this method. + * + * @return String Plugin name. + */ + @Override + public String getLongName() { + return "Reserve Economy: " + getProvider(); + } - public ReserveAccount(String identifier, EconomyAPI economy) { - this.identifier = identifier; - this.economy = economy; + /** + * Returns the actual version of this method. + * + * @return String Plugin version. + */ + @Override + public String getVersion() { + return plugin.getDescription().getVersion(); } + /** + * Returns the amount of decimal places that get stored NOTE: it will return -1 if there is no + * rounding + * + * @return int for each decimal place + */ @Override - public double balance() { - return economy.getHoldings(identifier).doubleValue(); + public int fractionalDigits() { + return 0; } + /** + * Formats amounts into this payment methods style of currency display. + * + * @param amount Double + * + * @return String - Formatted Currency Display. + */ @Override - public boolean set(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + public String format(double amount) { + return economy.format(BigDecimal.valueOf(amount)); } + /** + * Allows the verification of bank API existence in this payment method. + * + * @return boolean + */ @Override - public boolean add(double amount) { - return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + public boolean hasBanks() { + return false; } + /** + * Determines the existence of a bank via name. + * + * @param bank Bank name + * + * @return boolean + * + * @see #hasBanks + */ @Override - public boolean subtract(double amount) { - return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + public boolean hasBank(String bank) { + return false; } + /** + * Determines the existence of an account via name. + * + * @param name Account name + * + * @return boolean + */ @Override - public boolean multiply(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + public boolean hasAccount(String name) { + return economy.hasAccount(name); } + /** + * Check to see if an account name is tied to a bank. + * + * @param bank Bank name + * @param name Account name + * + * @return boolean + */ @Override - public boolean divide(double amount) { - return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + public boolean hasBankAccount(String bank, String name) { + return false; } + /** + * Forces an account creation + * + * @param name Account name + * + * @return boolean + */ @Override - public boolean hasEnough(double amount) { - return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + public boolean createAccount(String name) { + return economy.createAccount(name); } + /** + * Forces an account creation + * + * @param name Account name + * @param balance Initial account balance + * + * @return boolean + */ @Override - public boolean hasOver(double amount) { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + public boolean createAccount(String name, Double balance) { + return economy.createAccount(name) && economy.addHoldings(name, BigDecimal.valueOf(balance)); } + /** + * Returns a MethodAccount class for an account name. + * + * @param name Account name + * + * @return MethodAccount or Null + */ @Override - public boolean hasUnder(double amount) { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + public MethodAccount getAccount(String name) { + if(!hasAccount(name)) return null; + return new ReserveAccount(name, economy); } + /** + * Returns a MethodBankAccount class for an account name. + * + * @param bank Bank name + * @param name Account name + * + * @return MethodBankAccount or Null + */ @Override - public boolean isNegative() { - return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + public MethodBankAccount getBankAccount(String bank, String name) { + return null; } + /** + * Checks to verify the compatibility between this Method and a plugin. Internal usage only, for + * the most part. + * + * @param plugin Plugin + * + * @return boolean + */ @Override - public boolean remove() { - return economy.deleteAccount(identifier); + public boolean isCompatible(Plugin plugin) { + try { + EconomyAPI economyAPI = ((Reserve)plugin).economy(); + return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); + } catch (LinkageError | Exception e) { + return false; + } + } + + /** + * Set Plugin data. + * + * @param plugin Plugin + */ + @Override + public void setPlugin(Plugin plugin) { + this.plugin = plugin; + + if(((Reserve)plugin).economyProvided()) { + this.economy = ((Reserve)plugin).economy(); + } + } + + public class ReserveAccount implements MethodAccount { + + private String identifier; + private EconomyAPI economy; + + public ReserveAccount(String identifier, EconomyAPI economy) { + this.identifier = identifier; + this.economy = economy; + } + + @Override + public double balance() { + return economy.getHoldings(identifier).doubleValue(); + } + + @Override + public boolean set(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean add(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).add(BigDecimal.valueOf(amount))); + } + + @Override + public boolean subtract(double amount) { + return economy.setHoldings(identifier, economy.getHoldings(identifier).subtract(BigDecimal.valueOf(amount))); + } + + @Override + public boolean multiply(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() * amount)); + } + + @Override + public boolean divide(double amount) { + return economy.setHoldings(identifier, BigDecimal.valueOf(economy.getHoldings(identifier).doubleValue() / amount)); + } + + @Override + public boolean hasEnough(double amount) { + return economy.hasHoldings(identifier, BigDecimal.valueOf(amount)); + } + + @Override + public boolean hasOver(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) > 0; + } + + @Override + public boolean hasUnder(double amount) { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean isNegative() { + return economy.getHoldings(identifier).compareTo(BigDecimal.ZERO) < 0; + } + + @Override + public boolean remove() { + return economy.deleteAccount(identifier); + } } - } } \ No newline at end of file From 5046a8ca4e08f9693dd9c3c56cddb6c9b446f196 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 5 Aug 2019 16:42:19 +0100 Subject: [PATCH 05/25] Minor formatting and organisation fixes --- .../com/earth2me/essentials/Essentials.java | 28 +-- .../register/payment/methods/ReserveEco.java | 12 +- .../{ => services}/ReserveEssentials.java | 214 +++++++++--------- 3 files changed, 124 insertions(+), 130 deletions(-) rename Essentials/src/com/earth2me/essentials/{ => services}/ReserveEssentials.java (90%) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index ec518ad2a94..ec15d1854f9 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -17,17 +17,14 @@ */ package com.earth2me.essentials; -import com.earth2me.essentials.commands.EssentialsCommand; -import com.earth2me.essentials.commands.IEssentialsCommand; -import com.earth2me.essentials.commands.NoChargeException; -import com.earth2me.essentials.commands.NotEnoughArgumentsException; -import com.earth2me.essentials.commands.QuietAbortException; +import com.earth2me.essentials.commands.*; import com.earth2me.essentials.items.AbstractItemDb; import com.earth2me.essentials.items.FlatItemDb; import com.earth2me.essentials.items.LegacyItemDb; import com.earth2me.essentials.metrics.Metrics; import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; +import com.earth2me.essentials.services.ReserveEssentials; import com.earth2me.essentials.signs.SignBlockListener; import com.earth2me.essentials.signs.SignEntityListener; import com.earth2me.essentials.signs.SignPlayerListener; @@ -39,11 +36,9 @@ import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; -import net.ess3.api.Economy; import net.ess3.api.IEssentials; -import net.ess3.api.IItemDb; -import net.ess3.api.IJails; import net.ess3.api.ISettings; +import net.ess3.api.*; import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; import net.ess3.nms.SpawnerProvider; @@ -61,11 +56,7 @@ import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.TabCompleter; +import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -90,14 +81,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -200,7 +184,7 @@ public void onEnable() { } } - if(pm.isPluginEnabled("Reserve")) { + if (pm.isPluginEnabled("Reserve")) { ReserveEssentials.register(this); } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java index a39c2d02f4a..5c3cff07274 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -19,7 +19,7 @@ public class ReserveEco implements Method { * version then cast. *

*

-     *    if(method.getName().equalsIgnoreCase("iConomy"))
+     *    if (method.getName().equalsIgnoreCase("iConomy"))
      *     iConomy plugin = ((iConomy)method.getPlugin());
* * @return Object @@ -74,7 +74,7 @@ public String getVersion() { */ @Override public int fractionalDigits() { - return 0; + return -1; } /** @@ -172,7 +172,7 @@ public boolean createAccount(String name, Double balance) { */ @Override public MethodAccount getAccount(String name) { - if(!hasAccount(name)) return null; + if (!hasAccount(name)) return null; return new ReserveAccount(name, economy); } @@ -200,7 +200,7 @@ public MethodBankAccount getBankAccount(String bank, String name) { @Override public boolean isCompatible(Plugin plugin) { try { - EconomyAPI economyAPI = ((Reserve)plugin).economy(); + EconomyAPI economyAPI = ((Reserve) plugin).economy(); return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); } catch (LinkageError | Exception e) { return false; @@ -216,8 +216,8 @@ public boolean isCompatible(Plugin plugin) { public void setPlugin(Plugin plugin) { this.plugin = plugin; - if(((Reserve)plugin).economyProvided()) { - this.economy = ((Reserve)plugin).economy(); + if (((Reserve) plugin).economyProvided()) { + this.economy = ((Reserve) plugin).economy(); } } diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java similarity index 90% rename from Essentials/src/com/earth2me/essentials/ReserveEssentials.java rename to Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index bc04eab4664..6175d04d626 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -1,12 +1,13 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.services; +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import net.ess3.api.Economy; import net.tnemc.core.Reserve; import net.tnemc.core.economy.EconomyAPI; import net.tnemc.core.economy.currency.Currency; -import org.bukkit.Bukkit; import org.bukkit.World; import java.math.BigDecimal; @@ -15,20 +16,29 @@ import java.util.function.Supplier; /** - * @author creatorfromhell + * Reserve economy provider implementation for EssentialsX. + * @author creatorfromhell */ public class ReserveEssentials implements EconomyAPI { - private Essentials plugin; + private final Essentials ess; - public ReserveEssentials(Essentials plugin) { - this.plugin = plugin; + private ReserveEssentials(Essentials ess) { + this.ess = ess; } - public static void register(Essentials plugin) { - //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { - Reserve.instance().registerProvider(new ReserveEssentials(plugin)); + /** + * Register the provider if no other economy is available. + * + * @param ess The Essentials plugin instance + */ + public static void register(Essentials ess) { + Reserve reserve = Reserve.instance(); + + // Check to see if there is an economy provider already registered. + // If so, the existing provider should take priority + if (!reserve.economyProvided()) { + Reserve.instance().registerProvider(new ReserveEssentials(ess)); } } @@ -50,8 +60,8 @@ public String version() { //This is our method to convert UUID -> username for use with Essentials' create account methods. private String getName(UUID identifier) { - final User user = plugin.getUser(identifier); - return ((user == null)? identifier.toString() : user.getName()); + final User user = ess.getUser(identifier); + return user == null ? identifier.toString() : user.getName(); } /** @@ -136,7 +146,7 @@ public boolean hasCurrency(String name, String world) { */ @Override public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> true); //Always return true here as Essentials only supports one currency. } /** @@ -147,7 +157,7 @@ public CompletableFuture asyncHasCurrency(String name) { */ @Override public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> true); //Always return true here as Essentials only supports one currency. } /** @@ -219,7 +229,7 @@ public Boolean get() { */ @Override public boolean createAccount(String identifier) { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(identifier); } @@ -230,7 +240,7 @@ public boolean createAccount(String identifier) { */ @Override public boolean createAccount(UUID identifier) { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(getName(identifier)); } @@ -241,8 +251,8 @@ public boolean createAccount(UUID identifier) { */ @Override public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; + return CompletableFuture.supplyAsync(() -> { + if (hasAccount(identifier)) return false; return Economy.createNPC(identifier); }); } @@ -254,8 +264,8 @@ public CompletableFuture asyncCreateAccount(String identifier) { */ @Override public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ - if(hasAccount(identifier)) return false; + return CompletableFuture.supplyAsync(() -> { + if (hasAccount(identifier)) return false; return Economy.createNPC(getName(identifier)); }); } @@ -297,7 +307,7 @@ public boolean deleteAccount(UUID identifier) { */ @Override public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(identifier); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -314,7 +324,7 @@ public CompletableFuture asyncDeleteAccount(String identifier) { */ @Override public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(getName(identifier)); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -420,7 +430,7 @@ public boolean canWithdraw(UUID identifier, UUID accessor) { */ @Override public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -431,7 +441,7 @@ public CompletableFuture asyncCanWithdraw(String identifier, String acc */ @Override public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -442,7 +452,7 @@ public CompletableFuture asyncCanWithdraw(String identifier, UUID acces */ @Override public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -453,7 +463,7 @@ public CompletableFuture asyncCanWithdraw(UUID identifier, String acces */ @Override public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -508,7 +518,7 @@ public boolean canDeposit(UUID identifier, UUID accessor) { */ @Override public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -519,7 +529,7 @@ public CompletableFuture asyncCanDeposit(String identifier, String acce */ @Override public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -530,7 +540,7 @@ public CompletableFuture asyncCanDeposit(String identifier, UUID access */ @Override public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -541,7 +551,7 @@ public CompletableFuture asyncCanDeposit(UUID identifier, String access */ @Override public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -551,12 +561,12 @@ public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor */ @Override public BigDecimal getHoldings(String identifier) { - if(hasAccount(identifier)) { + if (hasAccount(identifier)) { try { return Economy.getMoneyExact(identifier); } catch(UserDoesNotExistException ignore) { } } - return plugin.getSettings().getStartingBalance(); + return ess.getSettings().getStartingBalance(); } /** @@ -566,12 +576,12 @@ public BigDecimal getHoldings(String identifier) { */ @Override public BigDecimal getHoldings(UUID identifier) { - if(hasAccount(identifier)) { + if (hasAccount(identifier)) { try { return Economy.getMoneyExact(getName(identifier)); } catch(UserDoesNotExistException ignore) { } } - return plugin.getSettings().getStartingBalance(); + return ess.getSettings().getStartingBalance(); } /** @@ -627,7 +637,7 @@ public BigDecimal getHoldings(UUID identifier, String world, String currency) { */ @Override public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -637,7 +647,7 @@ public CompletableFuture asyncGetHoldings(String identifier) { */ @Override public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -648,7 +658,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier) { */ @Override public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -659,7 +669,7 @@ public CompletableFuture asyncGetHoldings(String identifier, String */ @Override public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -671,7 +681,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier, String wo */ @Override public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -683,7 +693,7 @@ public CompletableFuture asyncGetHoldings(String identifier, String */ @Override public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -774,7 +784,7 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -785,7 +795,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -797,7 +807,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -809,7 +819,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -822,7 +832,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -835,7 +845,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -846,7 +856,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public boolean setHoldings(String identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; + if (!hasAccount(identifier)) return false; try { Economy.setMoney(identifier, amount); return true; @@ -863,7 +873,7 @@ public boolean setHoldings(String identifier, BigDecimal amount) { */ @Override public boolean setHoldings(UUID identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; + if (!hasAccount(identifier)) return false; try { Economy.setMoney(getName(identifier), amount); return true; @@ -930,7 +940,7 @@ public boolean setHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -941,7 +951,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -953,7 +963,7 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -965,7 +975,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -978,7 +988,7 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -991,7 +1001,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -1002,7 +1012,7 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public boolean addHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { try { Economy.add(identifier, amount); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -1020,7 +1030,7 @@ public boolean addHoldings(String identifier, BigDecimal amount) { */ @Override public boolean addHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { try { Economy.add(getName(identifier), amount); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -1088,7 +1098,7 @@ public boolean addHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1099,7 +1109,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1111,7 +1121,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1123,7 +1133,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1136,7 +1146,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1149,7 +1159,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1161,7 +1171,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; } /** @@ -1173,7 +1183,7 @@ public boolean canAddHoldings(String identifier, BigDecimal amount) { */ @Override public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; } /** @@ -1239,7 +1249,7 @@ public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1251,7 +1261,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1264,7 +1274,7 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1277,7 +1287,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1291,7 +1301,7 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1305,7 +1315,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1316,7 +1326,7 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public boolean removeHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { try { Economy.substract(identifier, amount); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -1334,7 +1344,7 @@ public boolean removeHoldings(String identifier, BigDecimal amount) { */ @Override public boolean removeHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { try { Economy.substract(getName(identifier), amount); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -1402,7 +1412,7 @@ public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1413,7 +1423,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1425,7 +1435,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1437,7 +1447,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1450,7 +1460,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1463,7 +1473,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1475,7 +1485,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; } /** @@ -1487,7 +1497,7 @@ public boolean canRemoveHoldings(String identifier, BigDecimal amount) { */ @Override public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; } /** @@ -1553,7 +1563,7 @@ public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String worl */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1565,7 +1575,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1578,7 +1588,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1591,7 +1601,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1605,7 +1615,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1619,7 +1629,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1633,7 +1643,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1646,7 +1656,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1660,7 +1670,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1672,7 +1682,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1685,7 +1695,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1699,7 +1709,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1712,7 +1722,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1726,7 +1736,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1741,7 +1751,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1754,7 +1764,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1767,11 +1777,11 @@ public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, * @param world The name of the {@link World} associated with the amount. * * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. + * otherwise false. */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1785,11 +1795,11 @@ public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, * @param currency The {@link Currency} associated with the balance. * * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. + * otherwise false. */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1850,7 +1860,7 @@ public boolean purgeAccountsUnder(BigDecimal amount) { */ @Override public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -1860,6 +1870,6 @@ public CompletableFuture asyncPurgeAccounts() { */ @Override public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } } \ No newline at end of file From b0d42101ea53b0691b1d098ca6a46d95bf883109 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Mon, 30 Dec 2019 18:33:41 -0500 Subject: [PATCH 06/25] Modified to suite requested changes. --- .../essentials/ReserveEssentials.java | 69 +++++-------------- pom.xml | 8 +-- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index bc04eab4664..3bb9b58f4d0 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -12,7 +12,6 @@ import java.math.BigDecimal; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; /** * @author creatorfromhell @@ -136,7 +135,7 @@ public boolean hasCurrency(String name, String world) { */ @Override public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(()->hasCurrency(name)); //Always return true here as Essentials only supports one currency. } /** @@ -147,13 +146,13 @@ public CompletableFuture asyncHasCurrency(String name) { */ @Override public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(()->true); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(()->hasCurrency(name, world)); //Always return true here as Essentials only supports one currency. } /** * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. + * @return True if an account exists for this identifier, else false. */ @Override public boolean hasAccount(String identifier) { @@ -163,7 +162,7 @@ public boolean hasAccount(String identifier) { /** * Checks to see if an account exists for this identifier. This method should be used for player accounts. * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. + * @return True if an account exists for this identifier, else false. */ @Override public boolean hasAccount(UUID identifier) { @@ -173,43 +172,21 @@ public boolean hasAccount(UUID identifier) { /** * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. + * @return True if an account exists for this identifier, else false. */ @Override public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(identifier); - } - }); + return CompletableFuture.supplyAsync(()->Economy.playerExists(identifier)); } /** * Checks to see if an account exists for this identifier. This method should be used for player accounts. * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. + * @return True if an account exists for this identifier, else false. */ @Override public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(getName(identifier)); - } - }); + return CompletableFuture.supplyAsync(()->Economy.playerExists(getName(identifier))); } /** @@ -332,7 +309,7 @@ public CompletableFuture asyncDeleteAccount(UUID identifier) { */ @Override public boolean isAccessor(String identifier, String accessor) { - return false; + return identifier.equalsIgnoreCase(accessor); } /** @@ -343,7 +320,7 @@ public boolean isAccessor(String identifier, String accessor) { */ @Override public boolean isAccessor(String identifier, UUID accessor) { - return false; + return isAccessor(identifier, getName(accessor)); } /** @@ -354,7 +331,7 @@ public boolean isAccessor(String identifier, UUID accessor) { */ @Override public boolean isAccessor(UUID identifier, String accessor) { - return false; + return isAccessor(getName(identifier), accessor); } /** @@ -365,7 +342,7 @@ public boolean isAccessor(UUID identifier, String accessor) { */ @Override public boolean isAccessor(UUID identifier, UUID accessor) { - return false; + return isAccessor(getName(identifier), getName(accessor)); } /** @@ -846,7 +823,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public boolean setHoldings(String identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; + if(!hasAccount(identifier) && !createAccount(identifier)) return false; try { Economy.setMoney(identifier, amount); return true; @@ -863,7 +840,7 @@ public boolean setHoldings(String identifier, BigDecimal amount) { */ @Override public boolean setHoldings(UUID identifier, BigDecimal amount) { - if(!hasAccount(identifier)) return false; + if(!hasAccount(identifier) && !createAccount(identifier)) return false; try { Economy.setMoney(getName(identifier), amount); return true; @@ -1020,14 +997,7 @@ public boolean addHoldings(String identifier, BigDecimal amount) { */ @Override public boolean addHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; + return addHoldings(getName(identifier), amount); } /** @@ -1334,14 +1304,7 @@ public boolean removeHoldings(String identifier, BigDecimal amount) { */ @Override public boolean removeHoldings(UUID identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; + return removeHoldings(getName(identifier), amount); } /** diff --git a/pom.xml b/pom.xml index d8500b6748d..3abfd23a480 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,6 @@ - - reserve-repo - https://dl.bintray.com/theneweconomy/java/ - ess-repo https://ci.ender.zone/plugin/repository/everything/ @@ -39,6 +35,10 @@ paper-repo https://papermc.io/repo/repository/maven-public/ + + reserve-repo + https://dl.bintray.com/theneweconomy/java/ + From ee7c3792b4e6e0c70fc6eb95b5fa5d1cb7d5f3ce Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Mon, 30 Dec 2019 18:37:31 -0500 Subject: [PATCH 07/25] Formatting fixes. --- .../essentials/ReserveEssentials.java | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index 3bb9b58f4d0..d783cb13d96 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -135,7 +135,7 @@ public boolean hasCurrency(String name, String world) { */ @Override public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(()->hasCurrency(name)); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> hasCurrency(name)); //Always return true here as Essentials only supports one currency. } /** @@ -146,7 +146,7 @@ public CompletableFuture asyncHasCurrency(String name) { */ @Override public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(()->hasCurrency(name, world)); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> hasCurrency(name, world)); //Always return true here as Essentials only supports one currency. } /** @@ -176,7 +176,7 @@ public boolean hasAccount(UUID identifier) { */ @Override public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(()->Economy.playerExists(identifier)); + return CompletableFuture.supplyAsync(() -> Economy.playerExists(identifier)); } /** @@ -186,7 +186,7 @@ public CompletableFuture asyncHasAccount(String identifier) { */ @Override public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->Economy.playerExists(getName(identifier))); + return CompletableFuture.supplyAsync(() -> Economy.playerExists(getName(identifier))); } /** @@ -218,7 +218,7 @@ public boolean createAccount(UUID identifier) { */ @Override public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { if(hasAccount(identifier)) return false; return Economy.createNPC(identifier); }); @@ -231,7 +231,7 @@ public CompletableFuture asyncCreateAccount(String identifier) { */ @Override public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { if(hasAccount(identifier)) return false; return Economy.createNPC(getName(identifier)); }); @@ -274,7 +274,7 @@ public boolean deleteAccount(UUID identifier) { */ @Override public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(identifier); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -291,7 +291,7 @@ public CompletableFuture asyncDeleteAccount(String identifier) { */ @Override public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(()->{ + return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(getName(identifier)); } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { @@ -397,7 +397,7 @@ public boolean canWithdraw(UUID identifier, UUID accessor) { */ @Override public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -408,7 +408,7 @@ public CompletableFuture asyncCanWithdraw(String identifier, String acc */ @Override public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -419,7 +419,7 @@ public CompletableFuture asyncCanWithdraw(String identifier, UUID acces */ @Override public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -430,7 +430,7 @@ public CompletableFuture asyncCanWithdraw(UUID identifier, String acces */ @Override public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -485,7 +485,7 @@ public boolean canDeposit(UUID identifier, UUID accessor) { */ @Override public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -496,7 +496,7 @@ public CompletableFuture asyncCanDeposit(String identifier, String acce */ @Override public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -507,7 +507,7 @@ public CompletableFuture asyncCanDeposit(String identifier, UUID access */ @Override public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -518,7 +518,7 @@ public CompletableFuture asyncCanDeposit(UUID identifier, String access */ @Override public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -604,7 +604,7 @@ public BigDecimal getHoldings(UUID identifier, String world, String currency) { */ @Override public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -614,7 +614,7 @@ public CompletableFuture asyncGetHoldings(String identifier) { */ @Override public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -625,7 +625,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier) { */ @Override public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -636,7 +636,7 @@ public CompletableFuture asyncGetHoldings(String identifier, String */ @Override public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -648,7 +648,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier, String wo */ @Override public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -660,7 +660,7 @@ public CompletableFuture asyncGetHoldings(String identifier, String */ @Override public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(()->getHoldings(identifier)); + return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); } /** @@ -751,7 +751,7 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -762,7 +762,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -774,7 +774,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -786,7 +786,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -799,7 +799,7 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -812,7 +812,7 @@ public CompletableFuture asyncHasHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->hasHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); } /** @@ -907,7 +907,7 @@ public boolean setHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -918,7 +918,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -930,7 +930,7 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -942,7 +942,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -955,7 +955,7 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -968,7 +968,7 @@ public CompletableFuture asyncSetHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->setHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); } /** @@ -1058,7 +1058,7 @@ public boolean addHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1069,7 +1069,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1081,7 +1081,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1093,7 +1093,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1106,7 +1106,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1119,7 +1119,7 @@ public CompletableFuture asyncAddHoldings(String identifier, BigDecimal */ @Override public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->addHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); } /** @@ -1209,7 +1209,7 @@ public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1221,7 +1221,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1234,7 +1234,7 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1247,7 +1247,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1261,7 +1261,7 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1275,7 +1275,7 @@ public CompletableFuture asyncCanAddHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canAddHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); } /** @@ -1365,7 +1365,7 @@ public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1376,7 +1376,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1388,7 +1388,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1400,7 +1400,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1413,7 +1413,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1426,7 +1426,7 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci */ @Override public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->removeHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); } /** @@ -1516,7 +1516,7 @@ public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String worl */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1528,7 +1528,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1541,7 +1541,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1554,7 +1554,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1568,7 +1568,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1582,7 +1582,7 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD */ @Override public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canRemoveHoldings(identifier, amount)); + return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); } /** @@ -1596,7 +1596,7 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1609,7 +1609,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1623,7 +1623,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1635,7 +1635,7 @@ public CompletableFuture asyncTransferHoldings(String fromIdentifier, S */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1648,7 +1648,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1662,7 +1662,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1675,7 +1675,7 @@ public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUI */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1689,7 +1689,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1704,7 +1704,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1717,7 +1717,7 @@ public CompletableFuture asyncCanTransferHoldings(String fromIdentifier */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); } /** @@ -1734,7 +1734,7 @@ public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); } /** @@ -1752,7 +1752,7 @@ public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, */ @Override public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(()->canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); } /** @@ -1813,7 +1813,7 @@ public boolean purgeAccountsUnder(BigDecimal amount) { */ @Override public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } /** @@ -1823,6 +1823,6 @@ public CompletableFuture asyncPurgeAccounts() { */ @Override public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(()->false); + return CompletableFuture.supplyAsync(() -> false); } } \ No newline at end of file From 1211f31eb7d4f4168fc3bb2ff8ea5eaed7b056b9 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Mon, 30 Dec 2019 22:32:12 -0500 Subject: [PATCH 08/25] Localize currency names --- .../earth2me/essentials/ReserveEssentials.java | 16 +++++++++------- Essentials/src/messages.properties | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index d783cb13d96..55fe6927bee 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -13,6 +13,8 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; +import static com.earth2me.essentials.I18n.tl; + /** * @author creatorfromhell */ @@ -75,7 +77,7 @@ public boolean vault() { */ @Override public String currencyDefaultPlural() { - return "Dollars"; + return tl("moneyPlural"); } /** @@ -84,7 +86,7 @@ public String currencyDefaultPlural() { */ @Override public String currencyDefaultSingular() { - return "Dollar"; + return tl("moneySingular"); } /** @@ -94,7 +96,7 @@ public String currencyDefaultSingular() { */ @Override public String currencyDefaultPlural(String world) { - return "Dollars"; + return tl("moneyPlural"); } /** @@ -104,7 +106,7 @@ public String currencyDefaultPlural(String world) { */ @Override public String currencyDefaultSingular(String world) { - return "Dollar"; + return tl("moneySingular"); } /** @@ -114,7 +116,7 @@ public String currencyDefaultSingular(String world) { */ @Override public boolean hasCurrency(String name) { - return true; //Always return true here as Essentials only supports one currency. + return name.equalsIgnoreCase(tl("moneySingular")); //Always return true here as Essentials only supports one currency. } /** @@ -125,7 +127,7 @@ public boolean hasCurrency(String name) { */ @Override public boolean hasCurrency(String name, String world) { - return true; //Always return true here as Essentials only supports one currency. + return name.equalsIgnoreCase(tl("moneySingular")); //Always return true here as Essentials only supports one currency. } /** @@ -309,7 +311,7 @@ public CompletableFuture asyncDeleteAccount(UUID identifier) { */ @Override public boolean isAccessor(String identifier, String accessor) { - return identifier.equalsIgnoreCase(accessor); + return identifier.equals(accessor); } /** diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 84f3207f017..b4a555aa05d 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -293,6 +293,8 @@ mobsAvailable=\u00a76Mobs\:\u00a7r {0} mobSpawnError=\u00a74Error while changing mob spawner. mobSpawnLimit=Mob quantity limited to server limit. mobSpawnTarget=\u00a74Target block must be a mob spawner. +moneySingular=dollar +moneyPlural=dollars moneyRecievedFrom=\u00a7a{0}\u00a76 has been received from\u00a7a {1}\u00a76. moneySentTo=\u00a7a{0} has been sent to {1}. month=month From 4022d9f739741461e7bf1efab1af6921f718f9ba Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Mon, 30 Dec 2019 22:33:22 -0500 Subject: [PATCH 09/25] Remove outdated comments. --- .../src/com/earth2me/essentials/ReserveEssentials.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index 55fe6927bee..6defff2d484 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -116,7 +116,7 @@ public String currencyDefaultSingular(String world) { */ @Override public boolean hasCurrency(String name) { - return name.equalsIgnoreCase(tl("moneySingular")); //Always return true here as Essentials only supports one currency. + return name.equalsIgnoreCase(tl("moneySingular")); } /** @@ -127,7 +127,7 @@ public boolean hasCurrency(String name) { */ @Override public boolean hasCurrency(String name, String world) { - return name.equalsIgnoreCase(tl("moneySingular")); //Always return true here as Essentials only supports one currency. + return name.equalsIgnoreCase(tl("moneySingular")); } /** @@ -137,7 +137,7 @@ public boolean hasCurrency(String name, String world) { */ @Override public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(() -> hasCurrency(name)); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> hasCurrency(name)); } /** @@ -148,7 +148,7 @@ public CompletableFuture asyncHasCurrency(String name) { */ @Override public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(() -> hasCurrency(name, world)); //Always return true here as Essentials only supports one currency. + return CompletableFuture.supplyAsync(() -> hasCurrency(name, world)); } /** From a49e414437cf87b690b1d42a4f3dcadd120916e8 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Mon, 30 Dec 2019 22:40:14 -0500 Subject: [PATCH 10/25] reorder new strings for alphabetical correctness --- Essentials/src/messages.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index b4a555aa05d..45cd0e654c3 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -293,10 +293,10 @@ mobsAvailable=\u00a76Mobs\:\u00a7r {0} mobSpawnError=\u00a74Error while changing mob spawner. mobSpawnLimit=Mob quantity limited to server limit. mobSpawnTarget=\u00a74Target block must be a mob spawner. -moneySingular=dollar -moneyPlural=dollars moneyRecievedFrom=\u00a7a{0}\u00a76 has been received from\u00a7a {1}\u00a76. moneySentTo=\u00a7a{0} has been sent to {1}. +moneySingular=dollar +moneyPlural=dollars month=month months=months moreThanZero=\u00a74Quantities must be greater than 0. From 43fbcc1035527956cdab0d6ef33ea391df279886 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Tue, 31 Dec 2019 10:26:38 -0500 Subject: [PATCH 11/25] Styling fixes, and pom update. --- .../essentials/ReserveEssentials.java | 66 +++++++++---------- pom.xml | 4 -- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index 6defff2d484..b150ffdaaa6 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -20,15 +20,15 @@ */ public class ReserveEssentials implements EconomyAPI { - private Essentials plugin; + private final Essentials ess; public ReserveEssentials(Essentials plugin) { - this.plugin = plugin; + this.ess = plugin; } public static void register(Essentials plugin) { //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if(!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + if (!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { Reserve.instance().registerProvider(new ReserveEssentials(plugin)); } } @@ -38,7 +38,7 @@ public static void register(Essentials plugin) { */ @Override public String name() { - return "Essentials Economy"; + return "EssentialsX"; } /** @@ -51,7 +51,7 @@ public String version() { //This is our method to convert UUID -> username for use with Essentials' create account methods. private String getName(UUID identifier) { - final User user = plugin.getUser(identifier); + final User user = ess.getUser(identifier); return ((user == null)? identifier.toString() : user.getName()); } @@ -198,7 +198,7 @@ public CompletableFuture asyncHasAccount(UUID identifier) { */ @Override public boolean createAccount(String identifier) { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(identifier); } @@ -209,7 +209,7 @@ public boolean createAccount(String identifier) { */ @Override public boolean createAccount(UUID identifier) { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(getName(identifier)); } @@ -221,7 +221,7 @@ public boolean createAccount(UUID identifier) { @Override public CompletableFuture asyncCreateAccount(String identifier) { return CompletableFuture.supplyAsync(() -> { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(identifier); }); } @@ -234,7 +234,7 @@ public CompletableFuture asyncCreateAccount(String identifier) { @Override public CompletableFuture asyncCreateAccount(UUID identifier) { return CompletableFuture.supplyAsync(() -> { - if(hasAccount(identifier)) return false; + if (hasAccount(identifier)) return false; return Economy.createNPC(getName(identifier)); }); } @@ -248,7 +248,7 @@ public CompletableFuture asyncCreateAccount(UUID identifier) { public boolean deleteAccount(String identifier) { try { Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } return true; @@ -263,7 +263,7 @@ public boolean deleteAccount(String identifier) { public boolean deleteAccount(UUID identifier) { try { Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } return true; @@ -279,7 +279,7 @@ public CompletableFuture asyncDeleteAccount(String identifier) { return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } return true; @@ -296,7 +296,7 @@ public CompletableFuture asyncDeleteAccount(UUID identifier) { return CompletableFuture.supplyAsync(() -> { try { Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } return true; @@ -530,12 +530,12 @@ public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor */ @Override public BigDecimal getHoldings(String identifier) { - if(hasAccount(identifier)) { + if (hasAccount(identifier)) { try { return Economy.getMoneyExact(identifier); - } catch(UserDoesNotExistException ignore) { } + } catch (UserDoesNotExistException ignore) { } } - return plugin.getSettings().getStartingBalance(); + return ess.getSettings().getStartingBalance(); } /** @@ -545,12 +545,12 @@ public BigDecimal getHoldings(String identifier) { */ @Override public BigDecimal getHoldings(UUID identifier) { - if(hasAccount(identifier)) { + if (hasAccount(identifier)) { try { return Economy.getMoneyExact(getName(identifier)); - } catch(UserDoesNotExistException ignore) { } + } catch (UserDoesNotExistException ignore) { } } - return plugin.getSettings().getStartingBalance(); + return ess.getSettings().getStartingBalance(); } /** @@ -675,7 +675,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier, String wo public boolean hasHoldings(String identifier, BigDecimal amount) { try { return hasAccount(identifier) && Economy.hasEnough(identifier, amount); - } catch(UserDoesNotExistException ignore) { + } catch (UserDoesNotExistException ignore) { return false; } } @@ -690,7 +690,7 @@ public boolean hasHoldings(String identifier, BigDecimal amount) { public boolean hasHoldings(UUID identifier, BigDecimal amount) { try { return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); - } catch(UserDoesNotExistException ignore) { + } catch (UserDoesNotExistException ignore) { return false; } } @@ -825,11 +825,11 @@ public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal a */ @Override public boolean setHoldings(String identifier, BigDecimal amount) { - if(!hasAccount(identifier) && !createAccount(identifier)) return false; + if (!hasAccount(identifier) && !createAccount(identifier)) return false; try { Economy.setMoney(identifier, amount); return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } } @@ -842,11 +842,11 @@ public boolean setHoldings(String identifier, BigDecimal amount) { */ @Override public boolean setHoldings(UUID identifier, BigDecimal amount) { - if(!hasAccount(identifier) && !createAccount(identifier)) return false; + if (!hasAccount(identifier) && !createAccount(identifier)) return false; try { Economy.setMoney(getName(identifier), amount); return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } } @@ -981,10 +981,10 @@ public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal a */ @Override public boolean addHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0) { + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { try { Economy.add(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } } @@ -1133,7 +1133,7 @@ public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal a */ @Override public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; } /** @@ -1145,7 +1145,7 @@ public boolean canAddHoldings(String identifier, BigDecimal amount) { */ @Override public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(plugin.getSettings().getMaxMoney()) <= 0; + return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; } /** @@ -1288,10 +1288,10 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima */ @Override public boolean removeHoldings(String identifier, BigDecimal amount) { - if(getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0) { + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { try { Economy.substract(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { + } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { return false; } } @@ -1440,7 +1440,7 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima */ @Override public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; } /** @@ -1452,7 +1452,7 @@ public boolean canRemoveHoldings(String identifier, BigDecimal amount) { */ @Override public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(plugin.getSettings().getMinMoney()) >= 0; + return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; } /** diff --git a/pom.xml b/pom.xml index 06b337a0b1e..b61ce202313 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,6 @@ - - reserve-repo - https://dl.bintray.com/theneweconomy/java/ - ess-repo https://ci.ender.zone/plugin/repository/everything/ From 73c0452c8d1b0d13ae721ebd96005b662ad80c72 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Tue, 31 Dec 2019 20:25:14 -0500 Subject: [PATCH 12/25] Update to latest Reserve Version. --- Essentials/pom.xml | 2 +- .../essentials/ReserveEssentials.java | 1303 +++-------------- 2 files changed, 222 insertions(+), 1083 deletions(-) diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 6ce32ffb4dd..815d6a783c8 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -51,7 +51,7 @@ net.tnemc Reserve - 0.1.2.0 + 0.1.4.3 provided diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index b150ffdaaa6..fe5b79cab7e 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -6,12 +6,15 @@ import net.tnemc.core.Reserve; import net.tnemc.core.economy.EconomyAPI; import net.tnemc.core.economy.currency.Currency; +import net.tnemc.core.economy.response.AccountResponse; +import net.tnemc.core.economy.response.EconomyResponse; +import net.tnemc.core.economy.response.GeneralResponse; +import net.tnemc.core.economy.response.HoldingsResponse; import org.bukkit.Bukkit; import org.bukkit.World; import java.math.BigDecimal; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import static com.earth2me.essentials.I18n.tl; @@ -46,7 +49,7 @@ public String name() { */ @Override public String version() { - return "0.1.2.0"; + return "0.1.4.3"; } //This is our method to convert UUID -> username for use with Essentials' create account methods. @@ -130,55 +133,17 @@ public boolean hasCurrency(String name, String world) { return name.equalsIgnoreCase(tl("moneySingular")); } - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(() -> hasCurrency(name)); - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(() -> hasCurrency(name, world)); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this identifier, else false. - */ - @Override - public boolean hasAccount(String identifier) { - return Economy.playerExists(identifier); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this identifier, else false. - */ - @Override - public boolean hasAccount(UUID identifier) { - return Economy.playerExists(getName(identifier)); - } - /** * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. * @param identifier The identifier of the account. * @return True if an account exists for this identifier, else false. */ @Override - public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(() -> Economy.playerExists(identifier)); + public EconomyResponse hasAccountDetail(String identifier) { + if (Economy.playerExists(identifier)) { + return GeneralResponse.SUCCESS; + } + return AccountResponse.DOESNT_EXIST; } /** @@ -187,30 +152,8 @@ public CompletableFuture asyncHasAccount(String identifier) { * @return True if an account exists for this identifier, else false. */ @Override - public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(() -> Economy.playerExists(getName(identifier))); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(String identifier) { - if (hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(UUID identifier) { - if (hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); + public EconomyResponse hasAccountDetail(UUID identifier) { + return hasAccountDetail(getName(identifier)); } /** @@ -219,11 +162,12 @@ public boolean createAccount(UUID identifier) { * @return True if an account was created, else false. */ @Override - public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(() -> { - if (hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - }); + public EconomyResponse createAccountDetail(String identifier) { + if (hasAccount(identifier)) return AccountResponse.ALREADY_EXISTS; + if (Economy.createNPC(identifier)) { + return AccountResponse.CREATED; + } + return GeneralResponse.FAILED; } /** @@ -232,11 +176,8 @@ public CompletableFuture asyncCreateAccount(String identifier) { * @return True if an account was created, else false. */ @Override - public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(() -> { - if (hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - }); + public EconomyResponse createAccountDetail(UUID identifier) { + return createAccountDetail(getName(identifier)); } /** @@ -245,45 +186,15 @@ public CompletableFuture asyncCreateAccount(UUID identifier) { * @return True if an account was deleted, else false. */ @Override - public boolean deleteAccount(String identifier) { + public EconomyResponse deleteAccountDetail(String identifier) { try { Economy.resetBalance(identifier); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(UUID identifier) { - try { - Economy.resetBalance(getName(identifier)); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(() -> { - try { - Economy.resetBalance(identifier); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); + return GeneralResponse.SUCCESS; } /** @@ -292,15 +203,8 @@ public CompletableFuture asyncDeleteAccount(String identifier) { * @return True if an account was deleted, else false. */ @Override - public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(() -> { - try { - Economy.resetBalance(getName(identifier)); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); + public EconomyResponse deleteAccountDetail(UUID identifier) { + return deleteAccountDetail(getName(identifier)); } /** @@ -351,176 +255,94 @@ public boolean isAccessor(UUID identifier, UUID accessor) { * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(String identifier, String accessor) { + if (identifier.equals(accessor)) { + return GeneralResponse.SUCCESS; + } + return GeneralResponse.FAILED; } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(String identifier, UUID accessor) { + return canWithdrawDetail(identifier, getName(accessor)); } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(UUID identifier, String accessor) { + return canWithdrawDetail(getName(identifier), accessor); } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canDeposit(UUID identifier, UUID accessor) { - return false; + public EconomyResponse canWithdrawDetail(UUID identifier, UUID accessor) { + return canWithdrawDetail(getName(identifier), getName(accessor)); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(String identifier, String accessor) { + if (identifier.equals(accessor)) { + return GeneralResponse.SUCCESS; + } + return GeneralResponse.FAILED; } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(String identifier, UUID accessor) { + return canDepositDetail(identifier, getName(accessor)); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(UUID identifier, String accessor) { + return canDepositDetail(getName(identifier), accessor); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(UUID identifier, UUID accessor) { + return canDepositDetail(getName(identifier), getName(accessor)); } /** @@ -599,72 +421,6 @@ public BigDecimal getHoldings(UUID identifier, String world, String currency) { return getHoldings(identifier); } - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - /** * Used to determine if an account has at least an amount of funds. * @param identifier The identifier of the account that is associated with this call. @@ -746,446 +502,222 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @param amount The amount you wish to set this accounts's funds to. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; + if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + try { + Economy.setMoney(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; + } } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @param amount The amount you wish to set this accounts's funds to. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount) { + return setHoldingsDetail(getName(identifier), amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return false; + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; + if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) + return HoldingsResponse.MAX_HOLDINGS; + try { - Economy.setMoney(identifier, amount); - return true; - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; + Economy.add(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; } } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return false; - try { - Economy.setMoney(getName(identifier), amount); - return true; - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount) { + return addHoldingsDetail(getName(identifier), amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; + if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) + return HoldingsResponse.MAX_HOLDINGS; + return GeneralResponse.SUCCESS; } /** - * Used to set funds to an account. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount) { + return canAddHoldingsDetail(getName(identifier), amount); } /** - * Used to set funds to an account. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world) { + return canAddHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount) { - if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(identifier, amount); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount) { - return addHoldings(getName(identifier), amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return canAddHoldingsDetail(identifier, amount); } /** @@ -1195,61 +727,11 @@ public boolean canAddHoldings(String identifier, BigDecimal amount, String world * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldingsDetail(identifier, amount); } /** @@ -1259,126 +741,46 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldingsDetail(identifier, amount); } - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } /** * Used to remove funds from an account. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean removeHoldings(String identifier, BigDecimal amount) { - if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(identifier, amount); - } catch (UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; + if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) + return HoldingsResponse.MIN_HOLDINGS; - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount) { - return removeHoldings(getName(identifier), amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + try { + Economy.substract(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; + } } /** * Used to remove funds from an account. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount) { + return removeHoldingsDetail(getName(identifier), amount); } /** @@ -1386,11 +788,11 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1398,11 +800,11 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1411,11 +813,11 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1424,89 +826,11 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1514,11 +838,15 @@ public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String worl * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; + if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) + return HoldingsResponse.MIN_HOLDINGS; + return GeneralResponse.SUCCESS; } /** @@ -1526,11 +854,11 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount) { + return canRemoveHoldingsDetail(getName(identifier), amount); } /** @@ -1539,11 +867,11 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1552,11 +880,11 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1566,11 +894,11 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1580,181 +908,11 @@ public CompletableFuture asyncCanRemoveHoldings(String identifier, BigD * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1808,23 +966,4 @@ public boolean purgeAccounts() { public boolean purgeAccountsUnder(BigDecimal amount) { return false; } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(() -> false); - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> false); - } } \ No newline at end of file From 97245c3c143c6823b2eb871e1a7aa110e7de1d48 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 1 Jan 2020 04:42:58 -0500 Subject: [PATCH 13/25] Bump Reserve to 0.1.4.4. --- Essentials/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 815d6a783c8..d6db448143a 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -51,7 +51,7 @@ net.tnemc Reserve - 0.1.4.3 + 0.1.4.4 provided From 6e9fe16440414ddc5d3188609e4cf2c650b58011 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 1 Jan 2020 04:50:54 -0500 Subject: [PATCH 14/25] Update pom. --- Essentials/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/pom.xml b/Essentials/pom.xml index d6db448143a..7dcb4ed5801 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -51,7 +51,7 @@ net.tnemc Reserve - 0.1.4.4 + 0.1.4.5 provided From a1c55e5915dd6e2fcee5d449ed75524d58683afd Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Wed, 8 Jan 2020 18:59:09 -0500 Subject: [PATCH 15/25] Only call createAccount if it doesn't exist. --- .../src/com/earth2me/essentials/ReserveEssentials.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index fe5b79cab7e..01c50e441f2 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -510,7 +510,7 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str @Override public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount) { if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; - if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; try { Economy.setMoney(identifier, amount); return GeneralResponse.SUCCESS; @@ -591,7 +591,7 @@ public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, Str @Override public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount) { if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; - if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) return HoldingsResponse.MAX_HOLDINGS; @@ -676,7 +676,7 @@ public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, Str @Override public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount) { if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; - if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) return HoldingsResponse.MAX_HOLDINGS; return GeneralResponse.SUCCESS; @@ -758,7 +758,7 @@ public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, @Override public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount) { if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; - if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) return HoldingsResponse.MIN_HOLDINGS; @@ -843,7 +843,7 @@ public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, @Override public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount) { if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; - if (!createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) return HoldingsResponse.MIN_HOLDINGS; return GeneralResponse.SUCCESS; From 9c86ddb695449d7fa7cc5083ba134270cf9e1474 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Thu, 9 Jan 2020 07:58:46 -0500 Subject: [PATCH 16/25] Fix issue where the createAccount method wouldn't be called if hasAccount was false. --- .../src/com/earth2me/essentials/ReserveEssentials.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java index 01c50e441f2..a9ae0d48185 100644 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java @@ -509,7 +509,6 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str */ @Override public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; try { Economy.setMoney(identifier, amount); @@ -590,7 +589,6 @@ public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, Str */ @Override public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) return HoldingsResponse.MAX_HOLDINGS; @@ -675,7 +673,6 @@ public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, Str */ @Override public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) return HoldingsResponse.MAX_HOLDINGS; @@ -757,7 +754,6 @@ public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, */ @Override public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) return HoldingsResponse.MIN_HOLDINGS; @@ -842,7 +838,6 @@ public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, */ @Override public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return AccountResponse.DOESNT_EXIST; if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) return HoldingsResponse.MIN_HOLDINGS; From 709ee2280902f29243d56b663756ea26cdf3fc8f Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Thu, 9 Jan 2020 23:43:13 -0500 Subject: [PATCH 17/25] Remove extra ReserveEssentials class. --- Essentials/pom.xml | 2 +- .../essentials/ReserveEssentials.java | 964 ------------ .../services/ReserveEssentials.java | 1385 +++-------------- 3 files changed, 239 insertions(+), 2112 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/ReserveEssentials.java diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 7dcb4ed5801..5d023ec0efc 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -51,7 +51,7 @@ net.tnemc Reserve - 0.1.4.5 + 0.1.4.6 provided diff --git a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/ReserveEssentials.java deleted file mode 100644 index a9ae0d48185..00000000000 --- a/Essentials/src/com/earth2me/essentials/ReserveEssentials.java +++ /dev/null @@ -1,964 +0,0 @@ -package com.earth2me.essentials; - -import com.earth2me.essentials.api.NoLoanPermittedException; -import com.earth2me.essentials.api.UserDoesNotExistException; -import net.ess3.api.Economy; -import net.tnemc.core.Reserve; -import net.tnemc.core.economy.EconomyAPI; -import net.tnemc.core.economy.currency.Currency; -import net.tnemc.core.economy.response.AccountResponse; -import net.tnemc.core.economy.response.EconomyResponse; -import net.tnemc.core.economy.response.GeneralResponse; -import net.tnemc.core.economy.response.HoldingsResponse; -import org.bukkit.Bukkit; -import org.bukkit.World; - -import java.math.BigDecimal; -import java.util.UUID; - -import static com.earth2me.essentials.I18n.tl; - -/** - * @author creatorfromhell - */ -public class ReserveEssentials implements EconomyAPI { - - private final Essentials ess; - - public ReserveEssentials(Essentials plugin) { - this.ess = plugin; - } - - public static void register(Essentials plugin) { - //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if (!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { - Reserve.instance().registerProvider(new ReserveEssentials(plugin)); - } - } - - /** - * @return The name of the Economy implementation. - */ - @Override - public String name() { - return "EssentialsX"; - } - - /** - * @return The version of Reserve the Economy implementation supports. - */ - @Override - public String version() { - return "0.1.4.3"; - } - - //This is our method to convert UUID -> username for use with Essentials' create account methods. - private String getName(UUID identifier) { - final User user = ess.getUser(identifier); - return ((user == null)? identifier.toString() : user.getName()); - } - - /** - * @return Whether or not this implementation is enabled. - */ - @Override - public boolean enabled() { - return true; - } - - /** - * @return Whether or not this implementation should have a default Vault implementation. - */ - @Override - public boolean vault() { - return false; - } - - /** - * Used to get the plural name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural() { - return tl("moneyPlural"); - } - - /** - * Used to get the singular name of the default currency. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular() { - return tl("moneySingular"); - } - - /** - * Used to get the plural name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultPlural(String world) { - return tl("moneyPlural"); - } - - /** - * Used to get the singular name of the default currency for a world. - * @param world The world to be used in this check. - * @return The plural name of the default currency. - */ - @Override - public String currencyDefaultSingular(String world) { - return tl("moneySingular"); - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name) { - return name.equalsIgnoreCase(tl("moneySingular")); - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public boolean hasCurrency(String name, String world) { - return name.equalsIgnoreCase(tl("moneySingular")); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this identifier, else false. - */ - @Override - public EconomyResponse hasAccountDetail(String identifier) { - if (Economy.playerExists(identifier)) { - return GeneralResponse.SUCCESS; - } - return AccountResponse.DOESNT_EXIST; - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this identifier, else false. - */ - @Override - public EconomyResponse hasAccountDetail(UUID identifier) { - return hasAccountDetail(getName(identifier)); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public EconomyResponse createAccountDetail(String identifier) { - if (hasAccount(identifier)) return AccountResponse.ALREADY_EXISTS; - if (Economy.createNPC(identifier)) { - return AccountResponse.CREATED; - } - return GeneralResponse.FAILED; - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. - */ - @Override - public EconomyResponse createAccountDetail(UUID identifier) { - return createAccountDetail(getName(identifier)); - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public EconomyResponse deleteAccountDetail(String identifier) { - try { - Economy.resetBalance(identifier); - } catch (UserDoesNotExistException ignore) { - return AccountResponse.DOESNT_EXIST; - } catch (NoLoanPermittedException ignore) { - return GeneralResponse.FAILED; - } - return GeneralResponse.SUCCESS; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public EconomyResponse deleteAccountDetail(UUID identifier) { - return deleteAccountDetail(getName(identifier)); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, String accessor) { - return identifier.equals(accessor); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(String identifier, UUID accessor) { - return isAccessor(identifier, getName(accessor)); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, String accessor) { - return isAccessor(getName(identifier), accessor); - } - - /** - * Determines whether or not a player is able to access this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to access this account. - */ - @Override - public boolean isAccessor(UUID identifier, UUID accessor) { - return isAccessor(getName(identifier), getName(accessor)); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canWithdrawDetail(String identifier, String accessor) { - if (identifier.equals(accessor)) { - return GeneralResponse.SUCCESS; - } - return GeneralResponse.FAILED; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canWithdrawDetail(String identifier, UUID accessor) { - return canWithdrawDetail(identifier, getName(accessor)); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canWithdrawDetail(UUID identifier, String accessor) { - return canWithdrawDetail(getName(identifier), accessor); - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canWithdrawDetail(UUID identifier, UUID accessor) { - return canWithdrawDetail(getName(identifier), getName(accessor)); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canDepositDetail(String identifier, String accessor) { - if (identifier.equals(accessor)) { - return GeneralResponse.SUCCESS; - } - return GeneralResponse.FAILED; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canDepositDetail(String identifier, UUID accessor) { - return canDepositDetail(identifier, getName(accessor)); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canDepositDetail(UUID identifier, String accessor) { - return canDepositDetail(getName(identifier), accessor); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canDepositDetail(UUID identifier, UUID accessor) { - return canDepositDetail(getName(identifier), getName(accessor)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier) { - if (hasAccount(identifier)) { - try { - return Economy.getMoneyExact(identifier); - } catch (UserDoesNotExistException ignore) { } - } - return ess.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier) { - if (hasAccount(identifier)) { - try { - return Economy.getMoneyExact(getName(identifier)); - } catch (UserDoesNotExistException ignore) { } - } - return ess.getSettings().getStartingBalance(); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(String identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public BigDecimal getHoldings(UUID identifier, String world, String currency) { - return getHoldings(identifier); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(identifier, amount); - } catch (UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount) { - try { - return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); - } catch (UserDoesNotExistException ignore) { - return false; - } - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to determine if an account has at least an amount of funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. - */ - @Override - public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return hasHoldings(identifier, amount); - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; - try { - Economy.setMoney(identifier, amount); - return GeneralResponse.SUCCESS; - } catch (UserDoesNotExistException ignore) { - return AccountResponse.DOESNT_EXIST; - } catch (NoLoanPermittedException ignore) { - return GeneralResponse.FAILED; - } - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount) { - return setHoldingsDetail(getName(identifier), amount); - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world) { - return setHoldingsDetail(identifier, amount); - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world) { - return setHoldingsDetail(identifier, amount); - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { - return setHoldingsDetail(identifier, amount); - } - - /** - * Used to set the funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set this accounts's funds to. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { - return setHoldingsDetail(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; - if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) - return HoldingsResponse.MAX_HOLDINGS; - - try { - Economy.add(identifier, amount); - return GeneralResponse.SUCCESS; - } catch (UserDoesNotExistException ignore) { - return AccountResponse.DOESNT_EXIST; - } catch (NoLoanPermittedException ignore) { - return GeneralResponse.FAILED; - } - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount) { - return addHoldingsDetail(getName(identifier), amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world) { - return addHoldingsDetail(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world) { - return addHoldingsDetail(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { - return addHoldingsDetail(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { - return addHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; - if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) - return HoldingsResponse.MAX_HOLDINGS; - return GeneralResponse.SUCCESS; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount) { - return canAddHoldingsDetail(getName(identifier), amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world) { - return canAddHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world) { - return canAddHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { - return canAddHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { - return canAddHoldingsDetail(identifier, amount); - } - - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; - if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) - return HoldingsResponse.MIN_HOLDINGS; - - try { - Economy.substract(identifier, amount); - return GeneralResponse.SUCCESS; - } catch (UserDoesNotExistException ignore) { - return AccountResponse.DOESNT_EXIST; - } catch (NoLoanPermittedException ignore) { - return GeneralResponse.FAILED; - } - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount) { - return removeHoldingsDetail(getName(identifier), amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world) { - return removeHoldingsDetail(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world) { - return removeHoldingsDetail(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { - return removeHoldingsDetail(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} for this action. - */ - @Override - public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { - return removeHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount) { - if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; - if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) - return HoldingsResponse.MIN_HOLDINGS; - return GeneralResponse.SUCCESS; - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount) { - return canRemoveHoldingsDetail(getName(identifier), amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world) { - return canRemoveHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world) { - return canRemoveHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldingsDetail(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. - */ - @Override - public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldingsDetail(identifier, amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world) { - return Economy.format(amount); - } - - /** - * Formats a monetary amount into a more text-friendly version. - * @param amount The amount of currency to format. - * @param world The {@link World} in which this format operation is occurring. - * @param currency The {@link Currency} associated with the balance. - * @return The formatted amount. - */ - @Override - public String format(BigDecimal amount, String world, String currency) { - return Economy.format(amount); - } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccounts() { - return false; - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public boolean purgeAccountsUnder(BigDecimal amount) { - return false; - } -} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index 6175d04d626..898788452a6 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -8,37 +8,33 @@ import net.tnemc.core.Reserve; import net.tnemc.core.economy.EconomyAPI; import net.tnemc.core.economy.currency.Currency; +import net.tnemc.core.economy.response.AccountResponse; +import net.tnemc.core.economy.response.EconomyResponse; +import net.tnemc.core.economy.response.GeneralResponse; +import net.tnemc.core.economy.response.HoldingsResponse; +import org.bukkit.Bukkit; import org.bukkit.World; import java.math.BigDecimal; import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; + +import static com.earth2me.essentials.I18n.tl; /** - * Reserve economy provider implementation for EssentialsX. - * @author creatorfromhell + * @author creatorfromhell */ public class ReserveEssentials implements EconomyAPI { private final Essentials ess; - private ReserveEssentials(Essentials ess) { - this.ess = ess; + public ReserveEssentials(Essentials plugin) { + this.ess = plugin; } - /** - * Register the provider if no other economy is available. - * - * @param ess The Essentials plugin instance - */ - public static void register(Essentials ess) { - Reserve reserve = Reserve.instance(); - - // Check to see if there is an economy provider already registered. - // If so, the existing provider should take priority - if (!reserve.economyProvided()) { - Reserve.instance().registerProvider(new ReserveEssentials(ess)); + public static void register(Essentials plugin) { + //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. + if (!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + Reserve.instance().registerProvider(new ReserveEssentials(plugin)); } } @@ -47,7 +43,7 @@ public static void register(Essentials ess) { */ @Override public String name() { - return "Essentials Economy"; + return "EssentialsX"; } /** @@ -55,13 +51,13 @@ public String name() { */ @Override public String version() { - return "0.1.2.0"; + return "0.1.4.3"; } //This is our method to convert UUID -> username for use with Essentials' create account methods. private String getName(UUID identifier) { final User user = ess.getUser(identifier); - return user == null ? identifier.toString() : user.getName(); + return ((user == null)? identifier.toString() : user.getName()); } /** @@ -86,7 +82,7 @@ public boolean vault() { */ @Override public String currencyDefaultPlural() { - return "Dollars"; + return tl("moneyPlural"); } /** @@ -95,7 +91,7 @@ public String currencyDefaultPlural() { */ @Override public String currencyDefaultSingular() { - return "Dollar"; + return tl("moneySingular"); } /** @@ -105,7 +101,7 @@ public String currencyDefaultSingular() { */ @Override public String currencyDefaultPlural(String world) { - return "Dollars"; + return tl("moneyPlural"); } /** @@ -115,7 +111,7 @@ public String currencyDefaultPlural(String world) { */ @Override public String currencyDefaultSingular(String world) { - return "Dollar"; + return tl("moneySingular"); } /** @@ -125,7 +121,7 @@ public String currencyDefaultSingular(String world) { */ @Override public boolean hasCurrency(String name) { - return true; //Always return true here as Essentials only supports one currency. + return name.equalsIgnoreCase(tl("moneySingular")); } /** @@ -136,112 +132,30 @@ public boolean hasCurrency(String name) { */ @Override public boolean hasCurrency(String name, String world) { - return true; //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name) { - return CompletableFuture.supplyAsync(() -> true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if a {@link Currency} exists with this name. - * @param name The name of the {@link Currency} to search for. - * @param world The name of the {@link World} to check for this {@link Currency} in. - * @return True if the currency exists, else false. - */ - @Override - public CompletableFuture asyncHasCurrency(String name, String world) { - return CompletableFuture.supplyAsync(() -> true); //Always return true here as Essentials only supports one currency. - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(String identifier) { - return Economy.playerExists(identifier); - } - - /** - * Checks to see if an account exists for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public boolean hasAccount(UUID identifier) { - return Economy.playerExists(getName(identifier)); + return name.equalsIgnoreCase(tl("moneySingular")); } /** * Checks to see if an account exists for this identifier. This method should be used for non-player accounts. * @param identifier The identifier of the account. - * @return True if an account exists for this player, else false. + * @return True if an account exists for this identifier, else false. */ @Override - public CompletableFuture asyncHasAccount(String identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(identifier); - } - }); + public EconomyResponse hasAccountDetail(String identifier) { + if (Economy.playerExists(identifier)) { + return GeneralResponse.SUCCESS; + } + return AccountResponse.DOESNT_EXIST; } /** * Checks to see if an account exists for this identifier. This method should be used for player accounts. * @param identifier The {@link UUID} of the account. - * @return True if an account exists for this player, else false. - */ - @Override - public CompletableFuture asyncHasAccount(UUID identifier) { - return CompletableFuture.supplyAsync(new Supplier() { - - /** - * Gets a result. - * - * @return a result - */ - @Override - public Boolean get() { - return Economy.playerExists(getName(identifier)); - } - }); - } - - /** - * Attempts to create an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was created, else false. - */ - @Override - public boolean createAccount(String identifier) { - if (hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - } - - /** - * Attempts to create an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was created, else false. + * @return True if an account exists for this identifier, else false. */ @Override - public boolean createAccount(UUID identifier) { - if (hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); + public EconomyResponse hasAccountDetail(UUID identifier) { + return hasAccountDetail(getName(identifier)); } /** @@ -250,11 +164,12 @@ public boolean createAccount(UUID identifier) { * @return True if an account was created, else false. */ @Override - public CompletableFuture asyncCreateAccount(String identifier) { - return CompletableFuture.supplyAsync(() -> { - if (hasAccount(identifier)) return false; - return Economy.createNPC(identifier); - }); + public EconomyResponse createAccountDetail(String identifier) { + if (hasAccount(identifier)) return AccountResponse.ALREADY_EXISTS; + if (Economy.createNPC(identifier)) { + return AccountResponse.CREATED; + } + return GeneralResponse.FAILED; } /** @@ -263,11 +178,8 @@ public CompletableFuture asyncCreateAccount(String identifier) { * @return True if an account was created, else false. */ @Override - public CompletableFuture asyncCreateAccount(UUID identifier) { - return CompletableFuture.supplyAsync(() -> { - if (hasAccount(identifier)) return false; - return Economy.createNPC(getName(identifier)); - }); + public EconomyResponse createAccountDetail(UUID identifier) { + return createAccountDetail(getName(identifier)); } /** @@ -276,45 +188,15 @@ public CompletableFuture asyncCreateAccount(UUID identifier) { * @return True if an account was deleted, else false. */ @Override - public boolean deleteAccount(String identifier) { + public EconomyResponse deleteAccountDetail(String identifier) { try { Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for player accounts. - * @param identifier The {@link UUID} of the account. - * @return True if an account was deleted, else false. - */ - @Override - public boolean deleteAccount(UUID identifier) { - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; } - return true; - } - - /** - * Attempts to delete an account for this identifier. This method should be used for non-player accounts. - * @param identifier The identifier of the account. - * @return True if an account was deleted, else false. - */ - @Override - public CompletableFuture asyncDeleteAccount(String identifier) { - return CompletableFuture.supplyAsync(() -> { - try { - Economy.resetBalance(identifier); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); + return GeneralResponse.SUCCESS; } /** @@ -323,15 +205,8 @@ public CompletableFuture asyncDeleteAccount(String identifier) { * @return True if an account was deleted, else false. */ @Override - public CompletableFuture asyncDeleteAccount(UUID identifier) { - return CompletableFuture.supplyAsync(() -> { - try { - Economy.resetBalance(getName(identifier)); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - return true; - }); + public EconomyResponse deleteAccountDetail(UUID identifier) { + return deleteAccountDetail(getName(identifier)); } /** @@ -342,7 +217,7 @@ public CompletableFuture asyncDeleteAccount(UUID identifier) { */ @Override public boolean isAccessor(String identifier, String accessor) { - return false; + return identifier.equals(accessor); } /** @@ -353,7 +228,7 @@ public boolean isAccessor(String identifier, String accessor) { */ @Override public boolean isAccessor(String identifier, UUID accessor) { - return false; + return isAccessor(identifier, getName(accessor)); } /** @@ -364,7 +239,7 @@ public boolean isAccessor(String identifier, UUID accessor) { */ @Override public boolean isAccessor(UUID identifier, String accessor) { - return false; + return isAccessor(getName(identifier), accessor); } /** @@ -375,183 +250,101 @@ public boolean isAccessor(UUID identifier, String accessor) { */ @Override public boolean isAccessor(UUID identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to withdraw holdings from this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public boolean canWithdraw(UUID identifier, UUID accessor) { - return false; + return isAccessor(getName(identifier), getName(accessor)); } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(String identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(String identifier, String accessor) { + if (identifier.equals(accessor)) { + return GeneralResponse.SUCCESS; + } + return GeneralResponse.FAILED; } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(String identifier, UUID accessor) { + return canWithdrawDetail(identifier, getName(accessor)); } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canWithdrawDetail(UUID identifier, String accessor) { + return canWithdrawDetail(getName(identifier), accessor); } /** * Determines whether or not a player is able to withdraw holdings from this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to withdraw holdings from this account. - */ - @Override - public CompletableFuture asyncCanWithdraw(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canDeposit(String identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(String identifier, UUID accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, String accessor) { - return false; - } - - /** - * Determines whether or not a player is able to deposit holdings into this account. - * @param identifier The identifier of the account that is associated with this call. - * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. - */ - @Override - public boolean canDeposit(UUID identifier, UUID accessor) { - return false; + public EconomyResponse canWithdrawDetail(UUID identifier, UUID accessor) { + return canWithdrawDetail(getName(identifier), getName(accessor)); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(String identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(String identifier, String accessor) { + if (identifier.equals(accessor)) { + return GeneralResponse.SUCCESS; + } + return GeneralResponse.FAILED; } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(String identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(String identifier, UUID accessor) { + return canDepositDetail(identifier, getName(accessor)); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(UUID identifier, String accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(UUID identifier, String accessor) { + return canDepositDetail(getName(identifier), accessor); } /** * Determines whether or not a player is able to deposit holdings into this account. * @param identifier The identifier of the account that is associated with this call. * @param accessor The identifier of the user attempting to access this account. - * @return Whether or not the player is able to deposit holdings into this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanDeposit(UUID identifier, UUID accessor) { - return CompletableFuture.supplyAsync(() -> false); + public EconomyResponse canDepositDetail(UUID identifier, UUID accessor) { + return canDepositDetail(getName(identifier), getName(accessor)); } /** @@ -564,7 +357,7 @@ public BigDecimal getHoldings(String identifier) { if (hasAccount(identifier)) { try { return Economy.getMoneyExact(identifier); - } catch(UserDoesNotExistException ignore) { } + } catch (UserDoesNotExistException ignore) { } } return ess.getSettings().getStartingBalance(); } @@ -579,7 +372,7 @@ public BigDecimal getHoldings(UUID identifier) { if (hasAccount(identifier)) { try { return Economy.getMoneyExact(getName(identifier)); - } catch(UserDoesNotExistException ignore) { } + } catch (UserDoesNotExistException ignore) { } } return ess.getSettings().getStartingBalance(); } @@ -630,72 +423,6 @@ public BigDecimal getHoldings(UUID identifier, String world, String currency) { return getHoldings(identifier); } - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(String identifier, String world, String currency) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - - /** - * Used to get the balance of an account. - * @param identifier The identifier of the account that is associated with this call. - * @param world The name of the {@link World} associated with the balance. - * @param currency The {@link Currency} associated with the balance. - * @return The balance of the account. - */ - @Override - public CompletableFuture asyncGetHoldings(UUID identifier, String world, String currency) { - return CompletableFuture.supplyAsync(() -> getHoldings(identifier)); - } - /** * Used to determine if an account has at least an amount of funds. * @param identifier The identifier of the account that is associated with this call. @@ -706,7 +433,7 @@ public CompletableFuture asyncGetHoldings(UUID identifier, String wo public boolean hasHoldings(String identifier, BigDecimal amount) { try { return hasAccount(identifier) && Economy.hasEnough(identifier, amount); - } catch(UserDoesNotExistException ignore) { + } catch (UserDoesNotExistException ignore) { return false; } } @@ -721,7 +448,7 @@ public boolean hasHoldings(String identifier, BigDecimal amount) { public boolean hasHoldings(UUID identifier, BigDecimal amount) { try { return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); - } catch(UserDoesNotExistException ignore) { + } catch (UserDoesNotExistException ignore) { return false; } } @@ -777,413 +504,193 @@ public boolean hasHoldings(UUID identifier, BigDecimal amount, String world, Str } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @param amount The amount you wish to set this accounts's funds to. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; + try { + Economy.setMoney(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; + } } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @param amount The amount you wish to set this accounts's funds to. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount) { + return setHoldingsDetail(getName(identifier), amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return setHoldingsDetail(identifier, amount); } /** - * Used to determine if an account has at least an amount of funds. + * Used to set the funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to use for this check. + * @param amount The amount you wish to set this accounts's funds to. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the account has at least the specified amount of funds, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncHasHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> hasHoldings(identifier, amount)); + public EconomyResponse setHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return setHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return false; + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) + return HoldingsResponse.MAX_HOLDINGS; + try { - Economy.setMoney(identifier, amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; + Economy.add(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; } } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount) { - if (!hasAccount(identifier)) return false; - try { - Economy.setMoney(getName(identifier), amount); - return true; - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount) { + return addHoldingsDetail(getName(identifier), amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(String identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to add funds to an account. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. + * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean setHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return setHoldings(identifier, amount); + public EconomyResponse addHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return addHoldingsDetail(identifier, amount); } /** - * Used to set funds to an account. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) > 0) + return HoldingsResponse.MAX_HOLDINGS; + return GeneralResponse.SUCCESS; } /** - * Used to set funds to an account. + * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not + * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @return True if the funds were set for the account, otherwise false. + * @param amount The amount you wish to add to this account. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to set funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to set from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were set for the account, otherwise false. - */ - @Override - public CompletableFuture asyncSetHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> setHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount) { - if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount) { - if (getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0) { - try { - Economy.add(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(String identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public boolean addHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return addHoldings(identifier, amount); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to add funds to an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were added to the account, otherwise false. - */ - @Override - public CompletableFuture asyncAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> addHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).add(amount).compareTo(ess.getSettings().getMaxMoney()) <= 0; + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount) { + return canAddHoldingsDetail(getName(identifier), amount); } /** @@ -1192,11 +699,11 @@ public boolean canAddHoldings(UUID identifier, BigDecimal amount) { * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return hasAccount(identifier) if a call to the corresponding addHoldings method would return hasAccount(identifier), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world) { + return canAddHoldingsDetail(identifier, amount); } /** @@ -1205,11 +712,11 @@ public boolean canAddHoldings(String identifier, BigDecimal amount, String world * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) { - return canAddHoldings(identifier, amount); + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return canAddHoldingsDetail(identifier, amount); } /** @@ -1219,75 +726,11 @@ public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world) * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public boolean canAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canAddHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return canAddHoldingsDetail(identifier, amount); } /** @@ -1297,133 +740,45 @@ public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecima * @param amount The amount you wish to add to this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncCanAddHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); + public EconomyResponse canAddHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return canAddHoldingsDetail(identifier, amount); } - /** - * Used to determine if a call to the corresponding addHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to add to this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return canAddHoldings(identifier, amount) if a call to the corresponding addHoldings method would return canAddHoldings(identifier, amount), otherwise false. - */ - @Override - public CompletableFuture asyncCanAddHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canAddHoldings(identifier, amount)); - } /** * Used to remove funds from an account. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean removeHoldings(String identifier, BigDecimal amount) { - if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(identifier, amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } - } - return false; - } + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) + return HoldingsResponse.MIN_HOLDINGS; - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount) { - if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0) { - try { - Economy.substract(getName(identifier), amount); - } catch(UserDoesNotExistException | NoLoanPermittedException ignore) { - return false; - } + try { + Economy.substract(identifier, amount); + return GeneralResponse.SUCCESS; + } catch (UserDoesNotExistException ignore) { + return AccountResponse.DOESNT_EXIST; + } catch (NoLoanPermittedException ignore) { + return GeneralResponse.FAILED; } - return false; - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public boolean removeHoldings(String identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); } /** * Used to remove funds from an account. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean removeHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return removeHoldings(identifier, amount); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); - } - - /** - * Used to remove funds from an account. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount) { + return removeHoldingsDetail(getName(identifier), amount); } /** @@ -1431,11 +786,11 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1443,11 +798,11 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1456,11 +811,11 @@ public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecima * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public CompletableFuture asyncRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); + public EconomyResponse removeHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1469,23 +824,11 @@ public CompletableFuture asyncRemoveHoldings(String identifier, BigDeci * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were removed from the account, otherwise false. - */ - @Override - public CompletableFuture asyncRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> removeHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} for this action. */ @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; + public EconomyResponse removeHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return removeHoldingsDetail(identifier, amount); } /** @@ -1493,11 +836,14 @@ public boolean canRemoveHoldings(String identifier, BigDecimal amount) { * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { - return hasAccount(identifier) && getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) >= 0; + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount) { + if (!hasAccount(identifier) && !createAccount(identifier)) return AccountResponse.CREATION_FAILED; + if (getHoldings(identifier).subtract(amount).compareTo(ess.getSettings().getMinMoney()) < 0) + return HoldingsResponse.MIN_HOLDINGS; + return GeneralResponse.SUCCESS; } /** @@ -1505,12 +851,11 @@ public boolean canRemoveHoldings(UUID identifier, BigDecimal amount) { * affect an account's funds. * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount) { + return canRemoveHoldingsDetail(getName(identifier), amount); } /** @@ -1519,11 +864,11 @@ public boolean canRemoveHoldings(String identifier, BigDecimal amount, String wo * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return canRemoveHoldings(identifier, amount); + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1532,12 +877,11 @@ public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String worl * @param identifier The identifier of the account that is associated with this call. * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public boolean canRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1547,61 +891,11 @@ public boolean canRemoveHoldings(String identifier, BigDecimal amount, String wo * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public boolean canRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return canRemoveHoldings(identifier, amount); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); + public EconomyResponse canRemoveHoldingsDetail(String identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1611,195 +905,11 @@ public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDec * @param amount The amount you wish to remove from this account. * @param world The name of the {@link World} associated with the amount. * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. + * @return The {@link EconomyResponse} that would be returned with the corresponding removeHoldingsDetail method. */ @Override - public CompletableFuture asyncCanRemoveHoldings(String identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to determine if a call to the corresponding removeHoldings method would be successful. This method does not - * affect an account's funds. - * @param identifier The identifier of the account that is associated with this call. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding removeHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanRemoveHoldings(UUID identifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canRemoveHoldings(identifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to transfer funds from one account to another. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if the funds were transferred. - */ - @Override - public CompletableFuture asyncTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> transferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(String fromIdentifier, String toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. This method does not - * affect an account's funds. - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @return True if a call to the corresponding transferHoldings method would return true, otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world)); - } - - /** - * Used to determine if a call to the corresponding transferHoldings method would be successful. - * This method does not affect an account's funds. - * - * @param fromIdentifier The identifier of the account that the holdings will be coming from. - * @param toIdentifier The identifier of the account that the holdings will be going to. - * @param amount The amount you wish to remove from this account. - * @param world The name of the {@link World} associated with the amount. - * @param currency The {@link Currency} associated with the balance. - * - * @return True if a call to the corresponding transferHoldings method would return true, - * otherwise false. - */ - @Override - public CompletableFuture asyncCanTransferHoldings(UUID fromIdentifier, UUID toIdentifier, BigDecimal amount, String world, String currency) { - return CompletableFuture.supplyAsync(() -> canTransferHoldings(fromIdentifier, toIdentifier, amount, world, currency)); + public EconomyResponse canRemoveHoldingsDetail(UUID identifier, BigDecimal amount, String world, String currency) { + return canRemoveHoldingsDetail(identifier, amount); } /** @@ -1853,23 +963,4 @@ public boolean purgeAccounts() { public boolean purgeAccountsUnder(BigDecimal amount) { return false; } - - /** - * Purges the database of accounts with the default balance. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccounts() { - return CompletableFuture.supplyAsync(() -> false); - } - - /** - * Purges the database of accounts with a balance under the specified one. - * @param amount The amount that an account's balance has to be under in order to be removed. - * @return True if the purge was completed successfully. - */ - @Override - public CompletableFuture asyncPurgeAccountsUnder(BigDecimal amount) { - return CompletableFuture.supplyAsync(() -> false); - } } \ No newline at end of file From 15c5df7fab11493b817fe63819db4dd583e0a422 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Thu, 9 Jan 2020 23:52:24 -0500 Subject: [PATCH 18/25] Fix for merge commit. --- .github/workflows/build.yml | 41 ++ .travis.yml | 13 - .../antibuild/EssentialsAntiBuild.java | 4 + .../EssentialsAntiBuildListener.java | 44 +- .../EssentialsChatPlayerListenerLowest.java | 1 + .../EssentialsProtectEntityListener.java | 475 +++++++++--------- .../essentials/protect/ProtectConfig.java | 9 +- README.md | 2 +- pom.xml | 8 +- 9 files changed, 333 insertions(+), 264 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000000..0b832765e26 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build EssentialsX + +on: + push: + branches: + - 2.x + - mc/* + pull_request: + branches: + - 2.x + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Git repo + uses: actions/checkout@v1 + - name: Restore Maven cache + uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Run BuildTools + if: steps.cache.outputs.cache-hit != 'true' + run: chmod +x scripts/buildtools.sh && ./scripts/buildtools.sh + - name: Build with Maven + run: mvn package --file pom.xml + - name: Copy artifacts + run: mkdir -p ./out/ && cp -t ./out/ **/target/Essentials*.jar + - uses: actions/upload-artifact@master + with: + name: Plugin jars + path: out/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4baf95b3614..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: java - -jdk: - - openjdk8 - -cache: - directories: - - .buildtools - - $HOME/.m2 - -before_install: - - chmod +x scripts/buildtools.sh - - scripts/buildtools.sh diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java index 59aa5828be4..7b00632bcc7 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java @@ -60,4 +60,8 @@ public boolean getSettingBool(final AntiBuildConfig protectConfig) { final Boolean bool = settingsBoolean.get(protectConfig); return bool == null ? protectConfig.getDefaultValueBoolean() : bool; } + + static String getNameForType(Material type) { + return type.toString().toLowerCase().replaceAll("_", " "); + } } diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index a9cff948f93..4c82aba5d61 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -1,7 +1,11 @@ package com.earth2me.essentials.antibuild; +import static com.earth2me.essentials.I18n.tl; + import com.earth2me.essentials.User; import com.earth2me.essentials.utils.VersionUtil; +import java.util.logging.Level; +import java.util.logging.Logger; import net.ess3.api.IEssentials; import org.bukkit.Material; import org.bukkit.block.Block; @@ -12,7 +16,11 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.inventory.CraftItemEvent; @@ -21,12 +29,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; -import java.util.logging.Level; -import java.util.logging.Logger; - - -import static com.earth2me.essentials.I18n.tl; - public class EssentialsAntiBuildListener implements Listener { private static final Logger logger = Logger.getLogger("EssentialsAntiBuild"); @@ -92,9 +94,9 @@ public void onBlockPlace(final BlockPlaceEvent event) { final Block block = event.getBlockPlaced(); final Material type = block.getType(); - if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "place", block)) { + if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !metaPermCheck(user, "place", block)) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildPlace", type.toString())); + user.sendMessage(tl("antiBuildPlace", EssentialsAntiBuild.getNameForType(type))); } event.setCancelled(true); return; @@ -102,14 +104,14 @@ public void onBlockPlace(final BlockPlaceEvent event) { if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, type) && !user.isAuthorized("essentials.protect.exemptplacement")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildPlace", type.toString())); + user.sendMessage(tl("antiBuildPlace", EssentialsAntiBuild.getNameForType(type))); } event.setCancelled(true); return; } if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced")); + prot.getEssentialsConnect().alert(user, EssentialsAntiBuild.getNameForType(type), tl("alertPlaced")); } } @@ -119,9 +121,9 @@ public void onBlockBreak(final BlockBreakEvent event) { final Block block = event.getBlock(); final Material type = block.getType(); - if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", block)) { + if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !metaPermCheck(user, "break", block)) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildBreak", type.toString())); + user.sendMessage(tl("antiBuildBreak", EssentialsAntiBuild.getNameForType(type))); } event.setCancelled(true); return; @@ -129,14 +131,14 @@ public void onBlockBreak(final BlockBreakEvent event) { if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildBreak", type.toString())); + user.sendMessage(tl("antiBuildBreak", EssentialsAntiBuild.getNameForType(type))); } event.setCancelled(true); return; } if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke")); + prot.getEssentialsConnect().alert(user, EssentialsAntiBuild.getNameForType(type), tl("alertBroke")); } } @@ -147,7 +149,7 @@ public void onHangingBreak(final HangingBreakByEntityEvent event) { final User user = ess.getUser((Player) entity); final EntityType type = event.getEntity().getType(); final boolean warn = ess.getSettings().warnOnBuildDisallow(); - if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild()) { if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING)) { if (warn) { user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString())); @@ -202,7 +204,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) { prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed")); } - if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { if (event.hasItem() && !metaPermCheck(user, "interact", item.getType(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { @@ -227,7 +229,7 @@ public void onCraftItemEvent(final CraftItemEvent event) { final User user = ess.getUser((Player) entity); final ItemStack item = event.getRecipe().getResult(); - if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { if (!metaPermCheck(user, "craft", item.getType(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { @@ -244,7 +246,7 @@ public void onPlayerDropItem(final PlayerDropItemEvent event) { final User user = ess.getUser(event.getPlayer()); final ItemStack item = event.getItemDrop().getItemStack(); - if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { if (!metaPermCheck(user, "drop", item.getType(), item.getDurability())) { event.setCancelled(true); user.getBase().updateInventory(); @@ -271,7 +273,7 @@ public void onPlayerPickupItem(EntityPickupItemEvent event) { final User user = ess.getUser((Player) event.getEntity()); final ItemStack item = event.getItem().getItemStack(); - if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) { event.setCancelled(true); event.getItem().setPickupDelay(50); @@ -287,7 +289,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) { final User user = ess.getUser(event.getPlayer()); final ItemStack item = event.getItem().getItemStack(); - if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { + if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) { event.setCancelled(true); event.getItem().setPickupDelay(50); diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 1969315c0e2..5963fc04fcd 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -55,6 +55,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { format = format.replace("{5}", team == null ? "" : team.getDisplayName()); format = format.replace("{6}", prefix); format = format.replace("{7}", suffix); + format = format.replace("{8}", player.getName()); synchronized (format) { event.setFormat(format); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index 6081657a45e..f949f402e26 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -1,226 +1,249 @@ -package com.earth2me.essentials.protect; - -import com.earth2me.essentials.User; -import net.ess3.api.IEssentials; -import org.bukkit.entity.*; -import org.bukkit.entity.minecart.ExplosiveMinecart; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.*; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; -import org.bukkit.event.hanging.HangingBreakEvent; - -import java.util.Locale; - - -public class EssentialsProtectEntityListener implements Listener { - private final IProtect prot; - private final IEssentials ess; - - EssentialsProtectEntityListener(final IProtect prot) { - this.prot = prot; - this.ess = prot.getEssentialsConnect().getEssentials(); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDamage(final EntityDamageEvent event) { - final Entity target = event.getEntity(); - - if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) { - event.setCancelled(true); - return; - } - - User user = null; - if (target instanceof Player) { - user = ess.getUser((Player) target); - } - - final DamageCause cause = event.getCause(); - - if (event instanceof EntityDamageByBlockEvent) { - if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player && shouldBeDamaged(user, "contact"))) { - event.setCancelled(true); - return; - } - if (prot.getSettingBool(ProtectConfig.disable_lavadmg) && cause == DamageCause.LAVA && !(target instanceof Player && shouldBeDamaged(user, "lava"))) { - event.setCancelled(true); - return; - } - if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && cause == DamageCause.BLOCK_EXPLOSION && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { - event.setCancelled(true); - return; - } - } - - if (event instanceof EntityDamageByEntityEvent) { - final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event; - final Entity eAttack = edEvent.getDamager(); - - User attacker = null; - if (eAttack instanceof Player) { - attacker = ess.getUser((Player) eAttack); - } - - //Creeper explode prevention - if (eAttack instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)) && !(target instanceof Player && shouldBeDamaged(user, "creeper"))) { - event.setCancelled(true); - return; - } - - if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "fireball"))) { - event.setCancelled(true); - return; - } - - if (event.getEntity() instanceof WitherSkull && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "witherskull"))) { - event.setCancelled(true); - return; - } - - if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { - event.setCancelled(true); - return; - } - - if (eAttack instanceof ExplosiveMinecart && prot.getSettingBool(ProtectConfig.prevent_tntminecart_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt-minecart"))) { - event.setCancelled(true); - return; - } - - // PVP Settings - if (target instanceof Player && eAttack instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && !user.getName().equalsIgnoreCase(attacker.getName()) && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp"))) { - event.setCancelled(true); - return; - } - - if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles")) || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") || !ess.getUser((Player) ((Projectile) edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) { - event.setCancelled(true); - return; - } - } - - if (target instanceof Player) { - if (cause == DamageCause.FALL && prot.getSettingBool(ProtectConfig.disable_fall) && !shouldBeDamaged(user, "fall")) { - event.setCancelled(true); - return; - } - - if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !shouldBeDamaged(user, "suffocation")) { - event.setCancelled(true); - return; - } - if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) && prot.getSettingBool(ProtectConfig.disable_firedmg) && !shouldBeDamaged(user, "fire")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.DROWNING && prot.getSettingBool(ProtectConfig.disable_drown) && !shouldBeDamaged(user, "drowning")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.LIGHTNING && prot.getSettingBool(ProtectConfig.disable_lightning) && !shouldBeDamaged(user, "lightning")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.WITHER && prot.getSettingBool(ProtectConfig.disable_wither) && !shouldBeDamaged(user, "wither")) { - event.setCancelled(true); - } - } - } - - private boolean shouldBeDamaged(final User user, final String type) { - return (user.isAuthorized("essentials.protect.damage.".concat(type)) && !user.isAuthorized("essentials.protect.damage.disable")); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityExplode(final EntityExplodeEvent event) { - if (event.getEntity() == null) { - return; - } - Entity entity = event.getEntity(); - final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight(); - - if (entity instanceof EnderDragon && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) { - event.setCancelled(true); - if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) { - event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); - } - return; - } - if (entity instanceof Wither && prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion)) { - event.setCancelled(true); - } else if (entity instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { - //Nicccccccccce plaaacccccccccce.. - event.setCancelled(true); - event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); - } else if (entity instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { - event.setCancelled(true); - - } else if (entity instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { - event.setCancelled(true); - - } else if ((entity instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)) { - event.setCancelled(true); - } else if ((entity instanceof ExplosiveMinecart) && prot.getSettingBool(ProtectConfig.prevent_tntminecart_explosion)) { - event.setCancelled(true); - } - - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onCreatureSpawn(final CreatureSpawnEvent event) { - if (event.getEntity() instanceof Player) { - return; - } - final EntityType creature = event.getEntityType(); - if (creature == null) { - return; - } - final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH); - if (creatureName.isEmpty()) { - return; - } - if (ess.getSettings().getProtectPreventSpawn(creatureName)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityTarget(final EntityTargetEvent event) { - if (!(event.getTarget() instanceof Player)) { - return; - } - final User user = ess.getUser((Player) event.getTarget()); - if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.TARGET_ATTACKED_NEARBY_ENTITY || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.DEFEND_VILLAGE || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && prot.getSettingBool(ProtectConfig.prevent_entitytarget) && !user.isAuthorized("essentials.protect.entitytarget.bypass")) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onExplosionPrime(ExplosionPrimeEvent event) { - if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { - event.setFire(false); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityChangeBlock(EntityChangeBlockEvent event) { - if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup)) { - event.setCancelled(true); - return; - } - if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPaintingBreak(HangingBreakByEntityEvent event) { - if ((event.getCause() == HangingBreakEvent.RemoveCause.ENTITY) && ((event.getRemover() instanceof Creeper) && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || (((event.getRemover() instanceof Fireball) || (event.getRemover() instanceof SmallFireball)) && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) || ((event.getRemover() instanceof TNTPrimed) && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) || ((event.getRemover() instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)))) { - event.setCancelled(true); - } - } -} +package com.earth2me.essentials.protect; + +import com.earth2me.essentials.User; +import net.ess3.api.IEssentials; +import org.bukkit.entity.*; +import org.bukkit.entity.minecart.ExplosiveMinecart; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; + +import java.util.Locale; + + +public class EssentialsProtectEntityListener implements Listener { + private final IProtect prot; + private final IEssentials ess; + + EssentialsProtectEntityListener(final IProtect prot) { + this.prot = prot; + this.ess = prot.getEssentialsConnect().getEssentials(); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityDamage(final EntityDamageEvent event) { + final Entity target = event.getEntity(); + + if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) { + event.setCancelled(true); + return; + } + + User user = null; + if (target instanceof Player) { + user = ess.getUser((Player) target); + } + + final DamageCause cause = event.getCause(); + + if (event instanceof EntityDamageByBlockEvent) { + if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player && shouldBeDamaged(user, "contact"))) { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.disable_lavadmg) && cause == DamageCause.LAVA && !(target instanceof Player && shouldBeDamaged(user, "lava"))) { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && cause == DamageCause.BLOCK_EXPLOSION && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { + event.setCancelled(true); + return; + } + } + + if (event instanceof EntityDamageByEntityEvent) { + final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event; + final Entity eAttack = edEvent.getDamager(); + + User attacker = null; + if (eAttack instanceof Player) { + attacker = ess.getUser((Player) eAttack); + } + + //Creeper explode prevention + if (eAttack instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)) && !(target instanceof Player && shouldBeDamaged(user, "creeper"))) { + event.setCancelled(true); + return; + } + + if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "fireball"))) { + event.setCancelled(true); + return; + } + + if (event.getEntity() instanceof WitherSkull && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "witherskull"))) { + event.setCancelled(true); + return; + } + + if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { + event.setCancelled(true); + return; + } + + if (eAttack instanceof ExplosiveMinecart && prot.getSettingBool(ProtectConfig.prevent_tntminecart_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt-minecart"))) { + event.setCancelled(true); + return; + } + + // PVP Settings + if (target instanceof Player && eAttack instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && !user.getName().equalsIgnoreCase(attacker.getName()) && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp"))) { + event.setCancelled(true); + return; + } + + if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles")) || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") || !ess.getUser((Player) ((Projectile) edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) { + event.setCancelled(true); + return; + } + } + + if (target instanceof Player) { + if (cause == DamageCause.FALL && prot.getSettingBool(ProtectConfig.disable_fall) && !shouldBeDamaged(user, "fall")) { + event.setCancelled(true); + return; + } + + if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !shouldBeDamaged(user, "suffocation")) { + event.setCancelled(true); + return; + } + if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) && prot.getSettingBool(ProtectConfig.disable_firedmg) && !shouldBeDamaged(user, "fire")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.DROWNING && prot.getSettingBool(ProtectConfig.disable_drown) && !shouldBeDamaged(user, "drowning")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.LIGHTNING && prot.getSettingBool(ProtectConfig.disable_lightning) && !shouldBeDamaged(user, "lightning")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.WITHER && prot.getSettingBool(ProtectConfig.disable_wither) && !shouldBeDamaged(user, "wither")) { + event.setCancelled(true); + } + } + } + + private boolean shouldBeDamaged(final User user, final String type) { + return (user.isAuthorized("essentials.protect.damage.".concat(type)) && !user.isAuthorized("essentials.protect.damage.disable")); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityExplode(final EntityExplodeEvent event) { + if (event.getEntity() == null) { + return; + } + Entity entity = event.getEntity(); + final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight(); + + if (entity instanceof EnderDragon && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) { + event.setCancelled(true); + if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) { + event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); + } + return; + } + if (entity instanceof Wither && prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion)) { + event.setCancelled(true); + } else if (entity instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { + //Nicccccccccce plaaacccccccccce.. + event.setCancelled(true); + event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); + } else if (entity instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { + event.setCancelled(true); + + } else if (entity instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { + event.setCancelled(true); + + } else if ((entity instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)) { + event.setCancelled(true); + } else if ((entity instanceof ExplosiveMinecart) && prot.getSettingBool(ProtectConfig.prevent_tntminecart_explosion)) { + event.setCancelled(true); + } + + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityTransform(final EntityTransformEvent event) { + final Entity entity = event.getEntity(); + final EntityTransformEvent.TransformReason reason = event.getTransformReason(); + if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) { + if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) { + event.setCancelled(true); + } else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) { + event.setCancelled(true); + } else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) { + event.setCancelled(true); + } else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) { + event.setCancelled(true); + } + } else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onCreatureSpawn(final CreatureSpawnEvent event) { + if (event.getEntity() instanceof Player) { + return; + } + final EntityType creature = event.getEntityType(); + if (creature == null) { + return; + } + final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH); + if (creatureName.isEmpty()) { + return; + } + if (ess.getSettings().getProtectPreventSpawn(creatureName)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityTarget(final EntityTargetEvent event) { + if (!(event.getTarget() instanceof Player)) { + return; + } + final User user = ess.getUser((Player) event.getTarget()); + if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.TARGET_ATTACKED_NEARBY_ENTITY || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.DEFEND_VILLAGE || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && prot.getSettingBool(ProtectConfig.prevent_entitytarget) && !user.isAuthorized("essentials.protect.entitytarget.bypass")) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onExplosionPrime(ExplosionPrimeEvent event) { + if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { + event.setFire(false); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup)) { + event.setCancelled(true); + return; + } + if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPaintingBreak(HangingBreakByEntityEvent event) { + if ((event.getCause() == HangingBreakEvent.RemoveCause.ENTITY) && ((event.getRemover() instanceof Creeper) && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || (((event.getRemover() instanceof Fireball) || (event.getRemover() instanceof SmallFireball)) && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) || ((event.getRemover() instanceof TNTPrimed) && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) || ((event.getRemover() instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)))) { + event.setCancelled(true); + } + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 3d8e06cd7c0..cc088b85f20 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -42,7 +42,14 @@ public enum ProtectConfig { prevent_villager_death("protect.prevent.villager-death", false), prevent_enderdragon_blockdmg("protect.prevent.enderdragon-blockdamage", true), prevent_entitytarget("protect.prevent.entitytarget", false), - enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false); + enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false), + prevent_creeper_charge("protect.prevent.transformation.charged-creeper", false), + prevent_villager_infection("protect.prevent.transformation.zombie-villager", false), + prevent_villager_cure("protect.prevent.transformation.villager", false), + prevent_villager_to_witch("protect.prevent.transformation.witch", false), + prevent_pig_transformation("protect.prevent.transformation.zombie-pigman", false), + prevent_zombie_drowning("protect.prevent.transformation.drowned", false), + prevent_mooshroom_switching("protect.prevent.transformation.mooshroom", false); private final String configName; private final String defValueString; private final boolean defValueBoolean; diff --git a/README.md b/README.md index ee27967cb7d..6c16790e62f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,6 @@ If you can't make a donation, don't worry! There's lots of other ways to contrib * Do you run a server? Take a look at our ["help wanted" issues](https://github.com/EssentialsX/Essentials/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22), where you can find issues that need extra testing and investigation. You can also join the [MOSS Discord community](https://discord.gg/casfFyh) and provide support to others. -* Do you speak multiple languages? If so, we always welcome pull requests to our [language files](https://essentialsx.github.io/#/Locale). +* Do you speak multiple languages? If so, we always welcome contributions to our [Crowdin project](https://crowdin.com/project/essentialsx-official). * If you're a developer, you could look through our ["open to PR" issues](https://github.com/EssentialsX/Essentials/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22status%3A+open+to+PR%22). We're always happy to receive bug fixes and feature additions as pull requests. diff --git a/pom.xml b/pom.xml index b61ce202313..8f932597233 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,10 @@ reserve-repo https://dl.bintray.com/theneweconomy/java/ + + jitpack + https://jitpack.io + @@ -62,7 +66,7 @@ org.bukkit bukkit - 1.14.4-R0.1-SNAPSHOT + 1.15.1-R0.1-SNAPSHOT provided @@ -74,7 +78,7 @@ org.mockito mockito-core - 2.8.47 + 3.2.0 test
From 29b457cb4a8666859af3a33e7b782b537bc9ac9d Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Thu, 9 Jan 2020 23:59:14 -0500 Subject: [PATCH 19/25] Revert EssentialsProtect class showing modified from merge. --- .../essentials/protect/EssentialsProtectEntityListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index f949f402e26..54f2867dc65 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -246,4 +246,4 @@ public void onPaintingBreak(HangingBreakByEntityEvent event) { event.setCancelled(true); } } -} +} \ No newline at end of file From 1142536ef6f6eca4b25776de9b6c74ab52b73fff Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Fri, 10 Jan 2020 08:37:21 -0500 Subject: [PATCH 20/25] Resolve requested changes. --- .../com/earth2me/essentials/services/ReserveEssentials.java | 6 +++--- .../essentials/protect/EssentialsProtectEntityListener.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index 898788452a6..b685e39d62d 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -33,7 +33,7 @@ public ReserveEssentials(Essentials plugin) { public static void register(Essentials plugin) { //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if (!((Reserve)Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { + if (!((Reserve) Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { Reserve.instance().registerProvider(new ReserveEssentials(plugin)); } } @@ -51,13 +51,13 @@ public String name() { */ @Override public String version() { - return "0.1.4.3"; + return "0.1.4.6"; } //This is our method to convert UUID -> username for use with Essentials' create account methods. private String getName(UUID identifier) { final User user = ess.getUser(identifier); - return ((user == null)? identifier.toString() : user.getName()); + return ((user == null) ? identifier.toString() : user.getName()); } /** diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index 54f2867dc65..f949f402e26 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -246,4 +246,4 @@ public void onPaintingBreak(HangingBreakByEntityEvent event) { event.setCancelled(true); } } -} \ No newline at end of file +} From bc29d5c8889f2ca405702bc68044d444cd9b5fee Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Fri, 10 Jan 2020 08:41:36 -0500 Subject: [PATCH 21/25] Revert EssentialsProtect dif --- .../EssentialsProtectEntityListener.java | 498 +++++++++--------- 1 file changed, 249 insertions(+), 249 deletions(-) diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index f949f402e26..1f527f7d551 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -1,249 +1,249 @@ -package com.earth2me.essentials.protect; - -import com.earth2me.essentials.User; -import net.ess3.api.IEssentials; -import org.bukkit.entity.*; -import org.bukkit.entity.minecart.ExplosiveMinecart; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.*; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; -import org.bukkit.event.hanging.HangingBreakEvent; - -import java.util.Locale; - - -public class EssentialsProtectEntityListener implements Listener { - private final IProtect prot; - private final IEssentials ess; - - EssentialsProtectEntityListener(final IProtect prot) { - this.prot = prot; - this.ess = prot.getEssentialsConnect().getEssentials(); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDamage(final EntityDamageEvent event) { - final Entity target = event.getEntity(); - - if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) { - event.setCancelled(true); - return; - } - - User user = null; - if (target instanceof Player) { - user = ess.getUser((Player) target); - } - - final DamageCause cause = event.getCause(); - - if (event instanceof EntityDamageByBlockEvent) { - if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player && shouldBeDamaged(user, "contact"))) { - event.setCancelled(true); - return; - } - if (prot.getSettingBool(ProtectConfig.disable_lavadmg) && cause == DamageCause.LAVA && !(target instanceof Player && shouldBeDamaged(user, "lava"))) { - event.setCancelled(true); - return; - } - if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && cause == DamageCause.BLOCK_EXPLOSION && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { - event.setCancelled(true); - return; - } - } - - if (event instanceof EntityDamageByEntityEvent) { - final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event; - final Entity eAttack = edEvent.getDamager(); - - User attacker = null; - if (eAttack instanceof Player) { - attacker = ess.getUser((Player) eAttack); - } - - //Creeper explode prevention - if (eAttack instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)) && !(target instanceof Player && shouldBeDamaged(user, "creeper"))) { - event.setCancelled(true); - return; - } - - if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "fireball"))) { - event.setCancelled(true); - return; - } - - if (event.getEntity() instanceof WitherSkull && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "witherskull"))) { - event.setCancelled(true); - return; - } - - if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { - event.setCancelled(true); - return; - } - - if (eAttack instanceof ExplosiveMinecart && prot.getSettingBool(ProtectConfig.prevent_tntminecart_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt-minecart"))) { - event.setCancelled(true); - return; - } - - // PVP Settings - if (target instanceof Player && eAttack instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && !user.getName().equalsIgnoreCase(attacker.getName()) && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp"))) { - event.setCancelled(true); - return; - } - - if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles")) || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") || !ess.getUser((Player) ((Projectile) edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) { - event.setCancelled(true); - return; - } - } - - if (target instanceof Player) { - if (cause == DamageCause.FALL && prot.getSettingBool(ProtectConfig.disable_fall) && !shouldBeDamaged(user, "fall")) { - event.setCancelled(true); - return; - } - - if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !shouldBeDamaged(user, "suffocation")) { - event.setCancelled(true); - return; - } - if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) && prot.getSettingBool(ProtectConfig.disable_firedmg) && !shouldBeDamaged(user, "fire")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.DROWNING && prot.getSettingBool(ProtectConfig.disable_drown) && !shouldBeDamaged(user, "drowning")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.LIGHTNING && prot.getSettingBool(ProtectConfig.disable_lightning) && !shouldBeDamaged(user, "lightning")) { - event.setCancelled(true); - return; - } - if (cause == DamageCause.WITHER && prot.getSettingBool(ProtectConfig.disable_wither) && !shouldBeDamaged(user, "wither")) { - event.setCancelled(true); - } - } - } - - private boolean shouldBeDamaged(final User user, final String type) { - return (user.isAuthorized("essentials.protect.damage.".concat(type)) && !user.isAuthorized("essentials.protect.damage.disable")); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityExplode(final EntityExplodeEvent event) { - if (event.getEntity() == null) { - return; - } - Entity entity = event.getEntity(); - final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight(); - - if (entity instanceof EnderDragon && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) { - event.setCancelled(true); - if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) { - event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); - } - return; - } - if (entity instanceof Wither && prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion)) { - event.setCancelled(true); - } else if (entity instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { - //Nicccccccccce plaaacccccccccce.. - event.setCancelled(true); - event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); - } else if (entity instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { - event.setCancelled(true); - - } else if (entity instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { - event.setCancelled(true); - - } else if ((entity instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)) { - event.setCancelled(true); - } else if ((entity instanceof ExplosiveMinecart) && prot.getSettingBool(ProtectConfig.prevent_tntminecart_explosion)) { - event.setCancelled(true); - } - - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityTransform(final EntityTransformEvent event) { - final Entity entity = event.getEntity(); - final EntityTransformEvent.TransformReason reason = event.getTransformReason(); - if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) { - event.setCancelled(true); - } else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) { - event.setCancelled(true); - } else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) { - if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) { - event.setCancelled(true); - } else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) { - event.setCancelled(true); - } else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) { - event.setCancelled(true); - } else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) { - event.setCancelled(true); - } - } else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onCreatureSpawn(final CreatureSpawnEvent event) { - if (event.getEntity() instanceof Player) { - return; - } - final EntityType creature = event.getEntityType(); - if (creature == null) { - return; - } - final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH); - if (creatureName.isEmpty()) { - return; - } - if (ess.getSettings().getProtectPreventSpawn(creatureName)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityTarget(final EntityTargetEvent event) { - if (!(event.getTarget() instanceof Player)) { - return; - } - final User user = ess.getUser((Player) event.getTarget()); - if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.TARGET_ATTACKED_NEARBY_ENTITY || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.DEFEND_VILLAGE || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && prot.getSettingBool(ProtectConfig.prevent_entitytarget) && !user.isAuthorized("essentials.protect.entitytarget.bypass")) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onExplosionPrime(ExplosionPrimeEvent event) { - if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { - event.setFire(false); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityChangeBlock(EntityChangeBlockEvent event) { - if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup)) { - event.setCancelled(true); - return; - } - if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPaintingBreak(HangingBreakByEntityEvent event) { - if ((event.getCause() == HangingBreakEvent.RemoveCause.ENTITY) && ((event.getRemover() instanceof Creeper) && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || (((event.getRemover() instanceof Fireball) || (event.getRemover() instanceof SmallFireball)) && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) || ((event.getRemover() instanceof TNTPrimed) && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) || ((event.getRemover() instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)))) { - event.setCancelled(true); - } - } -} +package com.earth2me.essentials.protect; + +import com.earth2me.essentials.User; +import net.ess3.api.IEssentials; +import org.bukkit.entity.*; +import org.bukkit.entity.minecart.ExplosiveMinecart; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; + +import java.util.Locale; + + +public class EssentialsProtectEntityListener implements Listener { + private final IProtect prot; + private final IEssentials ess; + + EssentialsProtectEntityListener(final IProtect prot) { + this.prot = prot; + this.ess = prot.getEssentialsConnect().getEssentials(); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityDamage(final EntityDamageEvent event) { + final Entity target = event.getEntity(); + + if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) { + event.setCancelled(true); + return; + } + + User user = null; + if (target instanceof Player) { + user = ess.getUser((Player) target); + } + + final DamageCause cause = event.getCause(); + + if (event instanceof EntityDamageByBlockEvent) { + if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player && shouldBeDamaged(user, "contact"))) { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.disable_lavadmg) && cause == DamageCause.LAVA && !(target instanceof Player && shouldBeDamaged(user, "lava"))) { + event.setCancelled(true); + return; + } + if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion) && cause == DamageCause.BLOCK_EXPLOSION && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { + event.setCancelled(true); + return; + } + } + + if (event instanceof EntityDamageByEntityEvent) { + final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent) event; + final Entity eAttack = edEvent.getDamager(); + + User attacker = null; + if (eAttack instanceof Player) { + attacker = ess.getUser((Player) eAttack); + } + + //Creeper explode prevention + if (eAttack instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)) && !(target instanceof Player && shouldBeDamaged(user, "creeper"))) { + event.setCancelled(true); + return; + } + + if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "fireball"))) { + event.setCancelled(true); + return; + } + + if (event.getEntity() instanceof WitherSkull && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "witherskull"))) { + event.setCancelled(true); + return; + } + + if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt"))) { + event.setCancelled(true); + return; + } + + if (eAttack instanceof ExplosiveMinecart && prot.getSettingBool(ProtectConfig.prevent_tntminecart_playerdmg) && !(target instanceof Player && shouldBeDamaged(user, "tnt-minecart"))) { + event.setCancelled(true); + return; + } + + // PVP Settings + if (target instanceof Player && eAttack instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && !user.getName().equalsIgnoreCase(attacker.getName()) && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp"))) { + event.setCancelled(true); + return; + } + + if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles")) || (((Projectile) edEvent.getDamager()).getShooter() instanceof Player && prot.getSettingBool(ProtectConfig.disable_pvp) && (!user.isAuthorized("essentials.protect.pvp") || !ess.getUser((Player) ((Projectile) edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp"))))) { + event.setCancelled(true); + return; + } + } + + if (target instanceof Player) { + if (cause == DamageCause.FALL && prot.getSettingBool(ProtectConfig.disable_fall) && !shouldBeDamaged(user, "fall")) { + event.setCancelled(true); + return; + } + + if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !shouldBeDamaged(user, "suffocation")) { + event.setCancelled(true); + return; + } + if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK) && prot.getSettingBool(ProtectConfig.disable_firedmg) && !shouldBeDamaged(user, "fire")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.DROWNING && prot.getSettingBool(ProtectConfig.disable_drown) && !shouldBeDamaged(user, "drowning")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.LIGHTNING && prot.getSettingBool(ProtectConfig.disable_lightning) && !shouldBeDamaged(user, "lightning")) { + event.setCancelled(true); + return; + } + if (cause == DamageCause.WITHER && prot.getSettingBool(ProtectConfig.disable_wither) && !shouldBeDamaged(user, "wither")) { + event.setCancelled(true); + } + } + } + + private boolean shouldBeDamaged(final User user, final String type) { + return (user.isAuthorized("essentials.protect.damage.".concat(type)) && !user.isAuthorized("essentials.protect.damage.disable")); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityExplode(final EntityExplodeEvent event) { + if (event.getEntity() == null) { + return; + } + Entity entity = event.getEntity(); + final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight(); + + if (entity instanceof EnderDragon && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) { + event.setCancelled(true); + if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) { + event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); + } + return; + } + if (entity instanceof Wither && prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion)) { + event.setCancelled(true); + } else if (entity instanceof Creeper && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { + //Nicccccccccce plaaacccccccccce.. + event.setCancelled(true); + event.getLocation().getWorld().createExplosion(event.getLocation(), 0F); + } else if (entity instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { + event.setCancelled(true); + + } else if (entity instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { + event.setCancelled(true); + + } else if ((entity instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)) { + event.setCancelled(true); + } else if ((entity instanceof ExplosiveMinecart) && prot.getSettingBool(ProtectConfig.prevent_tntminecart_explosion)) { + event.setCancelled(true); + } + + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityTransform(final EntityTransformEvent event) { + final Entity entity = event.getEntity(); + final EntityTransformEvent.TransformReason reason = event.getTransformReason(); + if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) { + event.setCancelled(true); + } else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) { + if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) { + event.setCancelled(true); + } else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) { + event.setCancelled(true); + } else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) { + event.setCancelled(true); + } else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) { + event.setCancelled(true); + } + } else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onCreatureSpawn(final CreatureSpawnEvent event) { + if (event.getEntity() instanceof Player) { + return; + } + final EntityType creature = event.getEntityType(); + if (creature == null) { + return; + } + final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH); + if (creatureName.isEmpty()) { + return; + } + if (ess.getSettings().getProtectPreventSpawn(creatureName)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityTarget(final EntityTargetEvent event) { + if (!(event.getTarget() instanceof Player)) { + return; + } + final User user = ess.getUser((Player) event.getTarget()); + if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.TARGET_ATTACKED_NEARBY_ENTITY || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.DEFEND_VILLAGE || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && prot.getSettingBool(ProtectConfig.prevent_entitytarget) && !user.isAuthorized("essentials.protect.entitytarget.bypass")) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onExplosionPrime(ExplosionPrimeEvent event) { + if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { + event.setFire(false); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if (event.getEntityType() == EntityType.ENDERMAN && prot.getSettingBool(ProtectConfig.prevent_enderman_pickup)) { + event.setCancelled(true); + return; + } + if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPaintingBreak(HangingBreakByEntityEvent event) { + if ((event.getCause() == HangingBreakEvent.RemoveCause.ENTITY) && ((event.getRemover() instanceof Creeper) && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) || (((event.getRemover() instanceof Fireball) || (event.getRemover() instanceof SmallFireball)) && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) || ((event.getRemover() instanceof TNTPrimed) && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) || ((event.getRemover() instanceof WitherSkull) && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion)))) { + event.setCancelled(true); + } + } +} From 27ca930dc1506af9ad58a8aadf1c8ea2e7fd3a70 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sat, 11 Jan 2020 23:03:45 -0500 Subject: [PATCH 22/25] Fixes for requested changes. --- .../earth2me/essentials/services/ReserveEssentials.java | 4 ++-- pom.xml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index b685e39d62d..5a5e08b80b5 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -432,7 +432,7 @@ public BigDecimal getHoldings(UUID identifier, String world, String currency) { @Override public boolean hasHoldings(String identifier, BigDecimal amount) { try { - return hasAccount(identifier) && Economy.hasEnough(identifier, amount); + return Economy.hasEnough(identifier, amount); } catch (UserDoesNotExistException ignore) { return false; } @@ -447,7 +447,7 @@ public boolean hasHoldings(String identifier, BigDecimal amount) { @Override public boolean hasHoldings(UUID identifier, BigDecimal amount) { try { - return hasAccount(identifier) && Economy.hasEnough(getName(identifier), amount); + return Economy.hasEnough(getName(identifier), amount); } catch (UserDoesNotExistException ignore) { return false; } diff --git a/pom.xml b/pom.xml index 8f932597233..63eaa4675be 100644 --- a/pom.xml +++ b/pom.xml @@ -34,15 +34,15 @@ paper-repo https://papermc.io/repo/repository/maven-public/ - - - reserve-repo - https://dl.bintray.com/theneweconomy/java/ jitpack https://jitpack.io + + reserve-repo + https://dl.bintray.com/theneweconomy/java/ +
From 89198ab020e715a09200bc591725dcc52771ed07 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Tue, 14 Jan 2020 17:48:36 -0500 Subject: [PATCH 23/25] Move currency namings to config.yml --- Essentials/pom.xml | 2 +- .../com/earth2me/essentials/ISettings.java | 4 ++++ .../src/com/earth2me/essentials/Settings.java | 10 +++++++++ .../services/ReserveEssentials.java | 22 ++++++++++++------- Essentials/src/config.yml | 6 +++++ Essentials/src/messages.properties | 2 -- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Essentials/pom.xml b/Essentials/pom.xml index f1aba7d3550..2cfab333374 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -51,7 +51,7 @@ net.tnemc Reserve - 0.1.4.6 + 0.1.4.8 provided diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index a20fcd541d5..9597b89b9c0 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -48,6 +48,10 @@ public interface ISettings extends IConf { String getCurrencySymbol(); + String getCurrencySingular(); + + String getCurrencyPlural(); + int getOversizedStackSize(); int getDefaultStackSize(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index ba965e225e6..8d6acdec6b6 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -672,6 +672,16 @@ public String getCurrencySymbol() { return config.getString("currency-symbol", "$").concat("$").substring(0, 1).replaceAll("[0-9]", "$"); } + @Override + public String getCurrencySingular() { + return config.getString("currency-singular"); + } + + @Override + public String getCurrencyPlural() { + return config.getString("currency-plural"); + } + // #easteregg @Override @Deprecated diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index 5a5e08b80b5..95be7deab8c 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -18,8 +18,6 @@ import java.math.BigDecimal; import java.util.UUID; -import static com.earth2me.essentials.I18n.tl; - /** * @author creatorfromhell */ @@ -68,6 +66,14 @@ public boolean enabled() { return true; } + /** + * @return True if this implementation should override other economy implementations. + */ + @Override + public boolean force() { + return false; + } + /** * @return Whether or not this implementation should have a default Vault implementation. */ @@ -82,7 +88,7 @@ public boolean vault() { */ @Override public String currencyDefaultPlural() { - return tl("moneyPlural"); + return ess.getSettings().getCurrencyPlural(); } /** @@ -91,7 +97,7 @@ public String currencyDefaultPlural() { */ @Override public String currencyDefaultSingular() { - return tl("moneySingular"); + return ess.getSettings().getCurrencySingular(); } /** @@ -101,7 +107,7 @@ public String currencyDefaultSingular() { */ @Override public String currencyDefaultPlural(String world) { - return tl("moneyPlural"); + return ess.getSettings().getCurrencyPlural(); } /** @@ -111,7 +117,7 @@ public String currencyDefaultPlural(String world) { */ @Override public String currencyDefaultSingular(String world) { - return tl("moneySingular"); + return ess.getSettings().getCurrencySingular(); } /** @@ -121,7 +127,7 @@ public String currencyDefaultSingular(String world) { */ @Override public boolean hasCurrency(String name) { - return name.equalsIgnoreCase(tl("moneySingular")); + return name.equalsIgnoreCase(ess.getSettings().getCurrencySingular()); } /** @@ -132,7 +138,7 @@ public boolean hasCurrency(String name) { */ @Override public boolean hasCurrency(String name, String world) { - return name.equalsIgnoreCase(tl("moneySingular")); + return name.equalsIgnoreCase(ess.getSettings().getCurrencySingular()); } /** diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 48694454140..c380b29a420 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -644,6 +644,12 @@ command-costs: # such as accented letters, you MUST save the file as UTF-8, not ANSI. currency-symbol: '$' +#Set this to the singular name of your currency. +currency-singular: 'dollar' + +#Set this to the plural name of your currency +currency-plural: 'dollars' + # Set the maximum amount of money a player can have. # The amount is always limited to 10 trillion because of the limitations of a java double. max-money: 10000000000000 diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 29d003ac921..70eb34d0ff9 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -295,8 +295,6 @@ mobSpawnLimit=Mob quantity limited to server limit. mobSpawnTarget=\u00a74Target block must be a mob spawner. moneyRecievedFrom=\u00a7a{0}\u00a76 has been received from\u00a7a {1}\u00a76. moneySentTo=\u00a7a{0} has been sent to {1}. -moneySingular=dollar -moneyPlural=dollars month=month months=months moreThanZero=\u00a74Quantities must be greater than 0. From 251eb87def44edcd9ddadf0118de07cf415493ad Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Tue, 14 Jan 2020 18:19:15 -0500 Subject: [PATCH 24/25] Remove unneeded check as Reserve checks for existing providers for us. --- .../com/earth2me/essentials/services/ReserveEssentials.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index 95be7deab8c..8a70833b346 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -12,7 +12,6 @@ import net.tnemc.core.economy.response.EconomyResponse; import net.tnemc.core.economy.response.GeneralResponse; import net.tnemc.core.economy.response.HoldingsResponse; -import org.bukkit.Bukkit; import org.bukkit.World; import java.math.BigDecimal; @@ -30,10 +29,7 @@ public ReserveEssentials(Essentials plugin) { } public static void register(Essentials plugin) { - //Check to see if there is an economy provider already registered, if so Essentials will take the back seat. - if (!((Reserve) Bukkit.getServer().getPluginManager().getPlugin("Reserve")).economyProvided()) { - Reserve.instance().registerProvider(new ReserveEssentials(plugin)); - } + Reserve.instance().registerProvider(new ReserveEssentials(plugin)); } /** From b5b38358fdef4e7da385ad6ec108b6b18e5bd3ce Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Tue, 14 Jan 2020 20:44:15 -0500 Subject: [PATCH 25/25] Match ReserveEco ess naming scheme to ReserveEssentials. --- .../essentials/register/payment/methods/ReserveEco.java | 2 +- .../earth2me/essentials/services/ReserveEssentials.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java index 5c3cff07274..db8bbac6075 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/ReserveEco.java @@ -201,7 +201,7 @@ public MethodBankAccount getBankAccount(String bank, String name) { public boolean isCompatible(Plugin plugin) { try { EconomyAPI economyAPI = ((Reserve) plugin).economy(); - return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("Essentials Economy"); + return plugin.getName().equals("Reserve") && economyAPI != null && !economyAPI.name().equals("EssentialsX"); } catch (LinkageError | Exception e) { return false; } diff --git a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java index 8a70833b346..4cc2ce30037 100644 --- a/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java +++ b/Essentials/src/com/earth2me/essentials/services/ReserveEssentials.java @@ -2,9 +2,9 @@ import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; +import com.earth2me.essentials.api.Economy; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; -import net.ess3.api.Economy; import net.tnemc.core.Reserve; import net.tnemc.core.economy.EconomyAPI; import net.tnemc.core.economy.currency.Currency; @@ -358,7 +358,8 @@ public EconomyResponse canDepositDetail(UUID identifier, UUID accessor) { public BigDecimal getHoldings(String identifier) { if (hasAccount(identifier)) { try { - return Economy.getMoneyExact(identifier); + + return new BigDecimal(Economy.getMoney(identifier)); } catch (UserDoesNotExistException ignore) { } } return ess.getSettings().getStartingBalance(); @@ -373,7 +374,7 @@ public BigDecimal getHoldings(String identifier) { public BigDecimal getHoldings(UUID identifier) { if (hasAccount(identifier)) { try { - return Economy.getMoneyExact(getName(identifier)); + return new BigDecimal(Economy.getMoney(getName(identifier))); } catch (UserDoesNotExistException ignore) { } } return ess.getSettings().getStartingBalance();