From 09ab9815857f0d695fdaa9d257673b2fc3d733eb Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 16 Apr 2011 06:45:37 +0000 Subject: [PATCH] [trunk] Worth/Sell: Support for double values as prices and more important: support for data items. the yaml structure has changed, there is a fallback to the old structure. This code is untested. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1212 e251c2fe-e539-e718-e476-b85c1f46cddb --- .../src/com/earth2me/essentials/Worth.java | 8 ++++---- .../essentials/commands/Commandworth.java | 17 +++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java index ce3e83980..3c074657f 100644 --- a/Essentials/src/com/earth2me/essentials/Worth.java +++ b/Essentials/src/com/earth2me/essentials/Worth.java @@ -19,9 +19,9 @@ public class Worth implements IConf public double getPrice(ItemStack itemStack) { - double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), Double.NaN); + double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getData().getData(), Double.NaN); if (Double.isNaN(result)) { - result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase(), Double.NaN); + result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", ""), Double.NaN); } if (Double.isNaN(result)) { result = config.getDouble("worth-"+itemStack.getTypeId(), 0.0); @@ -32,9 +32,9 @@ public class Worth implements IConf public void setPrice(ItemStack itemStack, double price) { if (itemStack.getType().getData() == null) { - config.setProperty("worth." + itemStack.getType().toString().toLowerCase(), price); + config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price); } else { - config.setProperty("worth." + itemStack.getType().toString().toLowerCase()+"."+itemStack.getData().getData(), price); + config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getData().getData(), price); } config.removeProperty("worth-"+itemStack.getTypeId()); config.save(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index 66e1be715..aee5041c2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -18,30 +18,27 @@ public class Commandworth extends EssentialsCommand public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception { ItemStack is = user.getInventory().getItemInHand(); - int id = is.getTypeId(); int amount = is.getAmount(); - try - { - if (args.length > 0) id = Integer.parseInt(args[0]); - } - catch (NumberFormatException ex) - { - id = ItemDb.get(args[0]).getTypeId(); + if (args.length > 0) { + is = ItemDb.get(args[0]); } try { - if (args.length > 1) amount = Integer.parseInt(args[1]); + if (args.length > 1) { + amount = Integer.parseInt(args[1]); + } } catch (NumberFormatException ex) { amount = 64; } + is.setAmount(amount); double worth = Essentials.getWorth().getPrice(is); user.charge(this); - user.sendMessage("§7Stack of " + id + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)"); + user.sendMessage("§7Stack of " + is.getType().toString().toLowerCase().replace("_", "") + " worth §c$" + (worth * amount) + "§7 (" + amount + " item(s) at $" + worth + " each)"); } }