package com.yutian.minerwar.listener;

import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;

public class JoinListener implements Listener {

    private final Game game;
    public JoinListener(){
        game = MinerWar.getGame();
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player player = e.getPlayer();
        new BukkitRunnable() {
            @Override
            public void run() {
                if(!game.isStarted()) {
                    game.start();
                }
                player.getInventory().clear();
                game.initPlayerData(e.getPlayer());
            }
        }.runTaskLater(MinerWar.inst(),10L);
    }
}
