# RecvMessage

`com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage`

**Since:** 1.2.7

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fired before a message is added to the chat HUD. Cancelling skips the HUD's entire
`addMessage` call, including its chat-log output and queue updates.  
```js
JsMacros.on("RecvMessage", true, JavaWrapper.methodToJava(function (event) {
  if (event.messageType === "Chat Error") {
    // Hide the chat-validation error message.  
    event.cancel();  
    return;  
  }
  if (event.getText() === null) return;  
  Chat.log(`[${event.messageType}] ${event.getText().getString()}`);  
}))
```

## Constructors

### new EventRecvMessage {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_constructor-Component-MessageSignature-GuiMessageTag-}

```js
new EventRecvMessage(Component message, MessageSignature signature, GuiMessageTag indicator)
```

Initializes the event with the supplied message, signature bytes, and chat-log tag; this
constructor does not add or dispatch a HUD message. The message is wrapped with
[TextHelper.wrap(Component)](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/TextHelper.md#com.jsmacrosce.jsmacros.client.api.helper.TextHelper_wrap-Component-), which returns `null`. The signature
byte array is retained, not copied.

**Parameters:**
- `message`: raw message content, or `null`
- `signature`: raw signature, or `null`; its byte array is retained
- `indicator`: HUD tag, or `null`; its log tag is stored as [messageType](#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_messageType)

## Fields

### messageType {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_messageType}

```js
messageType: String
```

Minecraft chat-log tag for the message, or `null` when no tag was supplied. This field
is not changed when a listener replaces the text; the game adds its `"Modified"` tag
when the displayed text differs.

**Since:** 1.8.2

### signature {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_signature}

```js
signature: byte[]
```

Raw message-signature bytes, or `null` when no signature was supplied. Present
signatures contain 256 bytes.

**Since:** 1.8.2

### text {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_text}

```js
text: TextHelper
```

Message content to be added to the HUD. Replacing it changes the displayed and logged
content and marks the displayed line as `"Modified"`; assigning `null` instead
causes the HUD message to be skipped.

**Deprecated:** Removal in 3.0.0: Use [getText()](#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_getText-) and [setText(TextHelper)](#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_setText-TextHelper-) instead.

## Methods

### getText {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_getText-}

```js
getText(): TextHelper
```

Returns the message content to be added to the HUD, or `null` when the message is
skipped.

**Returns:** the current message helper, or `null`

**Since:** 2.2.0

### setText {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_setText-TextHelper-}

```js
setText(TextHelper text): void
```

Replaces the message content. A replacement changes the displayed and logged content; when
the displayed text differs, the game marks the line as `"Modified"`. `null`
skips the HUD message.

**Parameters:**
- `text`: replacement helper, or `null` to skip the message

**Since:** 2.2.0

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_toString-}

```js
toString(): String
```

Formats a diagnostic string from the event name and the current values of `getText()`,  
[signature](#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_signature), and [messageType](#com.jsmacrosce.jsmacros.client.api.event.impl.EventRecvMessage_messageType). Its shape is
`eventName:{"text": "textValue", "signature": boolean, "messageType": "tagValue"}`;  
the text and tag are inserted using ordinary string formatting, not JSON escaping. The
signature value is `true` only when the current signature array is non-null and
non-empty; it does not verify the signature.

**Returns:** diagnostic string containing the current field values
