Class ServerMessageDecoratorEvent
java.lang.Object
net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent
A class for registering a
ChatDecorator. Check the chat decorator documentation
for how chat decorators work. Unlike other events, this uses a functional interface that is
provided by the vanilla game.
This event uses phases to provide better mod compatibilities between mods that add custom
content and styling. Chat decorators with the styling phase will always apply after the ones
with the content phase. When registering the chat decorator, it is recommended to choose one
of the phases from this interface and pass that to the Event.register(Identifier, Object)
function. If not given, the chat decorator will run in the default phase, which is between
the content phase and the styling phase.
Example of registering a content phase chat decorator:
ServerMessageDecoratorEvent.EVENT.register(ServerMessageDecoratorEvent.CONTENT_PHASE, (sender, message) -> {
// Add smiley face. Has to copy() to get a MutableComponent with siblings and styles.
return message.copy().append(" :)");
});
Example of registering a styling phase message decorator:
ServerMessageDecoratorEvent.EVENT.register(ServerMessageDecoratorEvent.STYLING_PHASE, (sender, message) -> {
// Apply orange color to messages sent by server operators
if (sender != null && sender.server.getPlayerManager().isOperator(sender.getGameProfile())) {
return message.copy().styled(style -> style.withColor(0xFFA500));
}
return message;
});
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.minecraft.resources.IdentifierThe content phase of the event, passed when registering a chat decorator.static final Event<net.minecraft.network.chat.ChatDecorator> static final net.minecraft.resources.IdentifierThe styling phase of the event, passed when registering a chat decorator. -
Method Summary
-
Field Details
-
CONTENT_PHASE
public static final net.minecraft.resources.Identifier CONTENT_PHASEThe content phase of the event, passed when registering a chat decorator. Use this when the decorator modifies the component contents of the message. -
STYLING_PHASE
public static final net.minecraft.resources.Identifier STYLING_PHASEThe styling phase of the event, passed when registering a chat decorator. Use this when the decorator only modifies the styling of the message with the component intact. -
EVENT
-