package eu.mhsl.minecraft.pixelblocks.listeners;

import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlockWorld;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFertilizeEvent;

import java.util.Objects;

public class PreventGrowthListener implements Listener {
    @EventHandler
    public void inBoneMeal(BlockFertilizeEvent event) {
        if(!PixelBlockWorld.isPixelWorld(event.getBlock().getWorld())) return;
        PixelBlock pixelBlock = PixelBlock.getPixelBlockFromBlockWorld(event.getBlock().getWorld());
        Objects.requireNonNull(pixelBlock);

        event.getBlocks().stream()
            .filter(blockState -> !pixelBlock.getPixelWorld().allowPlacements(blockState.getBlock().getLocation()))
            .forEach(blockState -> blockState.setType(Material.AIR));
    }
}
