Search in sources :

Example 1 with BlockContainer

use of net.minecraft.block.BlockContainer in project minecolonies by Minecolonies.

the class ColonyPermissionEventHandler method on.

/**
     * PlayerInteractEvent handler.
     * <p>
     * Check, if a player right clicked a block.
     * Deny if:
     * - If the block is in colony
     * - block is AbstractBlockHut
     * - player has not permission
     *
     * @param event PlayerInteractEvent
     */
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
    if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
        final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
        // Huts
        if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
            cancelEvent(event, event.getEntityPlayer());
        }
        final Permissions perms = colony.getPermissions();
        if (isFreeToInteractWith(event.getWorld().getBlockState(event.getPos()).getBlock(), event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
            return;
        }
        if (Configurations.enableColonyProtection) {
            if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && event.getWorld().getBlockState(event.getPos()).getBlock() != null) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
                cancelEvent(event, event.getEntityPlayer());
            }
            if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
                cancelEvent(event, event.getEntityPlayer());
            }
        }
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ItemScanTool(com.minecolonies.coremod.items.ItemScanTool) BlockContainer(net.minecraft.block.BlockContainer) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) Block(net.minecraft.block.Block) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 ItemScanTool (com.minecolonies.coremod.items.ItemScanTool)1 Block (net.minecraft.block.Block)1 BlockContainer (net.minecraft.block.BlockContainer)1 ItemPotion (net.minecraft.item.ItemPotion)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1