From 6c9b73b100a5ae2cf175b19d6424e0cedbba8604 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Sun, 16 Aug 2020 14:02:03 +0200 Subject: [PATCH] Apply patch by @SirYwell to construct the ResourceKey without consulting the DimensionManager --- .../bukkit/util/OfflinePlayerUtil.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java index 197b05cd6..94a6acedf 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java @@ -63,11 +63,11 @@ public class OfflinePlayerUtil { Object profile = newGameProfile(id, name); Class entityPlayerClass = getNmsClass("EntityPlayer"); Constructor entityPlayerConstructor = - makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), - getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"), - getNmsClass("PlayerInteractManager")); + makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), + getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"), + getNmsClass("PlayerInteractManager")); Object entityPlayer = - callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager); + callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager); return (Player) getBukkitEntity(entityPlayer); } @@ -100,12 +100,21 @@ public class OfflinePlayerUtil { public static Object getWorldServer116() { Object server = getMinecraftServer(); Class minecraftServerClass = getNmsClass("MinecraftServer"); - Class dimensionManager = getNmsClass("DimensionManager"); Class genericResourceKey = getNmsClass("ResourceKey"); - Object overworld = getField(makeField(dimensionManager, "OVERWORLD"), null); + Class minecraftKey = getNmsClass("MinecraftKey"); + // MinecraftKey + MinecraftKey -> ResourceKey + Method constructResourceKey = makeMethod(genericResourceKey, "a", minecraftKey, minecraftKey); + // MinecraftKey(String) + Constructor minecraftKeyConstructor = makeConstructor(minecraftKey, String.class); + // minecraft:overworld + Object overworldKey = callConstructor(minecraftKeyConstructor, "overworld"); + // minecraft:dimension + Object dimensionKey = callConstructor(minecraftKeyConstructor, "dimension"); + // ResourceKey[minecraft:dimension / minecraft:overworld] + Object resourceKey = callMethod(constructResourceKey, null, dimensionKey, overworldKey); Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", genericResourceKey); - return callMethod(getWorldServer, server, overworld); + return callMethod(getWorldServer, server, resourceKey); } public static Object getWorldServerNew() {