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