package ee.ellytr.practice.restore;

import ee.ellytr.practice.Practice;
import ee.ellytr.practice.util.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;

public class RestoreListener implements Listener {

    public RestoreListener() {
        Bukkit.getPluginManager().registerEvents(this, Practice.getInstance());
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Bukkit.getScheduler().runTaskLaterAsynchronously(Practice.getInstance(), () -> {
            PlayerUtils.restoreAll(event.getPlayer());
        }, 1);
    }

    @EventHandler
    public void onPlayerDeath(PlayerRespawnEvent event) {
        Bukkit.getScheduler().runTaskLaterAsynchronously(Practice.getInstance(), () -> {
            PlayerUtils.restoreAll(event.getPlayer());
        }, 1);
    }



}
