Skip to content

Commit 90baa73

Browse files
committed
Update CraftBukkitReflection for 26.1
1 parent aaa49cb commit 90baa73

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cloud-bukkit/src/main/java/org/incendo/cloud/bukkit/internal/CraftBukkitReflection.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final class CraftBukkitReflection {
6565
if (Bukkit.getServer() != null) {
6666
try {
6767
final Method getMinecraftVersion = serverClass.getDeclaredMethod("getMinecraftVersion");
68-
fallbackVersion = Integer.parseInt(getMinecraftVersion.invoke(Bukkit.getServer()).toString().split("\\.")[1]);
68+
fallbackVersion = parseMajorRevision(getMinecraftVersion.invoke(Bukkit.getServer()).toString());
6969
} catch (final Exception ignored) {
7070
}
7171
} else {
@@ -85,7 +85,7 @@ public final class CraftBukkitReflection {
8585
}
8686
final String versionName = (String) getName.invoke(currentVersion);
8787
try {
88-
fallbackVersion = Integer.parseInt(versionName.split("\\.")[1]);
88+
fallbackVersion = parseMajorRevision(versionName);
8989
} catch (final Exception ignored) {
9090
}
9191
} catch (final ReflectiveOperationException e) {
@@ -102,6 +102,16 @@ public final class CraftBukkitReflection {
102102
CB_PKG_VERSION = name;
103103
}
104104

105+
private static int parseMajorRevision(final @NonNull String versionName) {
106+
final String[] components = versionName.split("\\.");
107+
if (components.length == 0) {
108+
throw new IllegalArgumentException("Empty version name");
109+
}
110+
// Version lines before 26.x use 1.<revision>.*, while 26.x+ uses <revision>.<minor>.*.
111+
final int major = Integer.parseInt(components[0]);
112+
return major == 1 && components.length > 1 ? Integer.parseInt(components[1]) : major;
113+
}
114+
105115
@SafeVarargs
106116
public static <T> @Nullable T firstNonNullOrNull(
107117
final @Nullable T @NonNull... elements

0 commit comments

Comments
 (0)