Skip to content

Commit

Permalink
v0.0.7 - Add legacy version string matching as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicallyCoded committed Oct 24, 2024
1 parent c2f370e commit 8496c8c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id 'java'
id 'maven-publish'
}

group = 'com.tcoded'
version = '0.0.6'
group = 'com.tcoded.lightlibs'
version = '0.0.7'

repositories {
mavenCentral()
Expand All @@ -16,4 +17,16 @@ dependencies {

test {
useJUnitPlatform()
}

publishing {
publications {
maven(MavenPublication) {
groupId = group
artifactId = project.name
version = version

from components.java
}
}
}
23 changes: 21 additions & 2 deletions src/main/java/com/tcoded/lightlibs/bukkitversion/MCVersion.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tcoded.lightlibs.bukkitversion;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public enum MCVersion {

Expand Down Expand Up @@ -78,8 +80,25 @@ public static MCVersion fromMcVersion(String mcVersion) {
public static MCVersion fromServerVersion(String serverVersion) {
Objects.requireNonNull(serverVersion, "serverVersion cannot be null");

String mcVersionSection = serverVersion.split("-")[0];
return fromMcVersion(mcVersionSection);
MCVersion mcVersion;
String mcVersionSection;

// Attempt match for modern Paper format
// 1.21.1-98-master@9b1ee0d
mcVersionSection = serverVersion.split("-")[0];
mcVersion = fromMcVersion(mcVersionSection);
if (mcVersion != null) return mcVersion;

// Attempt match for legacy Spigot format
// git-Paper-496 (MC: 1.20.4)
// 4352-Spigot-5eb8a94-55141ae (MC: 1.21.3)
Matcher matcher = Pattern.compile("\\(MC: (1\\.\\S+)\\)").matcher(serverVersion);
if (matcher.find()) {
mcVersionSection = matcher.group(1);
mcVersion = fromMcVersion(mcVersionSection);
}

return mcVersion;
}

public static MCVersion getLatest() {
Expand Down

0 comments on commit 8496c8c

Please sign in to comment.