Skip to content

Commit

Permalink
Fix VersionProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravis96 committed Jun 30, 2024
1 parent 7f835ae commit 360c1f5
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

@UtilityClass
Expand All @@ -35,15 +36,27 @@ public static VersionAccessor getVersionAccessor() {
}

private static String getNmsVersion() {

final String[] nmsVersionSplit = Bukkit.getServer().getClass().getPackage().getName().split("\\.");
if (nmsVersionSplit.length >= 4) {
final String nmsVersion = nmsVersionSplit[3];
if (nmsVersion.startsWith("v")) {
return nmsVersion;
}
}

try {
Method getDataVersion = UnsafeValues.class.getMethod("getDataVersion");
int dataVersion = (int) getDataVersion.invoke(Bukkit.getServer().getUnsafe());
return NEWER_NMS_VERSION.floorEntry(dataVersion).getValue();
}
catch (NoSuchMethodException ignored) {
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
Map.Entry<Integer, String> entry = NEWER_NMS_VERSION.floorEntry(dataVersion);

if (entry == null) {
throw new RuntimeException("Cannot find server version");
}

return entry.getValue();
}
catch (IllegalAccessException | InvocationTargetException e) {
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Cannot find server version", e);
}
}
Expand Down

0 comments on commit 360c1f5

Please sign in to comment.