From 254a0541cc986965f8be5748a2b52bb9ead4a925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 8 Apr 2020 22:52:13 +0200 Subject: [PATCH] Fix OfflinePlayerUtil runtime exception --- .../bukkit/util/OfflinePlayerUtil.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java index a4ee94f80..dd7edf83f 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java @@ -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