diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index e7ce055c5..81365a4a1 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -320,6 +320,8 @@ public interface ISettings extends IConf { boolean isAllowBulkBuySell(); + boolean isAllowSellNamedItems(); + boolean isAddingPrefixInPlayerlist(); boolean isAddingSuffixInPlayerlist(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index d0a03650a..0582d2bef 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -1486,6 +1486,11 @@ public class Settings implements net.ess3.api.ISettings { return config.getBoolean("allow-bulk-buy-sell", false); } + @Override + public boolean isAllowSellNamedItems() { + return config.getBoolean("allow-selling-named-items", false); + } + @Override public boolean isAddingPrefixInPlayerlist() { return config.getBoolean("add-prefix-in-playerlist", false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index 64d36b82a..53b6297ae 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -5,10 +5,12 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.collect.Lists; import net.ess3.api.events.UserBalanceUpdateEvent; +import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -41,7 +43,17 @@ public class Commandsell extends EssentialsCommand { boolean isBulk = is.size() > 1; + List notSold = new ArrayList<>(); for (ItemStack stack : is) { + if (!ess.getSettings().isAllowSellNamedItems()) { + if (stack.getItemMeta() != null && stack.getItemMeta().hasDisplayName()) { + if (isBulk) { + notSold.add(stack); + continue; + } + throw new Exception(tl("cannotSellNamedItem")); + } + } try { if (stack.getAmount() > 0) { totalWorth = totalWorth.add(sellItem(user, stack, args, isBulk)); @@ -59,6 +71,15 @@ public class Commandsell extends EssentialsCommand { } } } + if (!notSold.isEmpty()) { + List names = new ArrayList<>(); + for (ItemStack stack : notSold) { + if (stack.getItemMeta() != null) { //This was already validated but IDE still freaks out + names.add(stack.getItemMeta().getDisplayName()); + } + } + ess.showError(user.getSource(), new Exception(tl("cannotSellTheseNamedItems", String.join(ChatColor.RESET + ", ", names))), commandLabel); + } if (count != 1) { if (args[0].equalsIgnoreCase("blocks")) { user.sendMessage(tl("totalWorthBlocks", type, NumberUtil.displayCurrency(totalWorth, ess))); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 91e766b55..d2e2a8742 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -573,6 +573,10 @@ npcs-in-balance-ranking: false # This is useful when a sign sells or buys one item at a time and the player wants to sell a bunch at once. allow-bulk-buy-sell: true +# Allow selling of items with custom names with the /sell command. +# This may be useful to prevent players accidentally selling named items. +allow-selling-named-items: false + # Delay for the MOTD display for players on join, in milliseconds. # This has no effect if the MOTD command or permission are disabled. delay-motd: 0 diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 41d99be20..f102f3f12 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -50,6 +50,8 @@ bookLocked=\u00a76This book is now locked. bookTitleSet=\u00a76Title of the book set to {0}. broadcast=\u00a76[\u00a74Broadcast\u00a76]\u00a7a {0} burnMsg=\u00a76You set\u00a7c {0} \u00a76on fire for\u00a7c {1} seconds\u00a76. +cannotSellNamedItem=\u00a76You are not allowed to sell named items. +cannotSellTheseNamedItems=\u00a76You are not allowed to sell these named items: \u00a74{0} cannotStackMob=\u00a74You do not have permission to stack multiple mobs. canTalkAgain=\u00a76You can now talk again. cantFindGeoIpDB=Can''t find GeoIP database\!