Skip to content

PlayerChatEvent

Namespace Mc.Scripting.Events · Kind struct (ref)

public ref struct PlayerChatEvent : IEvent

A player sent a chat message. Cancel to drop it. Changing Message or Rendered sends the line as an unsigned server message instead of the player’s signed one. SenderName, ChatType, Decoration and the filter fields restyle the signed line without unsigning it: the signature covers only the typed text.

Id 14
Key mc:player_chat
Cancellable yes
Fired by the engine yes
Field Type Handlers may write Description
Player player no (readonly) The sender.
Message Utf8String yes What the player typed. Changing it re-renders the line with the default format.
Rendered component yes The complete line shown to everybody (default: message). Replace it to change the format; takes precedence over Message.
SenderName component yes The sender name as the line shows it (hover, click and insertion included). Changing it keeps the message signed.
ChatType enum:ChatKind yes The chat type of the line: Chat, EmoteCommand or SayCommand. The message kinds need a target and are refused here (Chat is used).
Decoration component yes The body as the line shows it (unsigned content: colours, highlights, glyphs). Equal to the typed text means none. Keeps the message signed.
FilterKind enum:ChatFilterKind yes How the recipients who filter text see the message (vanilla FilterMask). Any other value fully filters the message.
FilterBits Utf8String yes For PartiallyFiltered: one 0 or 1 per UTF-16 unit of the typed text, 1 hides the unit. A different length or character fully filters the message.

Set e.Cancelled = true in a handler to cancel it; lower-priority handlers are skipped unless they subscribed with receiveCancelled: true.

Member Description
Constructor Creates the event (for firing it from a plugin; native code builds its own).
public PlayerChatEvent(Player player, Utf8String message, Utf8String rendered, Utf8String senderName, ChatKind chatType, Utf8String decoration, ChatFilterKind filterKind, Utf8String filterBits)

Creates the event (for firing it from a plugin; native code builds its own). Signature of API 1.0.

Parameters

Name Type Description
player Player
message Utf8String
rendered Utf8String
senderName Utf8String
chatType ChatKind
decoration Utf8String
filterKind ChatFilterKind
filterBits Utf8String
Member Description
bool Cancelled { get; set; } Cancelling stops lower-priority handlers (unless they opt in) and the action itself.
ChatKind ChatType { get; set; } The chat type of the line: Chat, EmoteCommand or SayCommand.
Component Decoration { get; } The body as the line shows it (unsigned content: colours, highlights, glyphs).
Utf8String DecorationJson { get; } The body as the line shows it (unsigned content: colours, highlights, glyphs).
Utf8String FilterBits { get; } For PartiallyFiltered: one 0 or 1 per UTF-16 unit of the typed text, 1 hides the unit.
ChatFilterKind FilterKind { get; set; } How the recipients who filter text see the message (vanilla FilterMask).
Utf8String Message { get; } What the player typed.
Player Player { get; } The sender.
Component Rendered { get; } The complete line shown to everybody (default: <name> message).
Utf8String RenderedJson { get; } The complete line shown to everybody (default: <name> message).
Component SenderName { get; } The sender name as the line shows it (hover, click and insertion included).
Utf8String SenderNameJson { get; } The sender name as the line shows it (hover, click and insertion included).
static ushort CatalogueId { get; } Catalogue id (stable ABI).
static bool IsCancellable { get; } Whether handlers can cancel the event.
static string Key { get; } Registry key of the event.
public bool Cancelled { get; set; }

Cancelling stops lower-priority handlers (unless they opt in) and the action itself.

public ChatKind ChatType { get; set; }

The chat type of the line: Chat, EmoteCommand or SayCommand. The message kinds need a target and are refused here (Chat is used).

public Component Decoration { get; }

The body as the line shows it (unsigned content: colours, highlights, glyphs). Equal to the typed text means none. Keeps the message signed. (parsed on access; allocates).

public Utf8String DecorationJson { get; }

The body as the line shows it (unsigned content: colours, highlights, glyphs). Equal to the typed text means none. Keeps the message signed. as JSON text (borrowed).

public Utf8String FilterBits { get; }

For PartiallyFiltered: one 0 or 1 per UTF-16 unit of the typed text, 1 hides the unit. A different length or character fully filters the message. (mutable: use PlayerChatEvent.SetFilterBits)

public ChatFilterKind FilterKind { get; set; }

How the recipients who filter text see the message (vanilla FilterMask). Any other value fully filters the message.

public Utf8String Message { get; }

What the player typed. Changing it re-renders the line with the default format. (mutable: use PlayerChatEvent.SetMessage)

public Player Player { get; }

The sender.

public Component Rendered { get; }

The complete line shown to everybody (default: <name> message). Replace it to change the format; takes precedence over Message. (parsed on access; allocates).

public Utf8String RenderedJson { get; }

The complete line shown to everybody (default: <name> message). Replace it to change the format; takes precedence over Message. as JSON text (borrowed).

public Component SenderName { get; }

The sender name as the line shows it (hover, click and insertion included). Changing it keeps the message signed. (parsed on access; allocates).

public Utf8String SenderNameJson { get; }

The sender name as the line shows it (hover, click and insertion included). Changing it keeps the message signed. as JSON text (borrowed).

public static ushort CatalogueId { get; }

Catalogue id (stable ABI).

public static bool IsCancellable { get; }

Whether handlers can cancel the event.

public static string Key { get; }

Registry key of the event.

Member Description
void SetDecoration(Component value) Replaces PlayerChatEvent.Decoration; an empty component clears it where the event says so.
void SetFilterBits(string value) Replaces PlayerChatEvent.FilterBits (copied into the per-tick event arena; the engine reads it back after dispatch).
void SetMessage(string value) Replaces PlayerChatEvent.Message (copied into the per-tick event arena; the engine reads it back after dispatch).
void SetRendered(Component value) Replaces PlayerChatEvent.Rendered; an empty component clears it where the event says so.
void SetSenderName(Component value) Replaces PlayerChatEvent.SenderName; an empty component clears it where the event says so.
public void SetDecoration(Component value)

Replaces PlayerChatEvent.Decoration; an empty component clears it where the event says so.

Parameters

Name Type Description
value Component
public void SetFilterBits(string value)

Replaces PlayerChatEvent.FilterBits (copied into the per-tick event arena; the engine reads it back after dispatch).

Parameters

Name Type Description
value string
public void SetMessage(string value)

Replaces PlayerChatEvent.Message (copied into the per-tick event arena; the engine reads it back after dispatch).

Parameters

Name Type Description
value string
public void SetRendered(Component value)

Replaces PlayerChatEvent.Rendered; an empty component clears it where the event says so.

Parameters

Name Type Description
value Component
public void SetSenderName(Component value)

Replaces PlayerChatEvent.SenderName; an empty component clears it where the event says so.

Parameters

Name Type Description
value Component

ChatFilterKind · ChatKind · Component · IEvent · Player · Utf8String