package mcjty.rftools.blocks;

import mcjty.lib.container.GenericBlock;
import mcjty.lib.container.GenericItemBlock;
import mcjty.lib.entity.GenericTileEntity;
import mcjty.lib.varia.GlobalCoordinate;
import mcjty.lib.varia.Logging;
import mcjty.rftools.RFTools;
import mcjty.rftools.blocks.blockprotector.BlockProtectorConfiguration;
import mcjty.rftools.blocks.blockprotector.BlockProtectors;
import mcjty.rftools.blocks.security.OrphaningCardItem;
import mcjty.rftools.blocks.security.SecurityChannels;
import mcjty.rftools.blocks.security.SecurityConfiguration;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Collection;

public abstract class GenericRFToolsBlock<T extends GenericTileEntity, C extends Container> extends GenericBlock<T, C> {

    public GenericRFToolsBlock(Material material,
                               Class<? extends T> tileEntityClass,
                               Class<? extends C> containerClass,
                               String name, boolean isContainer) {
        super(RFTools.instance, material, tileEntityClass, containerClass, GenericItemBlock.class, name, isContainer);
        setCreativeTab(RFTools.tabRfTools);
    }

    public GenericRFToolsBlock(Material material,
                               Class<? extends T> tileEntityClass,
                               Class<? extends C> containerClass,
                               Class<? extends ItemBlock> itemBlockClass,
                               String name, boolean isContainer) {
        super(RFTools.instance, material, tileEntityClass, containerClass, itemBlockClass, name, isContainer);
        setCreativeTab(RFTools.tabRfTools);
    }

    @Override
    public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity) {
        boolean b = super.canEntityDestroy(state, world, pos, entity);
        if (b && BlockProtectorConfiguration.enabled) {
            Collection<GlobalCoordinate> protectors = BlockProtectors.getProtectors(entity.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ());
            if (BlockProtectors.checkHarvestProtection(pos.getX(), pos.getY(), pos.getZ(), world, protectors)) {
                return false;
            }
        }
        return b;
    }

    @Override
    protected boolean checkAccess(World world, EntityPlayer player, TileEntity te) {
        if (SecurityConfiguration.enabled && te instanceof GenericTileEntity) {
            GenericTileEntity genericTileEntity = (GenericTileEntity) te;
            if ((!OrphaningCardItem.isPrivileged(player, world)) && (!player.getPersistentID().equals(genericTileEntity.getOwnerUUID()))) {
                int securityChannel = genericTileEntity.getSecurityChannel();
                if (securityChannel != -1) {
                    SecurityChannels securityChannels = SecurityChannels.getChannels(world);
                    SecurityChannels.SecurityChannel channel = securityChannels.getChannel(securityChannel);
                    boolean playerListed = channel.getPlayers().contains(player.getDisplayNameString());
                    if (channel.isWhitelist() != playerListed) {
                        Logging.message(player, TextFormatting.RED + "You have no permission to use this block!");
                        return true;
                    }
                }
            }
        }
        return false;
    }


}

@@ -180,217 +180,44 @@
 ria.
-GlobalCoordinate;%0Aimport mcjty.lib.varia.Logging;%0Aimport mcjty.rftools.RFTools;%0Aimport mcjty.rftools.blocks.blockprotector.BlockProtectorConfiguration;%0Aimport mcjty.rftools.blocks.blockprotector.BlockProtector
+Logging;%0Aimport mcjty.rftools.RFTool
 s;%0Ai
@@ -436,90 +436,8 @@
 al;%0A
-import net.minecraft.block.state.IBlockState;%0Aimport net.minecraft.entity.Entity;%0A
 impo
@@ -608,49 +608,8 @@
 ty;%0A
-import net.minecraft.util.math.BlockPos;%0A
 impo
@@ -655,49 +655,8 @@
 ng;%0A
-import net.minecraft.world.IBlockAccess;%0A
 impo
@@ -690,38 +690,8 @@
 d;%0A%0A
-import java.util.Collection;%0A%0A
 publ
@@ -1718,593 +1718,8 @@
  %7D%0A%0A
-    @Override%0A    public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity) %7B%0A        boolean b = super.canEntityDestroy(state, world, pos, entity);%0A        if (b && BlockProtectorConfiguration.enabled) %7B%0A            Collection%3CGlobalCoordinate%3E protectors = BlockProtectors.getProtectors(entity.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ());%0A            if (BlockProtectors.checkHarvestProtection(pos.getX(), pos.getY(), pos.getZ(), world, protectors)) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return b;%0A    %7D%0A%0A
     

Remove override of canEntityDestroy