/*
 * This file is part of MissileWars (https://github.com/Butzlabben/missilewars).
 * Copyright (c) 2018-2021 Daniel Nägele.
 *
 * MissileWars is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MissileWars is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MissileWars.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.butzlabben.missilewars.missile.paste.r1_13.we;

import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Material;

public class BlockFilterExtent extends AbstractDelegateExtent {

    private Material material;

    protected BlockFilterExtent(Extent extent) {
        super(extent);
    }

    public BlockFilterExtent(Extent extent, Material material) {
        this(extent);
        this.material = material;
    }

    @Override
    public BaseBlock getFullBlock(BlockVector3 position) {
        BaseBlock block = super.getFullBlock(position);
        if (block.getBlockType().toString().contains("stained_glass_pane")) {
            block = BlockTypes.get(material.toString().toLowerCase() + "_pane").getDefaultState().toBaseBlock();
        } else if (block.getBlockType().toString().contains("stained_glass")) {
            block = BlockTypes.get(material.toString().toLowerCase()).getDefaultState().toBaseBlock();
        }
        return block;
    }
}
