Skip to content

PlayerChatEvent

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

Dispatched asynchronously when a player sends a chat message. This is the only async event in the Hytale event system — listeners receive a CompletableFuture rather than the event directly, enabling non-blocking processing of chat messages.

All data fields are mutable, allowing listeners to modify the sender, target list, message content, and formatting before the message is delivered.

Because the key type is String, this event is dispatched with a string key and listeners can filter by key value.

FieldTypeAccessorMutableNotes
senderPlayerRefgetSender()YesThe player who sent the message.
targetsList<PlayerRef>getTargets()YesThe list of players who will receive the message.
contentStringgetContent()YesThe raw text content of the chat message.
formatterPlayerChatEvent.FormattergetFormatter()YesThe formatter used to produce the final Message from sender and content.

Functional interface that controls how the chat message is formatted for display.

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

The DEFAULT_FORMATTER uses the server.chat.playerMessage translation key to produce the formatted message.

  • GamePacketHandler (line 367) via eventBus.dispatchForAsync() — async dispatch when a player sends a chat message through the game packet handler.

Because PlayerChatEvent implements IAsyncEvent, you must use registerAsync instead of register. The callback receives a CompletableFuture<PlayerChatEvent> rather than the event directly.

getEventRegistry().registerAsync(PlayerChatEvent.class, future -> {
return future.thenApply(event -> {
// Modify message content
event.setContent(event.getContent().toUpperCase());
return event;
});
});

To cancel the event asynchronously:

getEventRegistry().registerAsync(PlayerChatEvent.class, future -> {
return future.thenApply(event -> {
if (event.getContent().contains("blocked")) {
event.setCancelled(true);
}
return event;
});
});

This event is unique in the Hytale event system as the only async event. There are no directly related events in the same lifecycle, but it is part of the broader player event family:

  • PlayerConnectEvent — fired when the player connects. The player must be connected before chat events can fire.
  • PlayerDisconnectEvent — fired when the player disconnects. No further chat events fire after this.