/** * Gets the ChatColors used at the end of the given input string. * * @param input Input string to retrieve the colors from. * @return Any remaining ChatColors to pass onto the next line. */ public static String getLastColors(String input) { String result = ""; int length = input.length(); // Search backwards from the end as it is faster for (int index = length - 1; index > -1; index--) { char section = input.charAt(index); if (section == COLOR_CHAR && index < length - 1) { char c = input.charAt(index + 1); ChatColor color = getByChar(c); if (color != null) { result = color.toString() + result; // Once we find a color or reset we can stop searching if (color.isColor() || color.equals(RESET)) { break; } } } } return result; }