diff --git a/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java b/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java index 2a86dd5..3f3284b 100644 --- a/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java +++ b/src/main/java/me/dadus33/chatitem/platform/hook/SpigotPlatform.java @@ -117,6 +117,12 @@ public String baseComponentToJson(Object obj) { try { Object[] args = new Object[m.getParameterCount()]; args[0] = obj; + if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$a")) { + Class c = Class.forName("net.minecraft.core.HolderLookup$a"); + if (m.getParameterTypes()[1].isAssignableFrom(c)) { + args[1] = getRegistry(); + } + } return (String) m.invoke(null, args); } catch (Exception e) { e.printStackTrace(); @@ -130,6 +136,12 @@ public Object jsonToBaseComponent(String json) { try { Object[] args = new Object[m.getParameterCount()]; args[0] = json; + if (args.length > 1 && ReflectionUtils.isClassExist("net.minecraft.core.HolderLookup$a")) { + Class c = Class.forName("net.minecraft.core.HolderLookup$a"); + if (m.getParameterTypes()[1].isAssignableFrom(c)) { + args[1] = getRegistry(); + } + } return m.invoke(null, args); } catch (Exception e) { e.printStackTrace(); @@ -137,6 +149,11 @@ public Object jsonToBaseComponent(String json) { return null; } + private Object getRegistry() throws Exception { + Class serverClass = Class.forName("net.minecraft.server.MinecraftServer"); + return serverClass.getDeclaredMethod("ba").invoke(serverClass.getDeclaredMethod("getServer").invoke(null)); + } + public static Method getBaseComponentToJsonMethod() { Class chatSerializerClass = PacketUtils.getNmsClass("IChatBaseComponent$ChatSerializer", "network.chat.", "ChatSerializer", "Component$Serializer"); Class chatBaseComponentClass = PacketUtils.getNmsClass("IChatBaseComponent", "network.chat.", "Component");