MCPcopy Create free account
hub / github.com/PaperMC/Paper / getLastColors

Method getLastColors

paper-api/src/main/java/org/bukkit/ChatColor.java:374–409  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

372 * @return Any remaining ChatColors to pass onto the next line.
373 */
374 @NotNull
375 public static String getLastColors(@NotNull String input) {
376 Preconditions.checkArgument(input != null, "Cannot get last colors from null text");
377
378 String result = "";
379 int length = input.length();
380
381 // Search backwards from the end as it is faster
382 for (int index = length - 1; index > -1; index--) {
383 char section = input.charAt(index);
384 if (section == COLOR_CHAR && index < length - 1) {
385
386 String hexColor = getHexColor(input, index);
387 if (hexColor != null) {
388 // We got a hex color
389 result = hexColor + result;
390 break;
391 }
392
393 // It is not a hex color, check normal color
394 char c = input.charAt(index + 1);
395 ChatColor color = getByChar(c);
396
397 if (color != null) {
398 result = color.toString() + result;
399
400 // Once we find a color or reset we can stop searching
401 if (color.isColor() || color.equals(RESET)) {
402 break;
403 }
404 }
405 }
406 }
407
408 return result;
409 }
410
411 @Nullable
412 private static String getHexColor(@NotNull String input, int index) {

Callers 3

testGetLastColorsMethod · 0.95
wordWrapMethod · 0.95
getLegacyMethod · 0.95

Calls 6

getHexColorMethod · 0.95
getByCharMethod · 0.95
toStringMethod · 0.95
isColorMethod · 0.95
equalsMethod · 0.65
lengthMethod · 0.45

Tested by 1

testGetLastColorsMethod · 0.76