diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-04-16 06:45:37 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-04-16 06:45:37 +0000 |
commit | 09ab9815857f0d695fdaa9d257673b2fc3d733eb (patch) | |
tree | 9e7df8223b1376cd8cc30b768dae03ca17f008c5 | |
parent | c849bf7fe90576d9aa44252e9e7bf2649d23d531 (diff) | |
download | Essentials-09ab9815857f0d695fdaa9d257673b2fc3d733eb.tar Essentials-09ab9815857f0d695fdaa9d257673b2fc3d733eb.tar.gz Essentials-09ab9815857f0d695fdaa9d257673b2fc3d733eb.tar.lz Essentials-09ab9815857f0d695fdaa9d257673b2fc3d733eb.tar.xz Essentials-09ab9815857f0d695fdaa9d257673b2fc3d733eb.zip |
[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
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Worth.java | 8 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/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)"); } } |