From e1091d887dcb9bf9a89c33b8e504f28e10210177 Mon Sep 17 00:00:00 2001 From: "Justin M." Date: Sun, 8 Dec 2024 19:08:23 -0600 Subject: [PATCH] Added sell multipliers (#4770) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../com/earth2me/essentials/ISettings.java | 2 ++ .../com/earth2me/essentials/Settings.java | 31 +++++++++++++++++++ .../essentials/commands/Commandsell.java | 3 +- .../earth2me/essentials/signs/SignSell.java | 1 + Essentials/src/main/resources/config.yml | 9 ++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 81de33064..eedc49e01 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -418,6 +418,8 @@ public interface ISettings extends IConf { boolean showZeroBaltop(); + BigDecimal getMultiplier(final User user); + int getMaxItemLore(); Tag getPrimaryColor(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 908e2ca11..f817dca92 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -149,6 +149,8 @@ public class Settings implements net.ess3.api.ISettings { private Map worldAliases; private Tag primaryColor = DEFAULT_PRIMARY_COLOR; private Tag secondaryColor = DEFAULT_SECONDARY_COLOR; + private Set multiplierPerms; + private BigDecimal defaultMultiplier; public Settings(final IEssentials ess) { this.ess = ess; @@ -921,6 +923,8 @@ public class Settings implements net.ess3.api.ISettings { worldAliases = _getWorldAliases(); primaryColor = _getPrimaryColor(); secondaryColor = _getSecondaryColor(); + multiplierPerms = _getMultiplierPerms(); + defaultMultiplier = _getDefaultMultiplier(); reloadCount.incrementAndGet(); } @@ -2090,6 +2094,33 @@ public class Settings implements net.ess3.api.ISettings { } @Override + public BigDecimal getMultiplier(final User user) { + BigDecimal multiplier = defaultMultiplier; + if (multiplierPerms == null) { + return defaultMultiplier; + } + + for (final String multiplierPerm : multiplierPerms) { + if (user.isAuthorized("essentials.sell.multiplier." + multiplierPerm)) { + final BigDecimal value = config.getBigDecimal("sell-multipliers." + multiplierPerm, BigDecimal.ZERO); + if (value.compareTo(multiplier) > 0) { + multiplier = value; + } + } + } + + return multiplier; + } + + private BigDecimal _getDefaultMultiplier() { + return config.getBigDecimal("sell-multipliers.default", BigDecimal.ONE); + } + + private Set _getMultiplierPerms() { + final CommentedConfigurationNode section = config.getSection("sell-multipliers"); + return section == null ? null : ConfigurateUtil.getKeys(section); + } + public int getMaxItemLore() { return config.getInt("max-itemlore-lines", 10); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java index 4110de102..9a9ca1cf6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -93,7 +93,8 @@ public class Commandsell extends EssentialsCommand { private BigDecimal sellItem(final User user, final ItemStack is, final String[] args, final boolean isBulkSell) throws Exception { final int amount = ess.getWorth().getAmount(ess, user, is, args, isBulkSell); - final BigDecimal worth = ess.getWorth().getPrice(ess, is); + final BigDecimal originalWorth = ess.getWorth().getPrice(ess, is); + final BigDecimal worth = originalWorth == null ? null : originalWorth.multiply(ess.getSettings().getMultiplier(user)); if (worth == null) { throw new TranslatableException("itemCannotBeSold"); diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignSell.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignSell.java index 1e1079f25..5841e2b6e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignSell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignSell.java @@ -41,6 +41,7 @@ public class SignSell extends EssentialsSign { //noinspection BigDecimalMethodWithoutRoundingCalled BigDecimal pricePerSingleItem = chargeAmount.divide(new BigDecimal(initialItemAmount)); pricePerSingleItem = pricePerSingleItem.multiply(new BigDecimal(newItemAmount)); + pricePerSingleItem = pricePerSingleItem.multiply(ess.getSettings().getMultiplier(player)); money = new Trade(pricePerSingleItem, ess); } } diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 96bcb82af..f10f99248 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -879,6 +879,15 @@ baltop-requirements: # For 1'234,50 use fr-ch #currency-symbol-format-locale: en-US +# Allow players to receive multipliers for items sold with /sell or the sell sign. +# You can set the default multiplier using the 'default' rank below. +# To grant different multipliers to different people, you need to define a 'multiplier-rank' below. +# Create the 'multiplier-rank' below, and give the matching permission: essentials.sell.multiplier. +sell-multipliers: + default: 1.0 + double: 2.0 + triple: 3.0 + ############################################################ # +------------------------------------------------------+ # # | Help | #