package de.teleportsuite.listeners;

import de.teleportsuite.TeleportSuite;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;

public class PlayerMoveListener implements Listener {
    private final TeleportSuite plugin;
    public PlayerMoveListener(TeleportSuite plugin) { this.plugin = plugin; }

    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        if (!plugin.getConfigManager().cancelOnMove()) return;
        var from = event.getFrom();
        var to = event.getTo();
        if (to == null) return;
        if (from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
            plugin.getTeleportManager().cancelWarmup(event.getPlayer().getUniqueId());
        }
        // Portal check
        plugin.getPortalManager().checkPortal(event.getPlayer(), to);
    }
}
