Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void setMoney(String name, BigDecimal balance) throws UserDoesNotExistException, NoLoanPermittedException
- {
- User user = getUserByName(name);
- if (user == null)
- {
- throw new UserDoesNotExistException(name);
- }
- if (balance.compareTo(ess.getSettings().getMinMoney()) < 0)
- {
- throw new NoLoanPermittedException();
- }
- if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan"))
- {
- throw new NoLoanPermittedException();
- }
- try
- {
- user.setMoney(balance);
- }
- catch (MaxMoneyException ex)
- {
- //TODO: Update API to show max balance errors
- }
- Trade.log("API", "Set", "API", name, new Trade(balance, ess), null, null, null, ess);
- }
- /**
- * Adds money to the balance of a user
- *
- * @param name Name of the user
- * @param amount The money you want to add
- * @throws UserDoesNotExistException If a user by that name does not exists
- * @throws NoLoanPermittedException If the user is not allowed to have a negative balance
- */
- @Deprecated
- public static void add(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
- {
- try
- {
- add(name, BigDecimal.valueOf(amount));
- }
- catch (ArithmeticException e)
- {
- logger.log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e);
- }
- }
- public static void add(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
- {
- BigDecimal result = getMoneyExact(name).add(amount, MATH_CONTEXT);
- setMoney(name, result);
- Trade.log("API", "Add", "API", name, new Trade(amount, ess), null, null, null, ess);
- }
- /**
- * Substracts money from the balance of a user
- *
- * @param name Name of the user
- * @param amount The money you want to substract
- * @throws UserDoesNotExistException If a user by that name does not exists
- * @throws NoLoanPermittedException If the user is not allowed to have a negative balance
- */
- @Deprecated
- public static void subtract(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
- {
- try
- {
- substract(name, BigDecimal.valueOf(amount));
- }
- catch (ArithmeticException e)
- {
- logger.log(Level.WARNING, "Failed to substract " + amount + " of balance of " + name + ": " + e.getMessage(), e);
- }
- }
- public static void substract(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
- {
- BigDecimal result = getMoneyExact(name).subtract(amount, MATH_CONTEXT);
- setMoney(name, result);
- Trade.log("API", "Subtract", "API", name, new Trade(amount, ess), null, null, null, ess);
- }
- /**
- * Divides the balance of a user by a value
- *
- * @param name Name of the user
- * @param value The balance is divided by this value
- * @throws UserDoesNotExistException If a user by that name does not exists
- * @throws NoLoanPermittedException If the user is not allowed to have a negative balance
- */
- @Deprecated
- public static void divide(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
- {
- try
- {
- divide(name, BigDecimal.valueOf(amount));
- }
- catch (ArithmeticException e)
- {
- logger.log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e);
- }
- }
- public static void divide(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
- {
- BigDecimal result = getMoneyExact(name).divide(amount, MATH_CONTEXT);
- setMoney(name, result);
- Trade.log("API", "Divide", "API", name, new Trade(amount, ess), null, null, null, ess);
- }
- /**
- * Multiplies the balance of a user by a value
- *
- * @param name Name of the user
- * @param value The balance is multiplied by this value
- * @throws UserDoesNotExistException If a user by that name does not exists
- * @throws NoLoanPermittedException If the user is not allowed to have a negative balance
- */
- @Deprecated
- public static void multiply(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException
- {
- try
- {
- multiply(name, BigDecimal.valueOf(amount));
- }
- catch (ArithmeticException e)
- {
- logger.log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e);
- }
- }
- public static void multiply(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException
- {
- BigDecimal result = getMoneyExact(name).multiply(amount, MATH_CONTEXT);
- setMoney(name, result);
- Trade.log("API", "Multiply", "API", name, new Trade(amount, ess), null, null, null, ess);
- }
- /**
- * Resets the balance of a user to the starting balance
- *
- * @param name Name of the user
- * @throws UserDoesNotExistException If a user by that name does not exists
- * @throws NoLoanPermittedException If the user is not allowed to have a negative balance
- */
- public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException
- {
- if (ess == null)
- {
- throw new RuntimeException(noCallBeforeLoad);
- }
- setMoney(name, ess.getSettings().getStartingBalance());
- Trade.log("API", "Reset", "API", name, new Trade(BigDecimal.ZERO, ess), null, null, null, ess);
- }
- /**
- * @param name Name of the user
- * @param amount The amount of money the user should have
- * @return true, if the user has more or an equal amount of money
- * @throws UserDoesNotExistException If a user by that name does not exists
- */
- @Deprecated
- public static boolean hasEnough(String name, double amount) throws UserDoesNotExistException
- {
- try
- {
- return hasEnough(name, BigDecimal.valueOf(amount));
- }
- catch (ArithmeticException e)
- {
- logger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e);
- return false;
- }
- }
- public static boolean hasEnough(String name, BigDecimal amount) throws UserDoesNotExistException, ArithmeticException
- {
- return amount.compareTo(getMoneyExact(name)) <= 0;
- }
- /**
- * @param name Name of the user
- * @param amount The amount of money the user should have
- * @return true, if the user has more money
- * @throws UserDoesNotExistException If a user by that name does not exists
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement