/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 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.velocitycore.mods;

import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.Player;
import de.steamwar.velocitycore.listeners.PluginMessage;

public class WorldDownloader {
    // https://wiki.vg/Plugin_channels/World_downloader
    // https://github.com/Pokechu22/WorldDownloader-Serverside-Companion
    // https://github.com/Pokechu22/WorldDownloader

    private final byte[] controlPacket;

    public WorldDownloader() {
        controlPacket = PluginMessage.genStreamPacket(out -> {
            out.writeInt(1); // basic data packet
            out.writeBoolean(false); // General download enabled
            out.writeInt(-1); // Save radius
            out.writeBoolean(false); // Chunk caching enabled
            out.writeBoolean(false); // Entity saving enabled
            out.writeBoolean(false); // Tile entity saving disabled
            out.writeBoolean(false); // Container saving disabled
        });
    }

    public void handlePluginMessage(PluginMessageEvent event) {
        PluginMessage.send((Player) event.getSource(), "WDL|CONTROL", "wdl:control", controlPacket);
    }
}
