Class ChatUtils

java.lang.Object
me.hackware.api.util.ChatUtils

public final class ChatUtils extends Object
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 Details

    • bootstrap

      public static void bootstrap(ObjIntConsumer<net.minecraft.network.chat.Component> sink)
      Installed once by the client at startup.
    • parse

      public static net.minecraft.network.chat.MutableComponent parse(String input)
      Parses a string with & color/format codes into a styled Component.
      Parameters:
      input - the raw string with & codes
      Returns:
      a fully styled component
    • send

      public static void send(String message)
      Sends a color-coded message to the local player's chat.
      Parameters:
      message - the message with & color codes
    • sendKeyed

      public static void sendKeyed(String key, String message)
      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 message
      message - the message with & color codes
    • sendKeyed

      public static void sendKeyed(String key, net.minecraft.network.chat.Component component)
      Like sendKeyed(String, String) but takes a pre-built Component (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

      public static String prefix(TextIcons.Icon icon, net.minecraft.ChatFormatting iconColor)
      Builds the [icon] prefix, with the icon tinted iconColor. 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)
      Sends message behind an [icon] prefix, body text grey by default.
    • info

      public static void info(String message)
      Informational: aqua TextIcons.Icon.INFO.
    • warn

      public static void warn(String message)
      Advisory: yellow TextIcons.Icon.WARNING, message still grey.
    • error

      public static void error(String message)
      Failure: red TextIcons.Icon.WARNING, message red too.
    • visibleLength

      public static int visibleLength(String input)
      Number of visible characters in input& color/format codes don't count. Surrogate pairs count as one character.
    • truncateVisible

      public static String truncateVisible(String input, int visibleChars)
      Keeps the first visibleChars visible characters of input, carrying every & code that precedes them so the kept text stays styled exactly as it would be in the full string.
    • truncateVisibleFromEnd

      public static String truncateVisibleFromEnd(String input, int visibleChars)
      Keeps the last visibleChars visible characters of input. 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

      public static String formatError(String message, Throwable err)