hytalejs icon indicating copy to clipboard operation
hytalejs copied to clipboard

Issue with Chat Example

Open notG0ld opened this issue 10 months ago • 0 comments

The chat event seems to be triggered twice.

Heres the plugins code:

import { type PlayerChatEvent, EventListener, Colors } from "@hytalejs.com/core";

export class PlayerChatHandler {
  @EventListener("PlayerChatEvent")
  onPlayerChat(event: PlayerChatEvent): void {
    const sender = event.getSender();
    const content = event.getContent();
    logger.info("[CHAT] " + sender.getUsername() + ": " + content);

    const playerName = Message.raw(sender.getUsername()).color(Colors.WHITE).bold(true);
    const separator = Message.raw(" > ").color(Colors.DARK_GRAY);
    const messageText = Message.raw(content).color(Colors.LIGHT_GRAY);

    const formattedMessage = Message.empty().insert(playerName).insert(separator).insert(messageText);

    event.setCancelled(true);
	
    const targets = event.getTargets();
    for (let i = 0; i < targets.length; i++) {
      targets[i].sendMessage(formattedMessage);
    }
  }
}

Not sure if its an issue with my hytale server tho, as all messages from hytalejs seem to be sent twice.

Image But yeah its twice in the console too Image

notG0ld avatar Jan 20 '26 11:01 notG0ld