/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2026 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.features.dev;

import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;

@Linked
public class CreateKitCommand extends SWCommand {

    public CreateKitCommand() {
        super("createkit");
        if (!BauSystem.DEV_SERVER) unregister();
    }

    @Register
    public void onCommand(Player player, String name) {
        YamlConfiguration yaml = new YamlConfiguration();

        yaml.set("Items", player.getInventory().getContents());
        yaml.set("Armor", player.getInventory().getArmorContents());
        yaml.set("Effects", player.getActivePotionEffects());
        yaml.set("LeaderAllowed", true);
        yaml.set("MemberAllowed", true);
        yaml.set("EnterStage", 0);
        yaml.set("TNT", true);

        YamlConfiguration kits = new YamlConfiguration();

        kits.set("Kits." + name, yaml);

        try {
            kits.save(new File("new.kits.yaml"));

            player.sendMessage("Kit created!");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
