[trunk] metadata support in itemsdb.java, allows worth commands with metadata

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1364 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-05-07 13:03:45 +00:00
parent bd5b8eacd0
commit 31f5802611
2 changed files with 14 additions and 2 deletions

View File

@ -89,14 +89,25 @@ public class ItemDb
public static ItemStack get(String id) throws Exception
{
int itemid = getUnsafe(id);
int itemid;
short metaData =0;
if(id.matches("^\\d+:\\d+$"))
{
itemid = getUnsafe(id.split(":")[0]);
metaData = (short)getUnsafe(id.split(":")[1]);
}
else
{
itemid = getUnsafe(id);
}
Material mat = Material.getMaterial(itemid);
if (mat == null) {
throw new Exception("Unknown item id: "+itemid);
}
ItemStack retval = new ItemStack(mat);
retval.setAmount(Essentials.getStatic().getSettings().getDefaultStackSize());
retval.setDurability(durabilities.containsKey(id.toLowerCase()) ? durabilities.get(id.toLowerCase()) : 0);
retval.setDurability(metaData !=0 ? metaData :(durabilities.containsKey(id.toLowerCase()) ? durabilities.get(id.toLowerCase()) : 0));
return retval;
}

View File

@ -49,6 +49,7 @@ public class Commandworth extends EssentialsCommand
user.charge(this);
user.sendMessage("§7Stack of "
+ is.getType().toString().toLowerCase().replace("_", "")
+ (is.getDurability() !=0 ? " with metadata of "+ String.valueOf(is.getDurability()) : "")
+ " worth §c" + Util.formatCurrency(worth*amount) + "§7 ("
+ amount + " item(s) at " + Util.formatCurrency(worth) + " each)");
}