Fix server state reflection provider mappings

This commit is contained in:
Josh Roy 2022-06-07 14:28:38 -04:00 committed by MD
parent b916488de2
commit d04c933abe
2 changed files with 12 additions and 1 deletions

View File

@ -20,6 +20,7 @@ public final class ReflUtil {
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");
public static final NMSVersion V1_19_R1 = NMSVersion.fromString("v1_19_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

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