Store regex, use util method instead of another regex. Store variable

This commit is contained in:
Chris Ward 2013-01-08 02:26:09 +11:00
parent fbb1c1278c
commit c4e10da646

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IItemDb;
import java.util.*;
import java.util.regex.Pattern;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@ -21,6 +22,7 @@ public class ItemDb implements IConf, IItemDb
private final transient Map<ItemData, List<String>> names = new HashMap<ItemData, List<String>>();
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
private final transient ManagedFile file;
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
@Override
public void reloadConfig()
@ -85,19 +87,20 @@ public class ItemDb implements IConf, IItemDb
int itemid = 0;
String itemname = null;
short metaData = 0;
String[] parts = splitPattern.split(id);;
if (id.matches("^\\d+[:+',;.]\\d+$"))
{
itemid = Integer.parseInt(id.split("[:+',;.]")[0]);
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
itemid = Integer.parseInt(parts[0]);
metaData = Short.parseShort(parts[1]);
}
else if (id.matches("^\\d+$"))
else if (Util.isInt(id))
{
itemid = Integer.parseInt(id);
}
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
{
itemname = id.split("[:+',;.]")[0].toLowerCase(Locale.ENGLISH);
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
itemname = parts[0].toLowerCase(Locale.ENGLISH);
metaData = Short.parseShort(parts[1]);
}
else
{
@ -138,7 +141,7 @@ public class ItemDb implements IConf, IItemDb
public void addStringEnchantment(final User user, final boolean allowUnsafe, final ItemStack stack, final String string) throws Exception
{
final String[] split = string.split("[:+',;.]", 2);
final String[] split = splitPattern.split(string, 2);
if (split.length < 1)
{
return;