package de.teleportsuite.commands;
import de.teleportsuite.TeleportSuite;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
public class SetPortalCommand implements CommandExecutor {
    private final TeleportSuite plugin;
    public SetPortalCommand(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.setportal")) { p.sendMessage(plugin.getConfigManager().getMessage("no-permission")); return true; }
        // /setportal pos1 | pos2 | create <name> <server> <world> <x> <y> <z>
        if (args.length == 0) { p.sendMessage("§cVerwendung: /setportal pos1|pos2|create <name> [server] <world> <x> <y> <z>"); return true; }
        if (args[0].equalsIgnoreCase("pos1")) { plugin.getPortalManager().setPos1(p, p.getLocation()); return true; }
        if (args[0].equalsIgnoreCase("pos2")) { plugin.getPortalManager().setPos2(p, p.getLocation()); return true; }
        if (args[0].equalsIgnoreCase("create") && args.length >= 7) {
            String name = args[1], server = args[2], world = args[3];
            try {
                double x = Double.parseDouble(args[4]), y = Double.parseDouble(args[5]), z = Double.parseDouble(args[6]);
                plugin.getPortalManager().createPortal(p, name, server, world, x, y, z);
            } catch (NumberFormatException e) { p.sendMessage("§cUngültige Koordinaten!"); }
            return true;
        }
        p.sendMessage("§cVerwendung: /setportal pos1|pos2|create <name> <server> <world> <x> <y> <z>");
        return true;
    }
}
