[trunk] ItemDb.get(): Added support for other seperation characters : + ' , ; .

added support for itemname:data, e.g. wool:7

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1385 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-05-09 00:48:21 +00:00
parent e9927519c4
commit 3195470b1b

View File

@ -97,28 +97,42 @@ public class ItemDb
public static ItemStack get(String id) throws Exception public static ItemStack get(String id) throws Exception
{ {
int itemid; int itemid = 0;
String itemname = null;
short metaData = 0; short metaData = 0;
if (id.matches("^\\d+:\\d+$")) if (id.matches("^\\d+[:+',;.]\\d+$"))
{ {
itemid = Integer.parseInt(id.split(":")[0]); itemid = Integer.parseInt(id.split("[:+',;.]")[0]);
metaData = Short.parseShort(id.split(":")[1]); metaData = Short.parseShort(id.split("[:+',;.]")[1]);
} }
else if (id.matches("^\\d+$")) else if (id.matches("^\\d+$"))
{ {
itemid = Integer.parseInt(id); itemid = Integer.parseInt(id);
} }
else if (items.containsKey(id.toLowerCase())) else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
{ {
itemid = items.get(id.toLowerCase()); itemname = id.split("[:+',;.]")[0].toLowerCase();
if (durabilities.containsKey(id.toLowerCase())) metaData = Short.parseShort(id.split("[:+',;.]")[1]);
{
metaData = durabilities.get(id.toLowerCase());
}
} }
else else
{ {
throw new Exception("Unknown item name: " + id); itemname = id.toLowerCase();
}
if (itemname != null)
{
if (items.containsKey(itemname))
{
itemid = items.get(itemname);
if (durabilities.containsKey(itemname) && metaData == 0)
{
metaData = durabilities.get(itemname);
}
}
else
{
throw new Exception("Unknown item name: " + id);
}
} }
Material mat = Material.getMaterial(itemid); Material mat = Material.getMaterial(itemid);