From 0a978a328be299c54112ff81fd99a68992e65f5f Mon Sep 17 00:00:00 2001 From: JustinM95 Date: Thu, 20 Jan 2022 11:43:04 -0600 Subject: [PATCH 1/4] Added /sell multipliers with configuration Feature request @ https://github.com/EssentialsX/Essentials/issues/3934 --- .../com/earth2me/essentials/ISettings.java | 1 + .../com/earth2me/essentials/Settings.java | 26 +++++++++++++++++++ .../essentials/commands/Commandsell.java | 2 +- Essentials/src/main/resources/config.yml | 11 ++++++++ 4 files changed, 39 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 405fe5dc0de..e2801329650 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -395,6 +395,7 @@ public interface ISettings extends IConf { boolean isUpdateCheckEnabled(); boolean showZeroBaltop(); + BigDecimal getMultiplier(final User user); enum KeepInvPolicy { KEEP, diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 47eecc98568..8223d735300 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -138,6 +138,8 @@ public class Settings implements net.ess3.api.ISettings { private double maxProjectileSpeed; private boolean removeEffectsOnHeal; private Map worldAliases; + private Set multiplierPerms; + private BigDecimal defaultMultiplier; public Settings(final IEssentials ess) { this.ess = ess; @@ -766,6 +768,8 @@ public void reloadConfig() { bindingItemPolicy = _getBindingItemsPolicy(); currencySymbol = _getCurrencySymbol(); worldAliases = _getWorldAliases(); + multiplierPerms = _getMultiplierPerms(); + defaultMultiplier = _getDefaultMultiplier(); reloadCount.incrementAndGet(); } @@ -1919,4 +1923,26 @@ public boolean isUpdateCheckEnabled() { public boolean showZeroBaltop() { return config.getBoolean("show-zero-baltop", true); } + + @Override + public BigDecimal getMultiplier(final User user) { + BigDecimal multiplier = defaultMultiplier; + if (multiplierPerms == null) return defaultMultiplier; + for (String multiplierPerm : multiplierPerms) { + if (user.isAuthorized("essentials.sell.multiplier." + multiplierPerm)) { + 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); + } } 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 1a153c03982..57110a5ecda 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -90,7 +90,7 @@ public void run(final Server server, final User user, final String commandLabel, 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 worth = ess.getWorth().getPrice(ess, is) == null ? null : ess.getWorth().getPrice(ess, is).multiply(ess.getSettings().getMultiplier(user)); if (worth == null) { throw new Exception(tl("itemCannotBeSold")); diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index bd96fcaf48e..7d3ee224f43 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -845,6 +845,17 @@ show-zero-baltop: true # For 1'234,50 use fr-ch #currency-symbol-format-locale: en-US +# Settings for /sell multipliers +# Give multipliers to players with the permission 'essentials.sell.multiplier.{multiplier}' +# example: 'essentials.sell.multiplier.double', 'essentials.sell.multiplier.triple' +# You can add as many multipliers as you want. +# Use the "default" name to set the default multiplier that everyone has. It defaults to 1 if not set. +# If a player has more than one multiplier permission, it will pick the highest one. +sell-multipliers: + default: 1.0 + double: 2.0 + triple: 3.0 + ############################################################ # +------------------------------------------------------+ # # | Help | # From fded2937c7d27230040e774192689a503a587557 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:30:06 -0500 Subject: [PATCH 2/4] Apply suggestions from code review --- .../main/java/com/earth2me/essentials/ISettings.java | 1 + .../com/earth2me/essentials/commands/Commandsell.java | 3 ++- Essentials/src/main/resources/config.yml | 10 ++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index b3a35193934..0ef1491b337 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -405,6 +405,7 @@ public interface ISettings extends IConf { boolean isUpdateCheckEnabled(); boolean showZeroBaltop(); + BigDecimal getMultiplier(final User user); int getMaxItemLore(); 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 8efe5c54a1d..0fb0717b895 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -91,7 +91,8 @@ public void run(final Server server, final User user, final String commandLabel, 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) == null ? null : ess.getWorth().getPrice(ess, is).multiply(ess.getSettings().getMultiplier(user)); + 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 Exception(tl("itemCannotBeSold")); diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index f422ec236e2..ac734237e15 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -854,12 +854,10 @@ show-zero-baltop: true # For 1'234,50 use fr-ch #currency-symbol-format-locale: en-US -# Settings for /sell multipliers -# Give multipliers to players with the permission 'essentials.sell.multiplier.{multiplier}' -# example: 'essentials.sell.multiplier.double', 'essentials.sell.multiplier.triple' -# You can add as many multipliers as you want. -# Use the "default" name to set the default multiplier that everyone has. It defaults to 1 if not set. -# If a player has more than one multiplier permission, it will pick the highest one. +# 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 From 0d2e85087b64d01e2df557d5d9a1ac696197ba5e Mon Sep 17 00:00:00 2001 From: JRoy <10731363+JRoy@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:58:13 -0500 Subject: [PATCH 3/4] fix sell sign --- .../src/main/java/com/earth2me/essentials/signs/SignSell.java | 1 + 1 file changed, 1 insertion(+) 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 1e1079f2588..5841e2b6ee6 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 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri //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); } } From 9ec97e3b70758b830fab8bbd3fd23d0179969620 Mon Sep 17 00:00:00 2001 From: JRoy <10731363+JRoy@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:02:37 -0500 Subject: [PATCH 4/4] codestyle --- .../java/com/earth2me/essentials/Settings.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index cc4286c024e..f817dca9273 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -2096,13 +2096,19 @@ public boolean showZeroBaltop() { @Override public BigDecimal getMultiplier(final User user) { BigDecimal multiplier = defaultMultiplier; - if (multiplierPerms == null) return defaultMultiplier; - for (String multiplierPerm : multiplierPerms) { + if (multiplierPerms == null) { + return defaultMultiplier; + } + + for (final String multiplierPerm : multiplierPerms) { if (user.isAuthorized("essentials.sell.multiplier." + multiplierPerm)) { - BigDecimal value = config.getBigDecimal("sell-multipliers." + multiplierPerm, BigDecimal.ZERO); - if (value.compareTo(multiplier) > 0) multiplier = value; + final BigDecimal value = config.getBigDecimal("sell-multipliers." + multiplierPerm, BigDecimal.ZERO); + if (value.compareTo(multiplier) > 0) { + multiplier = value; + } } } + return multiplier; }