WrappedChatComponent uses incorrect "fromString" MethodAccessor in 1.8
Paroxial opened this issue · 2 comments
Describe the bug
The WrappedChatComponent class tries to lookup a method signature for the CONSTRUCT_COMPONENT field which does not exist in Minecraft version 1.8. This regressed after ProtocolLib version 4.6.0.
The correct method signatures for CraftChatMessage#fromString in 1.8 are as follows:
CraftChatMessage.fromString(String message)
CraftChatMessage.fromString(String message, boolean keepNewlines, boolean useRegex)
Error:
Caused by: java.lang.IllegalArgumentException: Unable to find method fromString ([class java.lang.String, boolean]) in class org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage
Full stacktrace: https://pastebin.com/8Byb6AYc
The affected line:
https://github.com/dmulloy2/ProtocolLib/blob/master/src/main/java/com/comphenix/protocol/wrappers/WrappedChatComponent.java#L53
Commit which caused this regression:
b3ccf82#diff-7d1c3727d4e2cb335e0fe8939774922a0e016850e5085ea693b5189b78bbaadc
To Reproduce
Steps to reproduce the behavior:
- Read a WrappedChatComponent or WrappedChatComponent[] from a packet
- Use the class in some way (parse JSON to plaintext via ComponentSerializer.parse(json)
Example code:
Reading from a PacketType.Play.Client.UPDATE_SIGN
String[] lines = new String[4];
WrappedChatComponent[] chatComponents = packet.getChatComponentArrays().read(0);
for (int i = 0; i < chatComponents.length; i++) {
String json = chatComponents[i].getJson();
lines[i] = ComponentSerializer.parse(json)[0].toPlainText();
}
Expected behavior
WrappedChatComponent should be able to be read and parsed without errors (as is the case in v4.6.0).
The String[] should be the output in plain text from the sign packet.
However, an exception is thrown since the method signature does not exist in this internal class.
Version Info
ProtocolLib version 4.7.0
Spigot version: 1.8.8
Protocol dump: https://pastebin.com/pxT6dsAB
Solution
Change the method accessor from
Accessors.getMethodAccessor(MinecraftReflection.getCraftChatMessage(), "fromString", String.class, boolean.class);
to
Accessors.getMethodAccessor(MinecraftReflection.getCraftChatMessage(), "fromString", String.class);
for versions below Minecraft 1.16
That's a bit strange... I looked into the code and the method should be there 🤔 Guess I'll look into this later