#include <ChatCommand/SetCommand/SetCommand.hpp>
#include <Settings/Settings.hpp>

SetCommand::SetCommand()
{
    require(UserPermission::ConfigServer);

    addVariant(
        "<key> <value> - Change a setting.",
        [](Player &player, std::string key, std::string value)
        {
            std::string error = settings.set(key, value);
            settings.save();

            if (error == "")
            {
                player.writeChat(formatString("Changed setting '$+' to '$+'.", key, value), Color::success);
                Log::info(formatString("Changed setting '$+' to '$+'.", key, value));
            }
            else
            {
                player.writeChat(error, Color::error);
                Log::error(error);
            }
        }
    );
}