mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-12 11:21:28 +01:00
Store regex, use util method instead of another regex. Store variable
This commit is contained in:
parent
fbb1c1278c
commit
c4e10da646
@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
|||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.IItemDb;
|
import com.earth2me.essentials.api.IItemDb;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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<ItemData, List<String>> names = new HashMap<ItemData, List<String>>();
|
||||||
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
|
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||||
private final transient ManagedFile file;
|
private final transient ManagedFile file;
|
||||||
|
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig()
|
public void reloadConfig()
|
||||||
@ -85,19 +87,20 @@ public class ItemDb implements IConf, IItemDb
|
|||||||
int itemid = 0;
|
int itemid = 0;
|
||||||
String itemname = null;
|
String itemname = null;
|
||||||
short metaData = 0;
|
short metaData = 0;
|
||||||
|
String[] parts = splitPattern.split(id);;
|
||||||
if (id.matches("^\\d+[:+',;.]\\d+$"))
|
if (id.matches("^\\d+[:+',;.]\\d+$"))
|
||||||
{
|
{
|
||||||
itemid = Integer.parseInt(id.split("[:+',;.]")[0]);
|
itemid = Integer.parseInt(parts[0]);
|
||||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
metaData = Short.parseShort(parts[1]);
|
||||||
}
|
}
|
||||||
else if (id.matches("^\\d+$"))
|
else if (Util.isInt(id))
|
||||||
{
|
{
|
||||||
itemid = Integer.parseInt(id);
|
itemid = Integer.parseInt(id);
|
||||||
}
|
}
|
||||||
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
|
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
|
||||||
{
|
{
|
||||||
itemname = id.split("[:+',;.]")[0].toLowerCase(Locale.ENGLISH);
|
itemname = parts[0].toLowerCase(Locale.ENGLISH);
|
||||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
metaData = Short.parseShort(parts[1]);
|
||||||
}
|
}
|
||||||
else
|
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
|
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)
|
if (split.length < 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user