package eu.mhsl.minenet.minigames.handler.global;

import eu.mhsl.minenet.minigames.message.type.ChatMessage;
import net.minestom.server.event.EventListener;
import net.minestom.server.event.player.PlayerChatEvent;
import org.jetbrains.annotations.NotNull;

public class PlayerChatHandler implements EventListener<PlayerChatEvent> {
    @Override
    public @NotNull Class<PlayerChatEvent> eventType() {
        return PlayerChatEvent.class;
    }

    @Override
    public @NotNull Result run(@NotNull PlayerChatEvent event) {
        event.setChatFormat(
                (messages) -> new ChatMessage()
                        .appendStatic(event.getPlayer().getUsername())
                        .pipe()
                        .appendStatic(messages.getMessage())
                        .build(event.getPlayer())
        );

        return Result.SUCCESS;
    }
}
