Class ServerMessageDecoratorEvent

java.lang.Object
net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent

public final class ServerMessageDecoratorEvent extends Object
A class for registering a MessageDecorator. Check the message decorator documentation for how message 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. Message decorators with the styling phase will always apply after the ones with the content phase. When registering the message 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 message decorator will run in the default phase, which is between the content phase and the styling phase.

Example of registering a content phase message decorator:


 ServerMessageDecoratorEvent.EVENT.register(ServerMessageDecoratorEvent.CONTENT_PHASE, (sender, message) -> {
     // Add smiley face. Has to copy() to get a MutableText 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 Details

    • CONTENT_PHASE

      public static final Identifier CONTENT_PHASE
      The content phase of the event, passed when registering a message decorator. Use this when the decorator modifies the text content of the message.
    • STYLING_PHASE

      public static final Identifier STYLING_PHASE
      The styling phase of the event, passed when registering a message decorator. Use this when the decorator only modifies the styling of the message with the text intact.
    • EVENT

      public static final Event<MessageDecorator> EVENT