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

import eu.mhsl.minenet.minigames.message.Icon;
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.event.EventListener;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import org.jetbrains.annotations.NotNull;

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

    @Override
    public @NotNull Result run(@NotNull PlayerDisconnectEvent event) {
        Player p = event.getPlayer();
        new ChatMessage(Icon.LEAVE)
            .appendStatic(p.getName().color(NamedTextColor.GRAY))
            .appendSpace()
            .appendTranslated("common#leave", NamedTextColor.DARK_GRAY)
            .send(MinecraftServer.getConnectionManager().getOnlinePlayers());
        return Result.SUCCESS;
    }
}
