diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 6a40d5efaf2..58068425e31 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -148,7 +148,7 @@ public class GeyserImpl implements GeyserApi, EventRegistrar { */ public static final String OAUTH_CLIENT_ID = "204cefd1-4818-4de1-b98d-513fae875d88"; - private static final String IP_REGEX = "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"; + private static final Pattern IP_REGEX = Pattern.compile("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"); private final SessionManager sessionManager = new SessionManager(); @@ -406,7 +406,7 @@ private void startInstance() { String remoteAddress = config.getRemote().address(); // Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry. - if (!remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) { + if (!IP_REGEX.matcher(remoteAddress).matches() && !remoteAddress.equalsIgnoreCase("localhost")) { String[] record = WebUtils.findSrvRecord(this, remoteAddress); if (record != null) { int remotePort = Integer.parseInt(record[2]); diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java index 10cbcf55686..2bfa6cce6a8 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java @@ -63,7 +63,7 @@ @RequiredArgsConstructor public class GeyserExtensionLoader extends ExtensionLoader { - private static final Pattern[] EXTENSION_FILTERS = new Pattern[] { Pattern.compile("^.+\\.jar$") }; + private static final Pattern EXTENSION_FILTER = Pattern.compile("^.+\\.jar$"); private final Object2ObjectMap> classes = new Object2ObjectOpenHashMap<>(); private final Map classLoaders = new HashMap<>(); @@ -133,8 +133,8 @@ public GeyserExtensionDescription extensionDescription(Path path) throws Invalid } } - public Pattern[] extensionFilters() { - return EXTENSION_FILTERS; + public Pattern extensionFilter() { + return EXTENSION_FILTER; } public Class classByName(final String name) throws ClassNotFoundException{ @@ -249,17 +249,15 @@ protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) { */ private void processExtensionsFolder(Path directory, ThrowingBiConsumer accept, BiConsumer reject) throws IOException { List extensionPaths = Files.list(directory).toList(); - Pattern[] extensionFilters = this.extensionFilters(); + Pattern extensionFilter = this.extensionFilter(); extensionPaths.forEach(path -> { if (Files.isDirectory(path)) { return; } // Only look at files that meet the extension filter - for (Pattern filter : extensionFilters) { - if (!filter.matcher(path.getFileName().toString()).matches()) { - return; - } + if (!extensionFilter.matcher(path.getFileName().toString()).matches()) { + return; } try { diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java index ec72433964c..3e09666bfe0 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java @@ -48,9 +48,12 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.function.Function; +import java.util.regex.Pattern; public class CustomSkullRegistryPopulator { + private static final Pattern SKULL_HASH_PATTERN = Pattern.compile("^[a-fA-F0-9]{64}$"); + public static void populate() { SkullResourcePackManager.SKULL_SKINS.clear(); // Remove skins after reloading BlockRegistries.CUSTOM_SKULLS.set(Object2ObjectMaps.emptyMap()); @@ -117,7 +120,7 @@ public void register(@NonNull String texture, @NonNull SkullTextureType type) { }); skinHashes.forEach((skinHash) -> { - if (!skinHash.matches("^[a-fA-F0-9]+$")) { + if (!SKULL_HASH_PATTERN.matcher(skinHash).matches()) { GeyserImpl.getInstance().getLogger().error("Skin hash " + skinHash + " does not match required format ^[a-fA-F0-9]{64}$ and will not be added as a custom block."); return; }