package de.hessj.environmentex;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Enums;
import io.papermc.paper.event.entity.EntityInsideBlockEvent;

public class CauldronConcrete implements Listener {
@EventHandler
    public void onPowderDrop(EntityInsideBlockEvent e){
        Block block = e.getBlock();
        if(block.getType()==Material.WATER_CAULDRON && e.getEntity() instanceof Item){
            Item item = (Item) e.getEntity();
            ItemStack concrete = item.getItemStack();
            if(!concrete.getType().toString().endsWith("_CONCRETE_POWDER")) return;
            Material mat = Enums.getIfPresent(Material.class, concrete.getType().toString().replace("_POWDER", "")).orNull();
            if(mat != null){
                item.getWorld().dropItem(item.getLocation(), new ItemStack(mat,concrete.getAmount()));
                item.remove();
            }
        }
    }
}
