Closed DenAbr closed 8 years ago
Try to use getStrings() instead.
I know it, but i need to use the same code in different versions
That's impossible if the protocol changed from a string to a json component. If you read the Javadoc description of the method getChatComponents, you see that this method is only for 1.7+.
Retrieves a read/write structure for chat components in Minecraft 1.7.2. *
* This modifier will automatically marshall between WrappedChatComponent and the * internal Minecraft IChatBaseComponent.
Same for the class description.
Represents a chat component added in Minecraft 1.7.2
You can try to detect the server version and then use the methods the server supports. Example:
private boolean supportsJson;
public void sendMessage() {
String message = ChatColor.DARK_RED + "Test";
if (supportsJson) {
WrappedChatComponent jsonComponent = WrappedChatComponent.fromText(message);
//send packet using .getChatComponents()
} else {
//send packet using getStrings()
}
}
Thanks. I thought that there is way to make more graceful solution. So than I continue to use the same method as you described.
Method fromText of WrappedChatComponent throws an exception when I use it on 1.5.2.