# 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)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_log-Object-) writes locally; [say(String)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_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 {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_actionbar-Object-}

```js
actionbar(Object text): void
```

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

**Since:** 1.8.1

### actionbar {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_actionbar-Object-boolean-}

```js
actionbar(Object text, boolean tinted): void
```

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

**Since:** 1.2.1

### ampersandToSectionSymbol {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_ampersandToSectionSymbol-String-}

```js
ampersandToSectionSymbol(String string): String
```

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)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_logColor-String-).  
It does not validate formatting codes, so use single ampersands only before characters
intended as formatting codes.  
```js
const converted = Chat.ampersandToSectionSymbol("\x26lbold\x26r normal");  
Chat.log(converted);  
```

**Parameters:**
- `string`: the string to convert

**Returns:** the converted text

**Since:** 1.6.5

### createTextBuilder {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_createTextBuilder-}

```js
createTextBuilder(): TextBuilder
```

Returns an empty [TextBuilder](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/TextBuilder.md) for constructing styled text in sections.

**Returns:** a new empty builder

**Since:** 1.3.0

**See:**
- [TextBuilder](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/TextBuilder.md)

### createTextHelperFromJSON {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_createTextHelperFromJSON-String-}

```js
createTextHelperFromJSON(String json): TextHelper
```

Parses an SNBT text-component representation and wraps the decoded component.

**Parameters:**
- `json`: the SNBT form of a text component

**Returns:** a new [TextHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md)

**Since:** 1.1.3

**See:**
- [TextHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md)

### createTextHelperFromString {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_createTextHelperFromString-String-}

```js
createTextHelperFromString(String content): TextHelper
```

Wraps the supplied text as a literal [TextHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md); formatting codes are not parsed.

**Parameters:**
- `content`: literal text

**Returns:** a new [TextHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md)

**Since:** 1.1.3

**See:**
- [TextHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md)

### createTextHelperFromTranslationKey {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_createTextHelperFromTranslationKey-String-Object[]-}

```js
createTextHelperFromTranslationKey(String key, Object... content): TextHelper
```

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](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md)

**Since:** 1.9.0

### getCommandManager {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_getCommandManager-}

```js
getCommandManager(): CommandManager
```

Returns the shared manager for command builders, client command-tree access, and autocomplete.

**Returns:** the shared command manager

**Since:** 1.7.0

### getHistory {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_getHistory-}

```js
getHistory(): ChatHistoryManager
```

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

**Since:** 1.7.0

### getLogger {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_getLogger-}

```js
getLogger(): Logger
```

Returns the SLF4J logger used by JsMacros.

**Returns:** the slf4j logger JsMacros itself uses

**Since:** 1.5.2

### getLogger {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_getLogger-String-}

```js
getLogger(String name): Logger
```

Returns the SLF4J logger associated with the supplied name.

**Parameters:**
- `name`: logger name

**Returns:** the logger associated with `name`

**Since:** 1.5.2

### getTextWidth {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_getTextWidth-String-}

```js
getTextWidth(String text): int
```

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

**Since:** 1.8.4

### log {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_log-Object-}

```js
log(Object message): void
```

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

**Since:** 1.1.3

### log {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_log-Object-boolean-}

```js
log(Object message, boolean await): void
```

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

**Since:** 1.1.3

### logColor {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_logColor-String-}

```js
logColor(String message): void
```

Logs text after converting ampersand codes to section-sign codes with
[ampersandToSectionSymbol(String)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_ampersandToSectionSymbol-String-).  
```js
// 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

**Since:** 1.9.0

### logColor {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_logColor-String-boolean-}

```js
logColor(String message, boolean await): void
```

Logs converted text, with waiting behavior controlled by `await`.  
```js
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

**Since:** 1.9.0

### logf {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_logf-String-Object[]-}

```js
logf(String message, Object... args): void
```

Logs the formatted message to the player's chat. The message is formatted using the default
java [String.format(String, Object...)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) syntax.  

Formatting occurs before the message is queued; the resulting string is passed to
[log(Object)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_log-Object-).  
```js
// %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

**Since:** 1.8.4

### logf {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_logf-String-boolean-Object[]-}

```js
logf(String message, boolean await, Object... args): void
```

Logs the formatted message to the player's chat. The message is formatted using the default
java [String.format(String, Object...)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) 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.  
```js
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

**Since:** 1.8.4

### open {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_open-String-}

```js
open(String message): void
```

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

**Since:** 1.6.4

### open {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_open-String-boolean-}

```js
open(String message, boolean await): void
```

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](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/UnsupportedOperationException.html).

**Parameters:**
- `message`: the message to start the chat screen with
- `await`: whether to wait for the screen to be open before continuing

**Since:** 1.6.4

### say {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_say-String-}

```js
say(String message): void
```

Sends a chat message or command as the player; a leading slash selects command sending.  
A `null` message is ignored.  
```js
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

**Since:** 1.0.0

### say {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_say-String-boolean-}

```js
say(String message, boolean await): void
```

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

**Since:** 1.3.1

### sayf {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_sayf-String-Object[]-}

```js
sayf(String message, Object... args): void
```

Formats a message with [String.format(String, Object...)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) 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

**Since:** 1.8.4

### sayf {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_sayf-String-boolean-Object[]-}

```js
sayf(String message, boolean await, Object... args): void
```

Formats a message with [String.format(String, Object...)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) and sends it using the
waiting behavior of [say(String, boolean)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_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

**Since:** 1.8.4

### sectionSymbolToAmpersand {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_sectionSymbolToAmpersand-String-}

```js
sectionSymbolToAmpersand(String string): String
```

Converts section symbols to `&` and doubles literal ampersands, reversing
[ampersandToSectionSymbol(String)](#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_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:** § -&gt; `&`

**Since:** 1.6.5

### stripFormatting {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_stripFormatting-String-}

```js
stripFormatting(String string): String
```

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()](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md#com.jsmacrosce.jsmacros.client.api.helper.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.  
```js
// 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

**Since:** 1.6.5

### title {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_title-Object-Object-int-int-int-}

```js
title(Object title, Object subtitle, int fadeIn, int remain, int fadeOut): void
```

Displays title and subtitle text, updating either independently.  

Non-null values are used as rich text when they are `TextHelper`s 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

**Since:** 1.2.1

### toast {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_toast-Object-Object-}

```js
toast(Object title, Object desc): void
```

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

**Since:** 1.2.5

### toast {#com.jsmacrosce.jsmacros.client.api.library.impl.FChat_toast-Object-Object-long-}

```js
toast(Object title, Object desc, long displayTimeMs): void
```

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

**Since:** 1.2.5
