diff options
author | Chris Ward <chris@chrisgward.com> | 2013-01-08 02:26:09 +1100 |
---|---|---|
committer | Chris Ward <chris@chrisgward.com> | 2013-01-08 02:26:09 +1100 |
commit | c4e10da646a0066cff73b497cd283ae42cc775f0 (patch) | |
tree | deaaeea8ed7cc83b2c67b0f6a2b48f3feaeb531e | |
parent | fbb1c1278ca0b8dc0d11a6f02d98036d9ff5c2d1 (diff) | |
download | Essentials-c4e10da646a0066cff73b497cd283ae42cc775f0.tar Essentials-c4e10da646a0066cff73b497cd283ae42cc775f0.tar.gz Essentials-c4e10da646a0066cff73b497cd283ae42cc775f0.tar.lz Essentials-c4e10da646a0066cff73b497cd283ae42cc775f0.tar.xz Essentials-c4e10da646a0066cff73b497cd283ae42cc775f0.zip |
Store regex, use util method instead of another regex. Store variable
-rw-r--r-- | Essentials/src/com/earth2me/essentials/ItemDb.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 820aea12d..80c54a5a2 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -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; |