Solved String#subString for colored message.

Discussion in 'Spigot Plugin Development' started by Gober, Aug 13, 2018.

  1. I'm having a bit of trouble here.
    I got this plugin called "LastHolo", a holographic chat plugin.

    Recently, I'm having an issue where if player enables multi-line support and uses color chat, String#subString the message won't make the other messages get colored.

    I spoke: &e12345678901234567890 (22)
    Multi line length: 12
    So the other 1234567890 message won't be colored as it substrings from 1 to 12.

    Any ideas?

    EDIT: Is it possible to check the color code in each String?
  2. I've got a utility method to handle this if you want to take a look at it:

    Or maybe this slightly older version might work better, it's simpler but doesn't handle \n in text, sounds like that'd be ok for you unless you want players to be able to force line breaks in chat.. I guess? :D

    It basically just uses ChatColor.getLastColors to keep track of all of the relevant color codes as is it splits the text out to multiple lines.
    • Winner Winner x 2
  3. Good idea, gotta use the ChatColor.getLastColors(); and add that to the new lines
    • Agree Agree x 1