package de.teleportsuite.commands;

import de.teleportsuite.TeleportSuite;
import de.teleportsuite.models.TeleportLocation;
import org.bukkit.command.*;
import org.bukkit.entity.Player;

public class DeathBackCommand implements CommandExecutor {
    private final TeleportSuite plugin;
    public DeathBackCommand(TeleportSuite p) { this.plugin = p; }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!(sender instanceof Player)) { sender.sendMessage("§cNur für Spieler!"); return true; }
        Player p = (Player) sender;
        if (!p.hasPermission("teleportsuite.deathback")) { p.sendMessage(plugin.getConfigManager().getMessage("no-permission")); return true; }
        TeleportLocation loc = plugin.getDatabaseManager().getDeathLocation(p.getUniqueId());
        if (loc == null) { p.sendMessage(plugin.getConfigManager().getMessage("death-no-location")); return true; }
        plugin.getTeleportManager().teleport(p, loc);
        return true;
    }
}
