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
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, ornullto clear it
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, ornullto clear ittinted: whether to animate the overlay message's color
ampersandToSectionSymbol
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
Returns an empty TextBuilder for constructing styled text in sections.
Returns: a new empty builder
See:
createTextHelperFromJSON
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
Wraps the supplied text as a literal TextHelper; formatting codes are not parsed.
Parameters:
content: literal text
Returns: a new TextHelper
See:
createTextHelperFromTranslationKey
Wraps a translatable text component using the key and supplied arguments.
Parameters:
key: the translation key to look upcontent: arguments supplied to the translation
Returns: a new TextHelper
getCommandManager
Returns the shared manager for command builders, client command-tree access, and autocomplete.
Returns: the shared command manager
getHistory
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
Returns the SLF4J logger used by JsMacros.
Returns: the slf4j logger JsMacros itself uses
getTextWidth
log
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, ornullto do nothing
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, ornullto do nothingawait: whether to wait for the message to be added to chat; has no effect on a thread that Minecraft is already waiting on
logColor
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
logf
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 logargs: the arguments used to format the message
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 logawait: whether to wait for message to be sent to chat before continuingargs: the arguments used to format the message
open
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
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 withawait: whether to wait for the screen to be open before continuing
say
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
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 commandawait: whether to wait for the message to be sent to the server before continuing
sayf
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 serverargs: the arguments used to format the message
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 serverawait: whether to wait for message to be sent to chat before continuingargs: the arguments used to format the message
sectionSymbolToAmpersand
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
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 benull
Returns: the string with matching formatting codes removed
title
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, ornullto leave the current onesubtitle: the smaller line under it, ornullto leave the current onefadeIn: ticks spent fading the text inremain: ticks the text is held fully visible forfadeOut: ticks spent fading the text out
toast
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, ornullto show nothingdesc: the smaller description under it, ornullfor none
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, ornullto show nothingdesc: the smaller description under it, ornullfor nonedisplayTimeMs: duration assigned to the toast, in milliseconds