package de.teleportsuite.commands;
import de.teleportsuite.TeleportSuite;
import de.teleportsuite.models.TeleportLocation;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
public class TpPosCommand implements CommandExecutor {
    private final TeleportSuite plugin;
    public TpPosCommand(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.tppos")) { p.sendMessage(plugin.getConfigManager().getMessage("no-permission")); return true; }
        if (args.length < 3) { p.sendMessage("§cVerwendung: /tppos <x> <y> <z> [world]"); return true; }
        try {
            double x = Double.parseDouble(args[0]), y = Double.parseDouble(args[1]), z = Double.parseDouble(args[2]);
            String world = args.length > 3 ? args[3] : p.getWorld().getName();
            plugin.getTeleportManager().teleport(p, new TeleportLocation(world, x, y, z, p.getLocation().getYaw(), p.getLocation().getPitch(), plugin.getConfigManager().getServerName()));
        } catch (NumberFormatException e) { p.sendMessage("§cUngültige Koordinaten!"); }
        return true;
    }
}
