aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-07-21 15:34:32 +0100
committerLuck <git@lucko.me>2020-07-21 15:34:32 +0100
commit1bf26ed4e9cd923ec1234804a3a3668afbb63876 (patch)
tree9c7ed87a9cebcad374cf60f73d047e00095f5063
parent014cfe32accf2f3cb2d42e49337809dbb32c2e2d (diff)
downloadspark-1bf26ed4e9cd923ec1234804a3a3668afbb63876.tar.gz
spark-1bf26ed4e9cd923ec1234804a3a3668afbb63876.tar.bz2
spark-1bf26ed4e9cd923ec1234804a3a3668afbb63876.zip
Fix NoSuchMethodError for getMinecraftVersion method (#59)
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
index 84ed1bf..cbeaf8e 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
@@ -23,6 +23,9 @@ package me.lucko.spark.bukkit;
import me.lucko.spark.common.platform.AbstractPlatformInfo;
import org.bukkit.Server;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
public class BukkitPlatformInfo extends AbstractPlatformInfo {
private final Server server;
@@ -47,6 +50,28 @@ public class BukkitPlatformInfo extends AbstractPlatformInfo {
@Override
public String getMinecraftVersion() {
- return this.server.getMinecraftVersion();
+ try {
+ return this.server.getMinecraftVersion();
+ } catch (NoSuchMethodError e) {
+ // ignore
+ }
+
+ Class<? extends Server> serverClass = this.server.getClass();
+ try {
+ Field minecraftServerField = serverClass.getDeclaredField("console");
+ minecraftServerField.setAccessible(true);
+
+ Object minecraftServer = minecraftServerField.get(this.server);
+ Class<?> minecraftServerClass = minecraftServer.getClass();
+
+ Method getVersionMethod = minecraftServerClass.getDeclaredMethod("getVersion");
+ getVersionMethod.setAccessible(true);
+
+ return (String) getVersionMethod.invoke(minecraftServer);
+ } catch (Exception e) {
+ // ignore
+ }
+
+ return serverClass.getPackage().getName().split("\\.")[3];
}
}