API reference / @jsprismarine/prismarine / chat/ChatManager / ChatManager
Class: ChatManager
Defined in: packages/prismarine/src/chat/ChatManager.ts:137
Chat for the whole server: sending a message, and which players it reaches.
A message goes out as a chat event first, which the console, the remote console and plugins listen for, and then to every player that has joined whom its channel reaches. A player joins the fan-out with ChatManager.join once its join completes and leaves it with ChatManager.leave, both keyed by keyOfPlayer. The table is server-wide state, not a world's, so it changes when the call is made, inside a tick or between ticks.
A line a player typed goes past the guard stage first, where a script's chatSend before-event runs, and a veto there drops it before the event or any player sees it.
The event is a before-hook: its listeners are called in the order they subscribed, and a listener that cancels it before its first wait stops every player, whenever they joined. The players are not listeners themselves, so the fan-out is one pass over them after the event.
Constructors
Constructor
new ChatManager(
events):ChatManager
Defined in: packages/prismarine/src/chat/ChatManager.ts:145
Parameters
events
The bus chat events go out on, which is the server's.
Returns
ChatManager
Methods
addGuard()
addGuard(
guard): () =>void
Defined in: packages/prismarine/src/chat/ChatManager.ts:178
Adds a guard to the guard stage of a player's chat, after the ones already there.
Parameters
guard
Returns
A function that removes it.
() => void
hasJoined()
hasJoined(
key):boolean
Defined in: packages/prismarine/src/chat/ChatManager.ts:223
Whether a player is in the fan-out under a key.
Parameters
key
string
The player's key; see keyOfPlayer.
Returns
boolean
join()
join(
recipient):void
Defined in: packages/prismarine/src/chat/ChatManager.ts:203
Adds a player to the fan-out. A player already joined under the same key is replaced.
Parameters
recipient
The connected player.
Returns
void
leave()
leave(
recipient):void
Defined in: packages/prismarine/src/chat/ChatManager.ts:214
Takes a player out of the fan-out. Does nothing when another player holds the key by now, so a replaced login leaving late does not take its successor's chat with it.
Parameters
recipient
The recipient ChatManager.join was given.
Returns
void
onSent()
onSent(
listener): () =>void
Defined in: packages/prismarine/src/chat/ChatManager.ts:191
Calls listener with each line a player typed that went past the guards and the chat event, as it goes out to the players, for a script's world.afterEvents.chatSend.
Parameters
listener
(intent) => void
Returns
A function that stops it.
() => void
send()
send(
chat):Promise<void>
Defined in: packages/prismarine/src/chat/ChatManager.ts:157
Sends a message to the console, the plugins and every player its channel reaches.
The chat listeners run first, each to its first wait, and the players get the message once they all have, unless one canceled it. Every line is queued before this returns.
Parameters
chat
The message.
Returns
Promise<void>
When the transport has framed every player's line.