ChatUtilities.convertLegacyCodes(chat) seems to duplicate ITextComponent siblings
Hello.
I was working on a mod that uses inbound chat filter. So, I have implemented ChatFilter
interface in main mod class. Like this:
@Override
public boolean onChat(ITextComponent chat, String message, LiteLoaderEventBroker.ReturnValue<ITextComponent> newMessage) {
return Core.getInstance().onChat(chat, newMessage);
}
So, code of Core.onChat
(pretty dirty right now because of testing things):
public boolean onChat(ITextComponent chat, LiteLoaderEventBroker.ReturnValue<ITextComponent> newMessage) {
boolean isPassed = true;
TextComponentString cmp = new TextComponentString("Word ");
cmp.appendSibling(new TextComponentString(" another "));
cmp.appendSibling(new TextComponentString("word"));
newMessage.set(cmp);
if(newMessage.isSet())
System.out.println(newMessage.get().toString());
else
System.out.println("Chat is not modified");
return isPassed;
}
And the result of it is like this:
Word another word another word
So, siblings are duplicated. I created mixin that overwrites PacketEventsClient.handlePacket
method, copy-pasted original code but commented out this line (line 259 in the original source file):
chat = ChatUtilities.convertLegacyCodes(chat);
And it seems that there is no more sibling duplication:
Word another word
Am I doing something wrong or there is bug in LiteLoader?
-
It seems that I have found the issue.
textComponent.getFormattedText()
on line 97 returns formatted text of itself and its siblings already (SeeTextComponentBase.getFormattedText()
,TextComponentString
does not override this method). So, we get formatted siblings' text too (I have noticed that all events, for example, HoverEvent, disappear on the first sibling repetition, but formatting like colors and font effects stays the same).Then siblings are added one more time on lines 129 - 132 of
ChatUtilities.covertCodesInPlace()
. But now they are properly added because events work.If I replace
String text = textComponent.getFormattedText();
on line 97 inChatUtilities
file with something like this:String text = style.getFormattingCode() + component.getUnformattedComponentText() + TextFormatting.RESET;
Then sibling duplication disappears. But I am not sure that the rest works properly then.