package eu.mhsl.minenet.minigames.util;

import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.ChangeGameStatePacket;
import net.minestom.server.timer.ExecutionType;
import net.minestom.server.timer.TaskSchedule;

import java.util.Set;


public class WeatherUtils {
    private float intensity;
    public void startRain(Set<Player> players) {
        intensity = 0;
        players.forEach(p -> p.sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.BEGIN_RAINING, 0f)));

        MinecraftServer.getSchedulerManager().submitTask(() -> {
            intensity += 0.1f;
            players.forEach(p -> p.sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.RAIN_LEVEL_CHANGE, intensity)));
            System.out.println(intensity);
            if(intensity < 1) {
                return TaskSchedule.millis(500);
            } else {
                return TaskSchedule.stop();
            }
        }, ExecutionType.TICK_END);
    }
}
