mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-05-29 02:27:35 +00:00
[trunk] Rewritten ItemDb.get(), removed the getUnsafe function.
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1383 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
e0f103c7d8
commit
ed47df93e9
1 changed files with 36 additions and 28 deletions
|
@ -31,7 +31,10 @@ public class ItemDb
|
||||||
FileWriter tx = new FileWriter(file);
|
FileWriter tx = new FileWriter(file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; (i = res.read()) > 0;) tx.write(i);
|
for (int i = 0; (i = res.read()) > 0;)
|
||||||
|
{
|
||||||
|
tx.write(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -58,11 +61,15 @@ public class ItemDb
|
||||||
{
|
{
|
||||||
String line = rx.readLine().trim().toLowerCase();
|
String line = rx.readLine().trim().toLowerCase();
|
||||||
if (line.startsWith("#"))
|
if (line.startsWith("#"))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String[] parts = line.split("[^a-z0-9]");
|
String[] parts = line.split("[^a-z0-9]");
|
||||||
if (parts.length < 2)
|
if (parts.length < 2)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int numeric = Integer.parseInt(parts[1]);
|
int numeric = Integer.parseInt(parts[1]);
|
||||||
|
|
||||||
|
@ -81,7 +88,8 @@ public class ItemDb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack get(String id, int quantity) throws Exception {
|
public static ItemStack get(String id, int quantity) throws Exception
|
||||||
|
{
|
||||||
ItemStack retval = get(id.toLowerCase());
|
ItemStack retval = get(id.toLowerCase());
|
||||||
retval.setAmount(quantity);
|
retval.setAmount(quantity);
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -90,37 +98,37 @@ public class ItemDb
|
||||||
public static ItemStack get(String id) throws Exception
|
public static ItemStack get(String id) throws Exception
|
||||||
{
|
{
|
||||||
int itemid;
|
int itemid;
|
||||||
short metaData =0;
|
short metaData = 0;
|
||||||
if(id.matches("^\\d+:\\d+$"))
|
if (id.matches("^\\d+:\\d+$"))
|
||||||
{
|
{
|
||||||
itemid = getUnsafe(id.split(":")[0]);
|
itemid = Integer.parseInt(id.split(":")[0]);
|
||||||
metaData = (short)getUnsafe(id.split(":")[1]);
|
metaData = Short.parseShort(id.split(":")[1]);
|
||||||
|
}
|
||||||
|
else if (id.matches("^\\d+$"))
|
||||||
|
{
|
||||||
|
itemid = Integer.parseInt(id);
|
||||||
|
}
|
||||||
|
else if (items.containsKey(id.toLowerCase()))
|
||||||
|
{
|
||||||
|
itemid = items.get(id.toLowerCase());
|
||||||
|
if (durabilities.containsKey(id.toLowerCase()))
|
||||||
|
{
|
||||||
|
metaData = durabilities.get(id.toLowerCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemid = getUnsafe(id);
|
throw new Exception("Unknown item name: " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material mat = Material.getMaterial(itemid);
|
Material mat = Material.getMaterial(itemid);
|
||||||
if (mat == null) {
|
if (mat == null)
|
||||||
throw new Exception("Unknown item id: "+itemid);
|
{
|
||||||
|
throw new Exception("Unknown item id: " + itemid);
|
||||||
}
|
}
|
||||||
ItemStack retval = new ItemStack(mat);
|
ItemStack retval = new ItemStack(mat);
|
||||||
retval.setAmount(Essentials.getStatic().getSettings().getDefaultStackSize());
|
retval.setAmount(Essentials.getStatic().getSettings().getDefaultStackSize());
|
||||||
retval.setDurability(metaData !=0 ? metaData :(durabilities.containsKey(id.toLowerCase()) ? durabilities.get(id.toLowerCase()) : 0));
|
retval.setDurability(metaData);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getUnsafe(String id) throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Integer.parseInt(id);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
if (items.containsKey(id.toLowerCase())) return items.get(id.toLowerCase());
|
|
||||||
throw new Exception("Unknown item name: " + id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue