Package com.kamikazejam.kamicommon.util
Class LegacyColors
java.lang.Object
com.kamikazejam.kamicommon.util.LegacyColors
A legacy color-code translator for Minecraft-style formatting codes.
Translates the alternate code character
Notes:
- This API is marked
- Basic legacy color/format codes supported: 0-9, a-f, k-o, r (case-insensitive), e.g.
- Hex color support requires either
Translates the alternate code character
& into the legacy section sign (§) and optionally expands 1.16+ hex color codes of the form &#RRGGBB into the §x§R§R§G§G§B§B sequence used by legacy clients.Notes:
- This API is marked
@Obsolete. Prefer modern text/color APIs where possible.- Basic legacy color/format codes supported: 0-9, a-f, k-o, r (case-insensitive), e.g.
&a, &l, &r, etc.- Hex color support requires either
forceTranslateHex = true or BukkitAdapter.supportsHexCodes() to be true.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe legacy color code character (section sign),'§'.static final @NotNull PatternCase-insensitive pattern that matches legacy color and format codes to strip.
Matches:
-§[0-9A-FK-OR](single legacy codes), and
-§x(§[0-9A-F0-9]){6}(expanded hex color sequences). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplaces the legacy section sign§with the alternate color code character&in a single string.static String[]Replaces the legacy section sign§with&in each string of the provided array.Replaces the legacy section sign§with&in each string of the provided list.static StringRemoves all legacy color and format codes from the provided string.
Supports stripping single legacy codes and expanded hex sequences.static StringTranslates alternate color codes in a message from&to§.
Hex colors of the form&#RRGGBBare translated only if supported by the runtime (BukkitAdapter.supportsHexCodes()is true).Translates alternate color codes for an array of messages usingt(String)behavior (hex translation only if supported).static StringTranslates alternate color codes in a message from&to§and, if enabled or supported, converts hex colors of the form&#RRGGBBinto the legacy expanded§x§R§R§G§G§B§Bsequence.Translates alternate color codes for a list of messages usingt(String)behavior (hex translation only if supported).
-
Field Details
-
COLOR_CHAR
public static final char COLOR_CHARThe legacy color code character (section sign),'§'.- See Also:
-
STRIP_COLOR_PATTERN
Case-insensitive pattern that matches legacy color and format codes to strip.
Matches:
-§[0-9A-FK-OR](single legacy codes), and
-§x(§[0-9A-F0-9]){6}(expanded hex color sequences).
-
-
Constructor Details
-
LegacyColors
public LegacyColors()
-
-
Method Details
-
t
Translates alternate color codes in a message from&to§and, if enabled or supported, converts hex colors of the form&#RRGGBBinto the legacy expanded§x§R§R§G§G§B§Bsequence.- Parameters:
msg- the input message (non-null expected)forceTranslateHex- if true, hex codes are translated regardless ofBukkitAdapter.supportsHexCodes()- Returns:
- the translated message with legacy codes applied
-
t
Translates alternate color codes in a message from&to§.
Hex colors of the form&#RRGGBBare translated only if supported by the runtime (BukkitAdapter.supportsHexCodes()is true).- Parameters:
msg- the input message (non-null expected)- Returns:
- the translated message with legacy codes applied
-
t
Translates alternate color codes for a list of messages usingt(String)behavior (hex translation only if supported).- Parameters:
msgs- list of input messages- Returns:
- a new list containing translated messages
-
t
Translates alternate color codes for an array of messages usingt(String)behavior (hex translation only if supported).- Parameters:
msgs- array of input messages- Returns:
- a new list containing translated messages
-
strip
@Obsolete @Contract(value="null -> null; !null -> !null", pure=true) public static String strip(String s) Removes all legacy color and format codes from the provided string.
Supports stripping single legacy codes and expanded hex sequences.- Parameters:
s- the input string, may be null- Returns:
- the input without legacy color/format codes, or null if input is null
-
reverseT
Replaces the legacy section sign§with the alternate color code character&in a single string.- Parameters:
s- the input string- Returns:
- the string with
§replaced by&
-
reverseT
Replaces the legacy section sign§with&in each string of the provided list.- Parameters:
s- a list of strings to transform- Returns:
- a new list with
§replaced by&in each element
-
reverseT
Replaces the legacy section sign§with&in each string of the provided array.- Parameters:
s- an array of strings to transform- Returns:
- a new array with
§replaced by&in each element
-