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.
(@NotNull String input)
| 370 | * @return Any remaining ChatColors to pass onto the next line. |
| 371 | */ |
| 372 | @NotNull |
| 373 | public static String getLastColors(@NotNull String input) { |
| 374 | Validate.notNull(input, "Cannot get last colors from null text"); |
| 375 | |
| 376 | String result = ""; |
| 377 | int length = input.length(); |
| 378 | |
| 379 | // Search backwards from the end as it is faster |
| 380 | for (int index = length - 1; index > -1; index--) { |
| 381 | char section = input.charAt(index); |
| 382 | if (section == COLOR_CHAR && index < length - 1) { |
| 383 | char c = input.charAt(index + 1); |
| 384 | ChatColor color = getByChar(c); |
| 385 | |
| 386 | if (color != null) { |
| 387 | result = color.toString() + result; |
| 388 | |
| 389 | // Once we find a color or reset we can stop searching |
| 390 | if (color.isColor() || color.equals(RESET)) { |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return result; |
| 398 | } |
| 399 | |
| 400 | static { |
| 401 | for (ChatColor color : values()) { |