Odd Linebreaks

Discussion in 'Spigot Plugin Development' started by JesseMcCullough, May 28, 2017.

  1. After experimenting with the AsyncPlayerChatEvent, an acquaintance and I noticed that when a color code is inserted before a message, the message receives some odd linebreaks. The two pictures below will do better justice as to what I'm talking about:

    (Normal; no odd linebreaks)

    (Unusual; odd linebreaks)

    Notice the fourth "HowdoyoudoSIR" is broken up oddly with its "SIR" on the next line, while the "normal" picture breaks up the message correctly.

    All I'm doing is inserting a color code before the message via
    Code (Text):
    AsyncPlayerChatEvent#setMessage(*thecolorcode* AsyncPlayerChatEvent#getMessage())

    I have noticed that AsyncPlayerChatEvent#setFormat(String) handles the linebreaks correctly, but I don't think that method is going to be able to satisfy my needs. I merely want to set the color of a message, not mess around with message's format structure.

    Suggestions for a fix would be awesome, especially in regards to whatever chat width is set in a player's Minecraft Chat Settings!

    UPDATE #1:
    I found out the issue is actually the way I am handling the messages in my chat plugin. Basically, I'm taking the message from getMessage(), running it through a StringBuilder to handle a few miscellaneous tasks, then returning the message back to setMessage(). So the AsyncPlayerChatEvent#setMessage method is not the issue here.

    Better question: What can I do to my messages in order for them to appear correctly without any odd linebreaks after running it through a StringBuilder?
    #1 JesseMcCullough, May 28, 2017
    Last edited: May 28, 2017
  2. Try adding a Reset after colorcodes, I've had this issue with bold before, but I don't see such usage, still worth a try :3
  3. To my knowledge, the issue lies with the client - if the first part of a new chat component reaches the end of the line, it will assume the length is too long to fit on a single line and wrap it. There's no real fix I know of aside from manually correcting it by sending multiple messages.
    • Informative Informative x 1
  4. Tell me about it!

    I could try that. But I think the same results would be gathered from before. After all, the reset color code is merely an additional 2 characters. haha

    I agree. Another solution to this problem would be to go through AsyncPlayerChatEvent#setFormat(), but I believe conflicts will arise with other chat plugins.

    If I figure out a solution, I'll reply back with what worked for me; no sense in having another individual go through the same issue. First one to figure out a solution wins!