From 2b4dd0c82b6402db22151e7bc74625fa7ae5f7d7 Mon Sep 17 00:00:00 2001 From: Xitee <59659167+Xitee1@users.noreply.github.com> Date: Sat, 25 Apr 2026 23:51:03 +0200 Subject: [PATCH] Fix version parsing for Paper 26+ Bukkit.getBukkitVersion() on Paper 26.1.2 no longer matches the legacy "-R-SNAPSHOT" format, so the substring-based parser produced a StringIndexOutOfBoundsException, preventing the plugin from enabling. Replace it with a regex that extracts only the leading numeric version, tolerating arbitrary suffixes, and add a safe fallback so a parsing failure no longer aborts onEnable(). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/main/java/de/xite/smp/main/Main.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/xite/smp/main/Main.java b/src/main/java/de/xite/smp/main/Main.java index 17ebadb..6301432 100644 --- a/src/main/java/de/xite/smp/main/Main.java +++ b/src/main/java/de/xite/smp/main/Main.java @@ -53,7 +53,20 @@ public void onEnable() { // Set the current detected MC version String vstring = Bukkit.getBukkitVersion(); - MCVersion = vstring.substring(0, vstring.lastIndexOf("-R")).replace("_", "."); + try { + // Extracts the leading numeric version, tolerating arbitrary suffixes: + // "1.21.4-R0.1-SNAPSHOT" -> "1.21.4" + // "26.1.2-build.12-alpha" -> "26.1.2" + // "26.1.2.build.12-alpha" -> "26.1.2" + Matcher m = Pattern.compile("^([0-9]+(?:\\.[0-9]+)*)").matcher(vstring.replace("_", ".")); + if(!m.find()) + throw new IllegalArgumentException("No leading version number in '" + vstring + "'"); + MCVersion = m.group(1); + } catch (Exception e) { + e.printStackTrace(); + getLogger().severe("Could not extract MC version from '" + vstring + "'! Defaulting to 1.20."); + MCVersion = "1.20"; + } // Load config and services pluginConfig = new PluginConfig();