Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/de/xite/smp/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down