summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/commands/Commandsell.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index a8ef83dc0..d59c09b1e 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -1,12 +1,14 @@
package com.earth2me.essentials.commands;
-import org.bukkit.Server;
-import com.earth2me.essentials.InventoryWorkaround;
+import static com.earth2me.essentials.I18n._;
+import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
+import java.util.Locale;
import java.util.logging.Level;
import org.bukkit.Material;
+import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
@@ -18,7 +20,7 @@ public class Commandsell extends EssentialsCommand
}
@Override
- public void run(Server server, User user, String commandLabel, String[] args) throws Exception
+ public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
@@ -76,7 +78,7 @@ public class Commandsell extends EssentialsCommand
{
if (is == null || is.getType() == Material.AIR)
{
- throw new Exception(Util.i18n("itemSellAir"));
+ throw new Exception(_("itemSellAir"));
}
int id = is.getTypeId();
int amount = 0;
@@ -94,11 +96,11 @@ public class Commandsell extends EssentialsCommand
if (Double.isNaN(worth))
{
- throw new Exception(Util.i18n("itemCannotBeSold"));
+ throw new Exception(_("itemCannotBeSold"));
}
if (requireStack && !stack)
{
- throw new Exception(Util.i18n("itemMustBeStacked"));
+ throw new Exception(_("itemMustBeStacked"));
}
@@ -117,12 +119,16 @@ public class Commandsell extends EssentialsCommand
{
continue;
}
+ if (!s.getEnchantments().equals(is.getEnchantments()))
+ {
+ continue;
+ }
max += s.getAmount();
}
if (stack)
{
- amount *= 64;
+ amount *= is.getType().getMaxStackSize();
}
if (amount < 1)
{
@@ -131,15 +137,15 @@ public class Commandsell extends EssentialsCommand
if (requireStack)
{
- amount -= amount % 64;
+ amount -= amount % is.getType().getMaxStackSize();
}
if (amount > max || amount < 1)
{
if (!isBulkSell)
{
- user.sendMessage(Util.i18n("itemNotEnough1"));
- user.sendMessage(Util.i18n("itemNotEnough2"));
- throw new Exception(Util.i18n("itemNotEnough3"));
+ user.sendMessage(_("itemNotEnough1"));
+ user.sendMessage(_("itemNotEnough2"));
+ throw new Exception(_("itemNotEnough3"));
}
else
{
@@ -147,13 +153,15 @@ public class Commandsell extends EssentialsCommand
}
}
- final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability());
- InventoryWorkaround.removeItem(user.getInventory(), true, ris);
+ //TODO: Prices for Enchantments
+ final ItemStack ris = is.clone();
+ ris.setAmount(amount);
+ InventoryWorkaround.removeItem(user.getInventory(), true, true, ris);
user.updateInventory();
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), user.getLocation(), ess);
user.giveMoney(worth * amount);
- user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount, ess), amount, is.getType().toString().toLowerCase(), Util.formatCurrency(worth, ess)));
- logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
+ user.sendMessage(_("itemSold", Util.formatCurrency(worth * amount, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.formatCurrency(worth, ess)));
+ logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
}
}