Class ServerChatEvent
- Direct Known Subclasses:
ServerChatEvent.Preview
,ServerChatEvent.Submitted
ServerboundChatPreviewPacket
or ServerboundChatPacket
is received.
Mods that modify chat messages from this event should call ForgeMod.enableServerChatPreview()
from their mod constructor to enable the chat preview and allow signing by clients.
It is recommended to listen to this event class when modifying chat messages
rather than a subclass to ensure clients with Options.onlyShowSecureChat()
enabled can see the modified messages.
This event is cancellable, and does not have a result. If the event is cancelled, the message will not be sent to clients.
This event is fired on the main Forge event bus, only on the logical server.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This event is fired whenever aServerboundChatPreviewPacket
is received from a client typing a message.static class
This event is fired whenever aServerboundChatPacket
is received from a client who has submitted their chat message.Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event
net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
-
Field Summary
Modifier and TypeFieldDescriptionprivate final boolean
private Component
private final ServerPlayer
private final String
private final String
-
Constructor Summary
ModifierConstructorDescriptionprotected
ServerChatEvent
(ServerPlayer player, String rawText, Component message, boolean canChangeMessage) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether the message can be changed or not.Returns the message that will be sent to the relevant clients, if the event is not cancelled.Returns the player who initiated the chat action.Returns the original raw text of the player chat message.Returns the username of the player who initiated the chat action.void
setMessage
(Component message) Set the message to be sent to the relevant clients.Methods inherited from class net.minecraftforge.eventbus.api.Event
getListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult
-
Field Details
-
player
-
username
-
rawText
-
canChangeMessage
private final boolean canChangeMessage -
message
-
-
Constructor Details
-
ServerChatEvent
@Internal protected ServerChatEvent(ServerPlayer player, String rawText, Component message, boolean canChangeMessage)
-
-
Method Details
-
getPlayer
Returns the player who initiated the chat action.- Returns:
- the player who initiated the chat action
-
getUsername
Returns the username of the player who initiated the chat action.- Returns:
- the username of the player who initiated the chat action
-
getRawText
Returns the original raw text of the player chat message.- Returns:
- the original raw text of the player chat message
-
canChangeMessage
public boolean canChangeMessage()Returns whether the message can be changed or not.. In vanilla, this will be false if aServerboundChatPacket
is received with signed decorated content already included by the sending player. Players who submit a chat message with chat previews disabled will cause this to be true.- Returns:
- whether the message can be changed or not
-
setMessage
Set the message to be sent to the relevant clients.If
canChangeMessage()
is false, this call will be ignored.It is recommended to listen to
ServerChatEvent
when modifying chat messages rather than a subclass to ensure clients withOptions.onlyShowSecureChat()
enabled can see the modified messages.- See Also:
-
getMessage
Returns the message that will be sent to the relevant clients, if the event is not cancelled.- Returns:
- the message that will be sent to the relevant clients, if the event is not cancelled
-