package eu.mhsl.minecraft.pixelblocks.listeners;

import eu.mhsl.minecraft.pixelblocks.utils.EventCanceling;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;

public class PlacePixelListener implements Listener {
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent event) {
        EventCanceling.shouldCancelInPixelBlock(
            event,
            event.getBlock().getWorld(),
            pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getBlock().getLocation())
        );
    }

    @EventHandler
    public void onBucketEmpty(PlayerBucketEmptyEvent event) {
        EventCanceling.shouldCancelInPixelBlock(
            event,
            event.getBlock().getWorld(),
            pixelBlock -> !pixelBlock.getPixelWorld().allowPlacements(event.getBlock().getLocation())
        );
    }
}
