mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-07 07:06:41 +02:00
Unnecessary RegEx is unnecessary. Also storing Patterns in their classes for reuse.
437b01e371
c4e10da646
This commit is contained in:
@@ -6,6 +6,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.ess3.utils.Util;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import net.ess3.api.IEssentials;
|
||||
@@ -95,7 +97,6 @@ public class ItemDb implements IItemDb
|
||||
|
||||
private final Pattern idMatch = Pattern.compile("^\\d+[:+',;.]\\d+$");
|
||||
private final Pattern metaSplit = Pattern.compile("[:+',;.]");
|
||||
private final Pattern number = Pattern.compile("^\\d+$");
|
||||
private final Pattern conjoined = Pattern.compile("^[^:+',;.]+[:+',;.]\\d+$");
|
||||
|
||||
@Override
|
||||
@@ -110,7 +111,7 @@ public class ItemDb implements IItemDb
|
||||
itemid = Integer.parseInt(split[0]);
|
||||
metaData = Short.parseShort(split[1]);
|
||||
}
|
||||
else if (number.matcher(id).matches())
|
||||
else if (Util.isInt(id))
|
||||
{
|
||||
itemid = Integer.parseInt(id);
|
||||
}
|
||||
|
@@ -5,7 +5,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.ess3.utils.Util;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
|
||||
@@ -16,7 +17,6 @@ public final class Enchantments
|
||||
{
|
||||
}
|
||||
|
||||
private static final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||
|
||||
static
|
||||
@@ -116,7 +116,7 @@ public final class Enchantments
|
||||
public static Enchantment getByName(final String name)
|
||||
{
|
||||
Enchantment enchantment;
|
||||
if (NUMPATTERN.matcher(name).matches())
|
||||
if (Util.isInt(name))
|
||||
{
|
||||
enchantment = Enchantment.getById(Integer.parseInt(name));
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.ess3.utils.Util;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -20,7 +22,6 @@ import org.yaml.snakeyaml.nodes.*;
|
||||
|
||||
public class BukkitConstructor extends Constructor
|
||||
{
|
||||
private final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
private final transient Pattern DATAPATTERN = Pattern.compile("[:+',;.]");
|
||||
private final transient Pattern WORD = Pattern.compile("\\W");
|
||||
private final transient IPlugin plugin;
|
||||
@@ -43,7 +44,7 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
final String val = (String)constructScalar((ScalarNode)node);
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(val).matches())
|
||||
if (Util.isInt(val))
|
||||
{
|
||||
final int typeId = Integer.parseInt(val);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -67,7 +68,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(split[0]).matches())
|
||||
if (Util.isInt(split[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split[0]);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -81,7 +82,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
byte data = 0;
|
||||
if (split.length == 2 && NUMPATTERN.matcher(split[1]).matches())
|
||||
if (split.length == 2 && Util.isInt(split[1]))
|
||||
{
|
||||
data = Byte.parseByte(split[1]);
|
||||
}
|
||||
@@ -105,7 +106,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Material mat;
|
||||
if (NUMPATTERN.matcher(split2[0]).matches())
|
||||
if (Util.isInt(split2[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split2[0]);
|
||||
mat = Material.getMaterial(typeId);
|
||||
@@ -119,12 +120,12 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
short data = 0;
|
||||
if (split2.length == 2 && NUMPATTERN.matcher(split2[1]).matches())
|
||||
if (split2.length == 2 && Util.isInt(split2[1]))
|
||||
{
|
||||
data = Short.parseShort(split2[1]);
|
||||
}
|
||||
int size = mat.getMaxStackSize();
|
||||
if (split1.length > 1 && NUMPATTERN.matcher(split1[1]).matches())
|
||||
if (split1.length > 1 && Util.isInt(split1[1]))
|
||||
{
|
||||
size = Integer.parseInt(split1[1]);
|
||||
}
|
||||
@@ -139,7 +140,7 @@ public class BukkitConstructor extends Constructor
|
||||
continue;
|
||||
}
|
||||
Enchantment enchantment;
|
||||
if (NUMPATTERN.matcher(split3[0]).matches())
|
||||
if (Util.isInt(split3[0]))
|
||||
{
|
||||
final int enchantId = Integer.parseInt(split3[0]);
|
||||
enchantment = Enchantment.getById(enchantId);
|
||||
@@ -153,7 +154,7 @@ public class BukkitConstructor extends Constructor
|
||||
continue;
|
||||
}
|
||||
int level = enchantment.getStartLevel();
|
||||
if (split3.length == 2 && NUMPATTERN.matcher(split3[1]).matches())
|
||||
if (split3.length == 2 && Util.isInt(split3[1]))
|
||||
{
|
||||
level = Integer.parseInt(split3[1]);
|
||||
}
|
||||
@@ -183,7 +184,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
Enchantment enchant;
|
||||
if (NUMPATTERN.matcher(split[0]).matches())
|
||||
if (Util.isInt(split[0]))
|
||||
{
|
||||
final int typeId = Integer.parseInt(split[0]);
|
||||
enchant = Enchantment.getById(typeId);
|
||||
@@ -197,7 +198,7 @@ public class BukkitConstructor extends Constructor
|
||||
return null;
|
||||
}
|
||||
int level = enchant.getStartLevel();
|
||||
if (split.length == 2 && NUMPATTERN.matcher(split[1]).matches())
|
||||
if (split.length == 2 && Util.isInt(split[1]))
|
||||
{
|
||||
level = Integer.parseInt(split[1]);
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import java.util.regex.Pattern;
|
||||
public class PastieUpload
|
||||
{
|
||||
private final transient PostToUrl connection;
|
||||
private final Pattern pattern = Pattern.compile("(?s).*\\?key=([a-z0-9]+).*");
|
||||
|
||||
public PastieUpload() throws MalformedURLException
|
||||
{
|
||||
@@ -26,7 +27,7 @@ public class PastieUpload
|
||||
map.put("paste[body]", data);
|
||||
map.put("paste[restricted]", "1");
|
||||
final String html = connection.send(map);
|
||||
final Matcher matcher = Pattern.compile("(?s).*\\?key=([a-z0-9]+).*").matcher(html);
|
||||
final Matcher matcher = pattern.matcher(html);
|
||||
if (matcher.matches())
|
||||
{
|
||||
final String key = matcher.group(1);
|
||||
|
@@ -20,6 +20,7 @@ public class UpdateCheck
|
||||
private final static int CHECK_INTERVAL = 20 * 60 * 60 * 6;
|
||||
private final transient Plugin plugin;
|
||||
private transient boolean essentialsInstalled;
|
||||
private final Pattern bukkitVersionPattern = Pattern.compile("git-Bukkit-(?:(?:[0-9]+)\\.)+[0-9]+-R[\\.0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.*");
|
||||
|
||||
public UpdateCheck(final Plugin plugin)
|
||||
{
|
||||
@@ -188,8 +189,7 @@ public class UpdateCheck
|
||||
|
||||
private int getBukkitVersion()
|
||||
{
|
||||
final Matcher versionMatch = Pattern.compile("git-Bukkit-(?:(?:[0-9]+)\\.)+[0-9]+-R[\\.0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.*").matcher(
|
||||
plugin.getServer().getVersion());
|
||||
final Matcher versionMatch = bukkitVersionPattern.matcher(plugin.getServer().getVersion());
|
||||
if (versionMatch.matches())
|
||||
{
|
||||
return Integer.parseInt(versionMatch.group(1));
|
||||
|
Reference in New Issue
Block a user