package com.trafalcraft.anti_redstone_clock.commands;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ArcTpCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Nur Spieler können diesen Befehl nutzen.");
            return true;
        }
        if (args.length < 4) {
            sender.sendMessage("Verwendung: /arc_tp <x> <y> <z> <world>");
            return true;
        }
        Player player = (Player) sender;
        try {
            double x = Double.parseDouble(args[0]);
            double y = Double.parseDouble(args[1]);
            double z = Double.parseDouble(args[2]);
            World world = Bukkit.getWorld(args[3]);
            if (world == null) {
                player.sendMessage("Welt nicht gefunden: " + args[3]);
                return true;
            }
            Location loc = new Location(world, x, y, z);
            player.teleport(loc);
            player.sendMessage("§aTeleportiert zu: " + x + ", " + y + ", " + z + " in Welt " + world.getName());
        } catch (NumberFormatException e) {
            player.sendMessage("Ungültige Koordinaten!");
        }
        return true;
    }
}
