Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getLastColors(String input) {
- char COLOR_CHAR = '\u00A7';
- 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 = ChatColor.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(ChatColor.RESET)) {
- //break; //Simple fix, will get all colors now
- }
- }
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment