package de.teleportsuite.commands;
import de.teleportsuite.TeleportSuite;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
import org.bukkit.entity.*;
public class EntityTransportCommand implements CommandExecutor {
    private final TeleportSuite plugin;
    public EntityTransportCommand(TeleportSuite p) { this.plugin = p; }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!sender.hasPermission("teleportsuite.entitytransport")) { sender.sendMessage(plugin.getConfigManager().getMessage("no-permission")); return true; }
        if (args.length < 2) { sender.sendMessage("§cVerwendung: /entitytransport <entity-id> <spieler>"); return true; }
        try {
            int entityId = Integer.parseInt(args[0]);
            Player target = Bukkit.getPlayer(args[1]);
            if (target == null) { sender.sendMessage(plugin.getConfigManager().getMessage("player-not-found","player",args[1])); return true; }
            Entity found = null;
            for (var world : Bukkit.getWorlds()) {
                for (var entity : world.getEntities()) {
                    if (entity.getEntityId() == entityId) { found = entity; break; }
                }
                if (found != null) break;
            }
            if (found == null) { sender.sendMessage("§cEntity mit ID §6" + entityId + " §cnicht gefunden."); return true; }
            found.teleport(target.getLocation());
            sender.sendMessage("§aEntity §6" + found.getType() + " §awurde zu §6" + target.getName() + " §ateleportiert.");
        } catch (NumberFormatException e) { sender.sendMessage("§cUngültige Entity-ID."); }
        return true;
    }
}
