package eu.mhsl.minenet.minigames.command.privileged;

import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.entity.Player;

import java.util.Objects;

public class KickCommand extends PrivilegedCommand {
    public KickCommand() {
        super("kick");

        addSyntax(
            (sender, context) ->
                kick(context.getRaw("player"), ""),
                ArgumentType.Entity("player").onlyPlayers(true)
        );

        addSyntax(
            (sender, context) ->
                kick(context.getRaw("player"), context.getRaw("reason")),
                ArgumentType.Entity("player").onlyPlayers(true),
                ArgumentType.String("reason")
        );
    }

    private void kick(String playername, String reason) {
        Player playerToKick = MinecraftServer.getConnectionManager().findOnlinePlayer(playername);
        Objects.requireNonNull(playerToKick).kick(reason);
    }
}
