Fix reflection mappings for the ServerStateProvider in 1.18

This commit is contained in:
Josh Roy 2021-11-21 23:20:35 -05:00 committed by MD
parent b6ba1768a1
commit 7a1e50d10f
2 changed files with 4 additions and 1 deletions

View file

@ -19,6 +19,7 @@ public final class ReflUtil {
public static final NMSVersion V1_12_R1 = NMSVersion.fromString("v1_12_R1");
public static final NMSVersion V1_11_R1 = NMSVersion.fromString("v1_11_R1");
public static final NMSVersion V1_17_R1 = NMSVersion.fromString("v1_17_R1");
public static final NMSVersion V1_18_R1 = NMSVersion.fromString("v1_18_R1");
private static final Map<String, Class<?>> classCache = new HashMap<>();
private static final Table<Class<?>, String, Method> methodCache = HashBasedTable.create();
private static final Table<Class<?>, MethodParams, Method> methodParamCache = HashBasedTable.create();

View file

@ -17,7 +17,9 @@ public class ReflServerStateProvider implements ServerStateProvider {
final Class<?> nmsClass = ReflUtil.getNMSClass("MinecraftServer");
try {
serverObject = nmsClass.getMethod("getServer").invoke(null);
isRunning = MethodHandles.lookup().findVirtual(nmsClass, "isRunning", MethodType.methodType(boolean.class));
isRunning = MethodHandles.lookup().findVirtual(nmsClass,
ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_18_R1) ? "v" : "isRunning", //TODO jmp said he may make this better
MethodType.methodType(boolean.class));
} catch (final Exception e) {
e.printStackTrace();
}