Package me.hackware.api.util
Class ChatUtils
java.lang.Object
me.hackware.api.util.ChatUtils
Utility for sending styled chat messages using
& color codes.
Supports standard Minecraft codes (&0–&9, &a–&f,
&l, &o, &n, &m, &k, &r)
and hex colors via &#RRGGBB.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbootstrap(ObjIntConsumer<net.minecraft.network.chat.Component> sink) Installed once by the client at startup.static voidFailure: redTextIcons.Icon.WARNING, message red too.static StringformatError(String message, Throwable err) static voidInformational: aquaTextIcons.Icon.INFO.static net.minecraft.network.chat.MutableComponentParses a string with&color/format codes into a styledComponent.static Stringprefix(TextIcons.Icon icon, net.minecraft.ChatFormatting iconColor) Builds the[icon]prefix, with the icon tintediconColor.static voidprint(TextIcons.Icon icon, net.minecraft.ChatFormatting iconColor, String message) Sendsmessagebehind an[icon]prefix, body text grey by default.static voidSends a color-coded message to the local player's chat.static voidSends a color-coded message, replacing any previous message sent with the same key.static voidLikesendKeyed(String, String)but takes a pre-builtComponent(so click/hover events are preserved).static StringtruncateVisible(String input, int visibleChars) Keeps the firstvisibleCharsvisible characters ofinput, carrying every&code that precedes them so the kept text stays styled exactly as it would be in the full string.static StringtruncateVisibleFromEnd(String input, int visibleChars) Keeps the lastvisibleCharsvisible characters ofinput.static intvisibleLength(String input) Number of visible characters ininput—&color/format codes don't count.static voidAdvisory: yellowTextIcons.Icon.WARNING, message still grey.
-
Method Details
-
bootstrap
Installed once by the client at startup. -
parse
Parses a string with&color/format codes into a styledComponent.- Parameters:
input- the raw string with&codes- Returns:
- a fully styled component
-
send
Sends a color-coded message to the local player's chat.- Parameters:
message- the message with&color codes
-
sendKeyed
Sends a color-coded message, replacing any previous message sent with the same key. Only the most recent message per key is kept visible in chat.- Parameters:
key- a unique identifier (e.g. module name) used to find and replace the old messagemessage- the message with&color codes
-
sendKeyed
LikesendKeyed(String, String)but takes a pre-builtComponent(so click/hover events are preserved). Re-sending with the same key replaces the previous message — used to "grey out" a clickable line after it's been actioned. -
prefix
Builds the[icon]prefix, with the icon tintediconColor. Callers that add their own segment after it (e.g. a module name) use this directly. -
print
public static void print(TextIcons.Icon icon, net.minecraft.ChatFormatting iconColor, String message) Sendsmessagebehind an[icon]prefix, body text grey by default. -
info
Informational: aquaTextIcons.Icon.INFO. -
warn
Advisory: yellowTextIcons.Icon.WARNING, message still grey. -
error
Failure: redTextIcons.Icon.WARNING, message red too. -
visibleLength
Number of visible characters ininput—&color/format codes don't count. Surrogate pairs count as one character. -
truncateVisible
Keeps the firstvisibleCharsvisible characters ofinput, carrying every&code that precedes them so the kept text stays styled exactly as it would be in the full string. -
truncateVisibleFromEnd
Keeps the lastvisibleCharsvisible characters ofinput. Every code from the dropped prefix is replayed in front of the kept text — codes are cumulative style state, so replaying them reproduces exactly the style those characters carry in the full string. -
formatError
-