Skip to content

PlayerChatEvent

Package: com.hypixel.hytale.server.core.event.events.player Implements: IAsyncEvent<String>, ICancellable Cancellable: Yes Async: Yes

Asynchronous event dispatched when a player sends a chat message. Listeners receive a CompletableFuture and can perform asynchronous operations before the message is sent. See also SendCommonAssetsEvent for another async event.

All data fields are mutable, allowing listeners to modify the sender, target list, message content, and formatting before the message is delivered. Cancelling this event prevents the chat message from being broadcast.

FieldTypeAccessorMutableNullable
senderPlayerRefgetSender()YesNo
targetsList<PlayerRef>getTargets()YesNo
contentStringgetContent()YesNo
formatterPlayerChatEvent.FormattergetFormatter()YesNo
  • sender — The player who sent the message. Mutable via setSender(@Nonnull PlayerRef).
  • targets — The list of players who will receive the message. Mutable via setTargets(@Nonnull List<PlayerRef>).
  • content — The text content of the chat message. Mutable via setContent(@Nonnull String).
  • formatter — The formatter used to convert the message into a Message object for display. Defaults to DEFAULT_FORMATTER which uses the server.chat.playerMessage translation with username and message parameters. Mutable via setFormatter(@Nonnull PlayerChatEvent.Formatter).

Functional interface for formatting chat messages.

public interface Formatter {
@Nonnull
Message format(@Nonnull PlayerRef var1, @Nonnull String var2);
}

The default formatter (DEFAULT_FORMATTER) uses Message.translation("server.chat.playerMessage").param("username", playerRef.getUsername()).param("message", msg).

  • GamePacketHandler (line 367) via eventBus dispatchForAsync — EventBus async dispatch when player sends a chat message.

Because PlayerChatEvent implements IAsyncEvent, use registerAsync for async handling or register for synchronous handling.

// Synchronous listener:
getEventRegistry().register(PlayerChatEvent.class, event -> {
String content = event.getContent();
// Example: censor profanity
event.setContent(censorProfanity(content));
});
// Async listener (can perform I/O):
getEventRegistry().registerAsync(PlayerChatEvent.class, future -> {
return future.thenApply(event -> {
event.setContent(event.getContent().toUpperCase());
return event;
});
});