Skip to content

Commit

Permalink
Added sell multipliers (#4770)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
  • Loading branch information
justinmtech and JRoy authored Dec 9, 2024
1 parent 424816e commit e1091d8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ public interface ISettings extends IConf {

boolean showZeroBaltop();

BigDecimal getMultiplier(final User user);

int getMaxItemLore();

Tag getPrimaryColor();
Expand Down
31 changes: 31 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public class Settings implements net.ess3.api.ISettings {
private Map<String, String> worldAliases;
private Tag primaryColor = DEFAULT_PRIMARY_COLOR;
private Tag secondaryColor = DEFAULT_SECONDARY_COLOR;
private Set<String> multiplierPerms;
private BigDecimal defaultMultiplier;

public Settings(final IEssentials ess) {
this.ess = ess;
Expand Down Expand Up @@ -921,6 +923,8 @@ public void reloadConfig() {
worldAliases = _getWorldAliases();
primaryColor = _getPrimaryColor();
secondaryColor = _getSecondaryColor();
multiplierPerms = _getMultiplierPerms();
defaultMultiplier = _getDefaultMultiplier();

reloadCount.incrementAndGet();
}
Expand Down Expand Up @@ -2090,6 +2094,33 @@ public boolean showZeroBaltop() {
}

@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<String> _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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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);
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.<multiplier-rank>
sell-multipliers:
default: 1.0
double: 2.0
triple: 3.0

############################################################
# +------------------------------------------------------+ #
# | Help | #
Expand Down

0 comments on commit e1091d8

Please sign in to comment.