Skip to content

Chat ​

com.jsmacrosce.jsmacros.client.api.library.impl.FChat

Provides client chat, server messaging, overlay display, and text-formatting functions to scripts as the Chat variable. log(Object) writes locally; say(String) sends a message or command to the server.

js
Chat.log("a note to myself");  

Chat.logColor("\x26agreen line");  

if (World.isWorldLoaded()) {
  Chat.say("hello everyone");  
}

Accessible in scripts via the global Chat variable.

Methods ​

actionbar ​

actionbar(Object text): voidSince1.8.1#
Displays a message above the hotbar. A TextHelper is used as rich text; other non-null values are converted to literal text. null clears the message.

Parameters:

  • text: the line to show, or null to clear it
actionbar(Object text, boolean tinted): voidSince1.2.1#
Displays a message above the hotbar. A TextHelper is used as rich text; other non-null values are converted to literal text. null clears the message; tinted controls the overlay's color animation.

Parameters:

  • text: the line to show, or null to clear it
  • tinted: whether to animate the overlay message's color

ampersandToSectionSymbol ​

ampersandToSectionSymbol(String string): StringSince1.6.5#
Converts each & followed by a non-line-terminator character to § and that character, except that && becomes a literal &. An unmatched trailing ampersand, or one immediately before a line terminator, is unchanged. This conversion is also used by logColor(String). It does not validate formatting codes, so use single ampersands only before characters intended as formatting codes.
const converted = Chat.ampersandToSectionSymbol("\x26lbold\x26r normal");
Chat.log(converted);

Parameters:

  • string: the string to convert
Returns: the converted text

createTextBuilder ​

createTextBuilder(): TextBuilderSince1.3.0#
Returns an empty TextBuilder for constructing styled text in sections.
Returns: a new empty builder

See:

createTextHelperFromJSON ​

createTextHelperFromJSON(String json): TextHelperSince1.1.3#
Parses an SNBT text-component representation and wraps the decoded component.

Parameters:

  • json: the SNBT form of a text component
Returns: a new TextHelper

See:

createTextHelperFromString ​

createTextHelperFromString(String content): TextHelperSince1.1.3#
Wraps the supplied text as a literal TextHelper; formatting codes are not parsed.

Parameters:

  • content: literal text
Returns: a new TextHelper

See:

createTextHelperFromTranslationKey ​

createTextHelperFromTranslationKey(String key, Object... content): TextHelperSince1.9.0#
Wraps a translatable text component using the key and supplied arguments.

Parameters:

  • key: the translation key to look up
  • content: arguments supplied to the translation
Returns: a new TextHelper

getCommandManager ​

getCommandManager(): CommandManagerSince1.7.0#
Returns the shared manager for command builders, client command-tree access, and autocomplete.
Returns: the shared command manager

getHistory ​

getHistory(): ChatHistoryManagerSince1.7.0#
Returns a manager for received chat history and sent-message history. A new manager is returned on each call, but each refers to the same chat component. Received history can include JsMacros log lines and excludes lines no longer in the history. Off-thread operations may be queued; whether they wait depends on the operation and its await argument.
Returns: a manager for the chat histories

getLogger ​

getLogger(): LoggerSince1.5.2#
Returns the SLF4J logger used by JsMacros.
Returns: the slf4j logger JsMacros itself uses
getLogger(String name): LoggerSince1.5.2#
Returns the SLF4J logger associated with the supplied name.

Parameters:

  • name: logger name
Returns: the logger associated with name

getTextWidth ​

getTextWidth(String text): intSince1.8.4#
Returns the rendered width of the text using the game's font.

Parameters:

  • text: the text to get the width of, or null for zero
Returns: the rendered width in GUI-scaled screen pixels

log ​

log(Object message): voidSince1.1.3#
Adds a message to the client's chat without sending it to the server. A null is ignored; text helpers preserve rich formatting and other values are converted with toString(). The message is added immediately on Minecraft's thread and queued there from any other thread; this overload never waits for the queued task.

Parameters:

  • message: the message to log, or null to do nothing
log(Object message, boolean await): voidSince1.1.3#
Adds a message to the client's chat without sending it to the server. A null is ignored; text helpers preserve rich formatting and other values are converted with toString(). On Minecraft's thread the message is added immediately. From another thread it is queued on Minecraft's thread; await=true waits for that queued task to finish. A thread that Minecraft is already waiting on, such as a joined callback, cannot wait for it without deadlocking, so the message is queued and this call returns without waiting.

Parameters:

  • message: the message to log, or null to do nothing
  • await: whether to wait for the message to be added to chat; has no effect on a thread that Minecraft is already waiting on

logColor ​

logColor(String message): voidSince1.9.0#
Logs text after converting ampersand codes to section-sign codes with ampersandToSectionSymbol(String).
// the usual ampersand codes, converted on the way in. the ampersand is written
// as the escape \x26 here so this documentation renders it literally
Chat.logColor("\x26l bold, \x26r back to normal");

Parameters:

  • message: the message to log, with ampersand codes
logColor(String message, boolean await): voidSince1.9.0#
Logs converted text, with waiting behavior controlled by await.
Chat.logColor("\x26c red", true);

Parameters:

  • message: the message to log, with ampersand codes
  • await: whether to wait for the message to be sent to chat before continuing

logf ​

logf(String message, Object... args): voidSince1.8.4#
Logs the formatted message to the player's chat. The message is formatted using the default java String.format(String, Object...) syntax. Formatting occurs before the message is queued; the resulting string is passed to log(Object).
// %s takes anything, %d wants a whole number
Chat.logf("%s is at %d, %d, %d", "the player", 12, 64, -30);

Parameters:

  • message: the message to format and log
  • args: the arguments used to format the message
logf(String message, boolean await, Object... args): voidSince1.8.4#
Logs the formatted message to the player's chat. The message is formatted using the default java String.format(String, Object...) syntax. The formatting happens here, before anything is queued. Pass true for await to block until the formatted line has been handed to the chat.
Chat.logf("%d of %d", true, 3, 10);

Parameters:

  • message: the message to format and log
  • await: whether to wait for message to be sent to chat before continuing
  • args: the arguments used to format the message

open ​

open(String message): voidSince1.6.4#
Opens the chat screen with the supplied text, or empty when message is null. The player must submit the text; outside a thread joined to the main thread, this overload does not wait for the screen-opening task to run.

Parameters:

  • message: the message to start the chat screen with
open(String message, boolean await): voidSince1.6.4#
Opens the chat screen with the supplied text, or empty when message is null. When called outside a thread joined to the main thread, await determines whether this call waits for the screen-opening task to run. A joined thread causes UnsupportedOperationException.

Parameters:

  • message: the message to start the chat screen with
  • await: whether to wait for the screen to be open before continuing

say ​

say(String message): voidSince1.0.0#
Sends a chat message or command as the player; a leading slash selects command sending. A null message is ignored.
if (World.isWorldLoaded()) {
  Chat.say("hello everyone");
  // a leading slash runs a command instead
  Chat.say("/list");
}

Parameters:

  • message: the line to send, with a leading slash meaning a command
say(String message, boolean await): voidSince1.3.1#
Sends a chat message or command as the player; a leading slash selects command sending. A null message is ignored. Outside a thread joined to the main thread, sending is scheduled on Minecraft's thread; await controls whether this call waits for that task to run. On a joined thread, sending happens immediately regardless of await.

Parameters:

  • message: the line to send, with a leading slash meaning a command
  • await: whether to wait for the message to be sent to the server before continuing

sayf ​

sayf(String message, Object... args): voidSince1.8.4#
Formats a message with String.format(String, Object...) and sends it without waiting for Minecraft's scheduled send task to run.

Parameters:

  • message: the message to format and send to the server
  • args: the arguments used to format the message
sayf(String message, boolean await, Object... args): voidSince1.8.4#
Formats a message with String.format(String, Object...) and sends it using the waiting behavior of say(String, boolean).

Parameters:

  • message: the message to format and send to the server
  • await: whether to wait for message to be sent to chat before continuing
  • args: the arguments used to format the message

sectionSymbolToAmpersand ​

sectionSymbolToAmpersand(String string): StringSince1.6.5#
Converts section symbols to & and doubles literal ampersands, reversing ampersandToSectionSymbol(String) character by character. For example, a section symbol in a hex colour sequence becomes &, while its # remains unchanged. The inverse conversion restores these characters.

Parameters:

  • string: the string to convert
Returns: § -> &

stripFormatting ​

stripFormatting(String string): StringSince1.6.5#
removes matching legacy colour and style codes from a string. This works on a plain string and is the cheap way to get readable text out of something that is full of codes. For a TextHelper, getStringStripFormatting() does the same thing and walks the actual styled text rather than a pattern. The pattern removes § followed by one legacy formatting character. It does not parse a full hex-colour sequence such as §x§1§2§3§4§5§6; that input becomes §x123456, because x is not matched while each following section-sign and digit pair is. A null is not handled and raises. The ampersands below are written as the escape \x26 so this documentation renders them literally.
// write to a log file without the codes in it
const plain = Chat.stripFormatting(Chat.ampersandToSectionSymbol("\x26c red \x26r and normal"));
Chat.getLogger("my macro").info(plain);

Parameters:

  • string: the string to strip, which must not be null
Returns: the string with matching formatting codes removed

title ​

title(Object title, Object subtitle, int fadeIn, int remain, int fadeOut): voidSince1.2.1#
Displays title and subtitle text, updating either independently. Non-null values are used as rich text when they are TextHelpers and otherwise converted to literal text. A null value leaves that component unchanged; passing null for both clears both. Timing values are ticks and are always updated.

Parameters:

  • title: the main line, or null to leave the current one
  • subtitle: the smaller line under it, or null to leave the current one
  • fadeIn: ticks spent fading the text in
  • remain: ticks the text is held fully visible for
  • fadeOut: ticks spent fading the text out

toast ​

toast(Object title, Object desc): voidSince1.2.5#
Displays a periodic notification toast. A TextHelper is used as rich text; other non-null values are converted to literal text. A null title displays nothing. The game controls this toast's duration.

Parameters:

  • title: the bold line of the toast, or null to show nothing
  • desc: the smaller description under it, or null for none
toast(Object title, Object desc, long displayTimeMs): voidSince1.2.5#
Displays a toast with the supplied duration. displayTimeMs is in milliseconds. A TextHelper is used as rich text; other non-null values are converted to literal text. A null title displays nothing. If no toast manager is available, this does nothing.

Parameters:

  • title: the bold line of the toast, or null to show nothing
  • desc: the smaller description under it, or null for none
  • displayTimeMs: duration assigned to the toast, in milliseconds