[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
This commit is contained in:
snowleo 2011-04-16 06:45:37 +00:00
parent c849bf7fe9
commit 09ab981585
2 changed files with 11 additions and 14 deletions

View File

@ -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();

View File

@ -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)");
}
}