From b17bb09b2b3c3e0db3963ed3c7a14cf13d8b14b7 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 16 Apr 2011 15:11:20 +0000 Subject: [PATCH] [trunk] /sell itemname amount New syntax for sell command, proposed by KimKandor It won't sell the items in hand anymore. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1219 e251c2fe-e539-e718-e476-b85c1f46cddb --- .../essentials/commands/Commandsell.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index 97cee37b6..73555ef50 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import org.bukkit.Server; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.InventoryWorkaround; +import com.earth2me.essentials.ItemDb; import com.earth2me.essentials.User; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -18,30 +19,49 @@ public class Commandsell extends EssentialsCommand @Override public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception { - ItemStack is = user.getInventory().getItemInHand(); - if(is.getType() == Material.AIR) + if (args.length < 1) { + user.sendMessage("§cUsage: /sell [amount]"); + return; + } + ItemStack is = ItemDb.get(args[0]); + if(is.getType() == Material.AIR) { throw new Exception("You really tried to sell Air? Put an item in your hand."); + } int id = is.getTypeId(); int amount = 0; - if (args.length > 0) amount = Integer.parseInt(args[0].replaceAll("[^0-9]", "")); + if (args.length > 1) { + amount = Integer.parseInt(args[0].replaceAll("[^0-9]", "")); + } double worth = Essentials.getWorth().getPrice(is); - boolean stack = args.length > 0 && args[0].endsWith("s"); + boolean stack = args.length > 1 && args[1].endsWith("s"); boolean requireStack = parent.getConfiguration().getBoolean("trade-in-stacks-" + id, false); - if (worth < 1) throw new Exception("That item cannot be sold to the server."); - if (requireStack && !stack) throw new Exception("Item must be traded in stacks. A quantity of 2s would be two stacks, etc."); + if (worth < 1) { + throw new Exception("That item cannot be sold to the server."); + } + if (requireStack && !stack) { + throw new Exception("Item must be traded in stacks. A quantity of 2s would be two stacks, etc."); + } int max = 0; - for (ItemStack s : user.getInventory().all(is).values()) + for (ItemStack s : user.getInventory().getContents()) { - if (s.getDurability() != is.getDurability()) + if (s.getTypeId() != is.getTypeId()) { continue; + } + if (s.getDurability() != is.getDurability()) { + continue; + } max += s.getAmount(); } - if (stack) amount *= 64; - if (amount < 1) amount += max; + if (stack) { + amount *= 64; + } + if (amount < 1) { + amount += max; + } if (requireStack) {