package com.elmakers.mine.bukkit.entity;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;

import com.elmakers.mine.bukkit.api.block.MaterialAndData;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;
import com.elmakers.mine.bukkit.utility.NMSUtils;

public class EntityFallingBlockData extends EntityExtraData {
    @Nullable
    private MaterialAndData material;

    private EntityFallingBlockData(MaterialAndData material) {
        this.material = material;
    }

    public EntityFallingBlockData(ConfigurationSection configuration) {
        material = ConfigurationUtils.getMaterialAndData(configuration, "material");
    }

    public EntityFallingBlockData(FallingBlock fallingBlock) {
        byte data = NMSUtils.getBlockData(fallingBlock);
        material = new com.elmakers.mine.bukkit.block.MaterialAndData(fallingBlock.getMaterial(), data);
    }

    @Override
    public void apply(Entity entity) {
        // Can't change a falling block after the fact.
    }

    @Override
    public EntityExtraData clone() {
        EntityFallingBlockData copy = new EntityFallingBlockData(this.material);
        return copy;
    }

    public void setMaterialAndData(@Nonnull MaterialAndData material) {
        this.material = material;
    }

    @Nullable
    public MaterialAndData getMaterialAndData() {
        return material;
    }

    @Nullable
    public Material getMaterial() {
        return material == null ? null : material.getMaterial();
    }

    public byte getData() {
        if (material == null) {
            return 0;
        }

        Byte data = material.getBlockData();
        return data == null ? 0 : data;
    }
}

@@ -541,16 +541,81 @@
 aterial;
+%0A    private boolean dropItems;%0A    private boolean hurtEntities;
 %0A%0A    pr
@@ -869,16 +869,155 @@
 rial%22);%0A
+        dropItems = configuration.getBoolean(%22drop_items%22, false);%0A        hurtEntities = configuration.getBoolean(%22hurt_entities%22, true);%0A
     %7D%0A%0A 
@@ -1240,16 +1240,113 @@
  data);%0A
+        fallingBlock.setDropItem(dropItems);%0A        fallingBlock.setHurtEntities(hurtEntities);%0A
     %7D%0A%0A 

Add drop_items and hurt_entities parameters to falling block mobs