package eu.mhsl.minecraft.pixelblocks.listeners;

import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
import org.bukkit.Location;
import org.bukkit.entity.Interaction;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;

public class EnterPixelBlockListener implements Listener {
    @EventHandler
    public void enterPixelBlock(PlayerInteractEntityEvent event) {
        if(!(event.getRightClicked() instanceof Interaction)) return;

        Location interactionLocation = event
            .getRightClicked()
            .getLocation()
            .toBlockLocation();
        PixelBlock pixelBlock = PixelBlock.getPixelBlockFromPlacedLocation(interactionLocation);
        if(pixelBlock == null) return;
        pixelBlock.enterBlock(event.getPlayer());
    }
}
