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

Method getHexColor

paper-api/src/main/java/org/bukkit/ChatColor.java:411–451  ·  view source on GitHub ↗
(@NotNull String input, int index)

Source from the content-addressed store, hash-verified

409 }
410
411 @Nullable
412 private static String getHexColor(@NotNull String input, int index) {
413 // Check for hex color with the format '§x§1§2§3§4§5§6'
414 // Our index is currently on the last '§' which means to have a potential hex color
415 // The index - 11 must be an 'x' and index - 12 must be a '§'
416 // But first check if the string is long enough
417 if (index < 12) {
418 return null;
419 }
420
421 if (input.charAt(index - 11) != 'x' || input.charAt(index - 12) != COLOR_CHAR) {
422 return null;
423 }
424
425 // We got a potential hex color
426 // Now check if every the chars switches between '§' and a hex number
427 // First check '§'
428 for (int i = index - 10; i <= index; i += 2) {
429 if (input.charAt(i) != COLOR_CHAR) {
430 return null;
431 }
432 }
433
434 for (int i = index - 9; i <= (index + 1); i += 2) {
435 char toCheck = input.charAt(i);
436 if (toCheck < '0' || toCheck > 'f') {
437 return null;
438 }
439
440 if (toCheck > '9' && toCheck < 'A') {
441 return null;
442 }
443
444 if (toCheck > 'F' && toCheck < 'a') {
445 return null;
446 }
447 }
448
449 // We got a hex color return it
450 return input.substring(index - 12, index + 2);
451 }
452
453 static {
454 for (ChatColor color : values()) {

Callers 1

getLastColorsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected