package de.teleportsuite.listeners;

import de.teleportsuite.TeleportSuite;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public class PlayerJoinListener implements Listener {
    private final TeleportSuite plugin;
    public PlayerJoinListener(TeleportSuite plugin) { this.plugin = plugin; }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        if (!plugin.getConfigManager().firstJoinTeleport()) return;
        var player = event.getPlayer();
        if (plugin.getDatabaseManager().isFirstJoin(player.getUniqueId())) {
            plugin.getDatabaseManager().setFirstJoinDone(player.getUniqueId());
            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
                () -> plugin.getSpawnManager().teleportToFirstSpawn(player), 20L);
        }
    }
}
