Skip to content

SendMessage ​

com.jsmacrosce.jsmacros.client.api.event.impl.EventSendMessage

Since1.2.7Cancellable

Fires for text submitted through the chat screen, before the game normalizes it. Cancelling prevents sending and chat-history insertion. A changed, nonempty value is sent directly without normalization or history insertion; null or an empty replacement is not sent. A leading / selects command submission, with the slash removed.

js
JsMacros.on("SendMessage", true, JavaWrapper.methodToJava(function (event) {
  if (event.getMessage() === null) {
    return;  
  }
  if (event.getMessage() === "/hello") {
    // swallow it, nothing is sent and nothing is added to the history
    event.cancel();  
    return;  
  }
  // rewrite it, the client sends this instead of what was typed
  event.setMessage(`say ${event.getMessage()}`);  
}))

Constructors ​

new EventSendMessage ​

new EventSendMessage(String message)#
Initializes the event with the supplied message; construction does not dispatch the event.

Parameters:

  • message: initial message text, stored verbatim

Fields ​

message ​

message: Stringdeprecated#
The raw text submitted in the chat screen. A changed, nonempty value is sent without normalization or history insertion; a leading / selects command submission, with the slash removed. null, an empty string, or cancelling the event prevents sending.

Deprecated: Removal in 3.0.0: Use getMessage() and setMessage(String) instead.

Methods ​

getMessage ​

getMessage(): StringSince2.2.0#
Returns the raw text submitted in the chat screen. null means no text will be sent.
Returns: the current message text, or null

setMessage ​

setMessage(String message): voidSince2.2.0#
Replaces the text that will be sent. A changed, nonempty value is sent without normalization or history insertion; a leading / selects command submission, with the slash removed. null, an empty string, or cancelling the event prevents sending.

Parameters:

  • message: replacement text, or null to prevent sending

toString ​

toString(): String#
Returns a diagnostic string containing the event name and current message text. The message is not escaped, so this representation is not JSON.
Returns: event name and current message text in the form %s:{"message": "%s"}