package de.teleportsuite.listeners;

import de.teleportsuite.TeleportSuite;
import de.teleportsuite.models.TeleportLocation;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;

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

    @EventHandler
    public void onRespawn(PlayerRespawnEvent event) {
        if (!plugin.getConfigManager().deathRespawnToSpawn()) return;
        TeleportLocation spawn = plugin.getDatabaseManager().getSpawn("spawn");
        if (spawn == null) return;
        var loc = spawn.toBukkitLocation();
        if (loc != null) event.setRespawnLocation(loc);
    }
}
