Fix OfflinePlayerUtil runtime exception

This commit is contained in:
Alexander Söderberg 2020-04-08 22:52:13 +02:00
parent 271109a726
commit 254a0541cc

View File

@ -12,9 +12,11 @@ import java.util.UUID;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.callConstructor;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.callMethod;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getCbClass;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getField;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getNmsClass;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getUtilClass;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.makeConstructor;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.makeField;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.makeMethod;
public class OfflinePlayerUtil {
@ -67,11 +69,26 @@ public class OfflinePlayerUtil {
return callConstructor(c, worldServer);
}
public static Object getWorldServerNew() {
Object server = getMinecraftServer();
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
Class<?> dimensionManager = getNmsClass("DimensionManager");
Object overworld = getField(makeField(dimensionManager, "OVERWORLD"), null);
Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", dimensionManager);
return callMethod(getWorldServer, server, overworld);
}
private static Object getWorldServer() {
Object server = getMinecraftServer();
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
return callMethod(getWorldServer, server, 0);
Object o;
try {
o = callMethod(getWorldServer, server, 0);
} catch (final RuntimeException e) {
o = getWorldServerNew();
}
return o;
}
//NMS Utils