/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.world.teleport;

import com.google.common.collect.ImmutableSet;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.world.teleport.TeleportHelperFilter;
import org.spongepowered.common.block.BlockUtil;

import java.util.Set;

public class DefaultTeleportHelperFilter implements TeleportHelperFilter {

    // Materials it is NOT safe to put players on top of.
    private static final Set<Material> NOT_SAFE_FLOOR = ImmutableSet.of(Material.AIR, Material.CACTUS, Material.FIRE, Material.LAVA);

    @Override
    public String getId() {
        return "sponge:default";
    }

    @Override
    public String getName() {
        return "Default Teleport Helper filter";
    }

    @Override
    public boolean isSafeFloorMaterial(BlockState blockState) {
        return !NOT_SAFE_FLOOR.contains(BlockUtil.toNative(blockState).getMaterial());
    }

    @Override
    public boolean isSafeBodyMaterial(BlockState blockState) {
        IBlockState state = BlockUtil.toNative(blockState);
        Material material = state.getMaterial();

        // Also avoid slabs.
        return !state.causesSuffocation() && material != Material.LAVA && !(state.getBlock() instanceof BlockSlab);
    }
}

@@ -1370,20 +1370,262 @@
 ck.Block
-Slab
+Anvil;%0Aimport net.minecraft.block.BlockCauldron;%0Aimport net.minecraft.block.BlockChorusPlant;%0Aimport net.minecraft.block.BlockFence;%0Aimport net.minecraft.block.BlockGlass;%0Aimport net.minecraft.block.BlockSlab;%0Aimport net.minecraft.block.BlockSnow
 ;%0Aimport
@@ -2721,25 +2721,34 @@
  // 
-Also avoid slabs.
+Deny blocks that suffocate
 %0A   
@@ -2752,24 +2752,20 @@
         
-return !
+if (
 state.ca
@@ -2781,20 +2781,99 @@
 cation()
- && 
+) %7B%0A            return false;%0A        %7D%0A        // Deny dangerous lava%0A        if (
 material
@@ -2873,17 +2873,17 @@
 aterial 
-!
+=
 = Materi
@@ -2893,51 +2893,689 @@
 LAVA
- && !(state.getBlock() instanceof BlockSlab
+) %7B%0A            return false;%0A        %7D%0A%0A        // Sadly there is no easy way to check for this using vanilla right now as Blocks like Cauldron are technically marked as passable.%0A%0A        // Deny non-passable non %22full%22 blocks%0A        return !(state.getBlock() instanceof BlockSlab %7C%7C%0A                 state.getBlock() instanceof BlockCauldron %7C%7C%0A                 state.getBlock() instanceof BlockAnvil %7C%7C%0A                 state.getBlock() instanceof BlockFence %7C%7C%0A                 state.getBlock() instanceof BlockChorusPlant %7C%7C%0A                 state.getBlock() instanceof BlockSnow %7C%7C%0A                 material == Material.GLASS %7C%7C%0A                 material == Material.LEAVES
 );%0A 

fix TeleportHelperFilter teleporting into non-passable blocks