Question Paper 1.20.2 NoSuchMethodError, same code works fine on spigot

xWil

New member
Sep 27, 2023
4
0
1
Hiya,

The code below shows a 1.20.1 and 1.20.2 version of the same spigot code. The 1.20.1 works with both spigot and paper, the 1.20.2 code only works with spigot.

Code:
//1.20.1
ClientboundSystemChatPacket packet = new ClientboundSystemChatPacket(IChatBaseComponent.ChatSerializer.a(line), false);
(((CraftPlayer) player).getHandle()).c.a(packet);
//1.20.2
ClientboundSystemChatPacket packet = new ClientboundSystemChatPacket(IChatBaseComponent.ChatSerializer.fromJson(line), false);
(((CraftPlayer) player).getHandle()).connection.send(packet);

I get this error on paper 1.20.2, is this something I can expect to be fixed eventually ? or is there something I can do to fix it. The spigot mappings changed so is paper also going to update theirs to be the same at some point?

Code:
java.lang.NoSuchMethodError: 'net.minecraft.network.chat.IChatMutableComponent net.minecraft.network.chat.IChatBaseComponent$ChatSerializer.fromJson(java.lang.String)'
 

electronicboy

Administrator
Staff member
Dec 11, 2021
236
12
42
28
Please file an issue on the tracker, this generally screams another headache around spigots borked tooling causing oddities elsewhere
 

xWil

New member
Sep 27, 2023
4
0
1
Please file an issue on the tracker, this generally screams another headache around spigots borked tooling causing oddities elsewhere
They closed and marked it as invalid. Owen says "NMS compatibility is never promised, we make changes here". Is there any other options? Is there a way to check if the server is running spigot or paper and do something accordingly?
 

electronicboy

Administrator
Staff member
Dec 11, 2021
236
12
42
28
If that's an area that we make changes to then you'll generally have to handle it another way, NMS is not API, and this looks like an area where stuff has generally changed for various reasons ranging from adding in library support, side-effects of spigots environment being mitigated, etc, etc


NMS is not supported, and so you're generally going to have to find another way to resolve it, I have no idea why you're using internals for something that already has well-supported API, but especially in areas like that we're generally not going to break our backs trying to support upstream oddities likely induced by compiling against their jars. Heavily suggests looking into using paperweight if you really want to use nms across platforms as at least then you'll have a generally less weird environment. However, you would need to ensure the methods you use exist in spigot, etc.
 

xWil

New member
Sep 27, 2023
4
0
1
Okay I'll admit I didn't do much research into the API, I only knew about the TextComponent stuff and that was a bit long winded for what I liked, the first solution I found was the NMS one. It's up to you if you fix it or not, but i did find a solution that works, I didn't know where was a json parser but I left the code here if anyone ever sees this and wants it. I still feel like for compatibility reasons this should be fixed but that's ofc your decision and not mine.

Java:
BaseComponent[] bc = ComponentSerializer.parse(json);
player.spigot().sendMessage(bc);