Timtower

getLastColors

Aug 17th, 2014
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public static String getLastColors(String input) {
  2. char COLOR_CHAR = '\u00A7';
  3. String result = "";
  4. int length = input.length();
  5.  
  6. // Search backwards from the end as it is faster
  7. for (int index = length - 1; index > -1; index--) {
  8. char section = input.charAt(index);
  9. if (section == COLOR_CHAR && index < length - 1) {
  10. char c = input.charAt(index + 1);
  11. ChatColor color = ChatColor.getByChar(c);
  12.  
  13. if (color != null) {
  14. result = color.toString() + result;
  15.  
  16. // Once we find a color or reset we can stop searching
  17. if (color.isColor() || color.equals(ChatColor.RESET)) {
  18. //break; //Simple fix, will get all colors now
  19. }
  20. }
  21. }
  22. }
  23.  
  24. return result;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment