#include <ChatCommand/BanCommand/BanCommand.hpp>

BanCommand::BanCommand(ServerWorld &world)
{
    require(UserPermission::BanUsers);

    addVariant(
        "<username> - Ban a user.",
        [&world](Player &player, std::string userName)
        {
            std::string error = userDB.banUser(userName);
            if (error.size() != 0)
            {
                player.writeChat(formatString("Cannot ban '$+': $+", userName, error), Color::error);
                return;
            }

            auto targetPlayer = world.getPlayer(userName);
            if (targetPlayer != nullptr)
            {
                targetPlayer->isBeingForcedOut = true;
                targetPlayer->client->sendKickedFromServerMessage("You've been banned.");
            }

            world.sendChatToAllPlayers(formatString("Player '$+' has been banned.", userName), Color::warning);
        }
    );
}