mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-06-23 13:15:02 +02:00
Add config option to control selling names items with /sell (#3314)
Adds an `allow-selling-named-items` config option, which allows server admins to enable/disable the ability to sell named items with `/sell`. Closes #1988. Closes #908. Closes #2196.
This commit is contained in:
parent
3e5bd4cf09
commit
6aa5e5cc4a
|
@ -320,6 +320,8 @@ public interface ISettings extends IConf {
|
|||
|
||||
boolean isAllowBulkBuySell();
|
||||
|
||||
boolean isAllowSellNamedItems();
|
||||
|
||||
boolean isAddingPrefixInPlayerlist();
|
||||
|
||||
boolean isAddingSuffixInPlayerlist();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<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));
|
||||
|
@ -59,6 +71,15 @@ public class Commandsell extends EssentialsCommand {
|
|||
}
|
||||
}
|
||||
}
|
||||
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)));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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\!
|
||||
|
|
Loading…
Reference in New Issue
Block a user