Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Essentials/src/com/earth2me/essentials/ISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ public interface ISettings extends IConf {

boolean isAllowBulkBuySell();

boolean isAllowSellNamedItems();

boolean isAddingPrefixInPlayerlist();

boolean isAddingSuffixInPlayerlist();
Expand Down
5 changes: 5 additions & 0 deletions Essentials/src/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,11 @@ public boolean isAllowBulkBuySell() {
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);
Expand Down
21 changes: 21 additions & 0 deletions Essentials/src/com/earth2me/essentials/commands/Commandsell.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
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;
Expand Down Expand Up @@ -41,7 +43,17 @@ public void run(final Server server, final User user, final String commandLabel,

boolean isBulk = is.size() > 1;

List<ItemStack> 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));
Expand All @@ -59,6 +71,15 @@ public void run(final Server server, final User user, final String commandLabel,
}
}
}
if (!notSold.isEmpty()) {
List<String> 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)));
Expand Down
4 changes: 4 additions & 0 deletions Essentials/src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Essentials/src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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\!
Expand Down