Skip to content

Commit

Permalink
Fix for spigot versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Nov 7, 2024
1 parent c9ea806 commit 4e7b14e
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -130,13 +136,24 @@ 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();
}
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");
Expand Down

0 comments on commit 4e7b14e

Please sign in to comment.