Search in sources :

Example 1 with ItemScanTool

use of com.ldtteam.structurize.items.ItemScanTool 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 (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
            cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
            return;
        }
        final Permissions perms = colony.getPermissions();
        if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
            return;
        }
        if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
            if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
                checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
                cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
                return;
            }
            if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
                checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            final ItemStack stack = event.getItemStack();
            if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
                return;
            }
            if (stack.getItem() instanceof PotionItem) {
                checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
                cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
            }
        }
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) ContainerBlock(net.minecraft.block.ContainerBlock) PotionItem(net.minecraft.item.PotionItem) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ContainerBlock(net.minecraft.block.ContainerBlock) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ItemScanTool

use of com.ldtteam.structurize.items.ItemScanTool in project minecolonies by ldtteam.

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 (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
            cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
            return;
        }
        final Permissions perms = colony.getPermissions();
        if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
            return;
        }
        if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
            if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
                checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
                cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
                return;
            }
            if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
                checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            final ItemStack stack = event.getItemStack();
            if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
                return;
            }
            if (stack.getItem() instanceof PotionItem) {
                checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
                cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
            }
        }
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) ContainerBlock(net.minecraft.block.ContainerBlock) PotionItem(net.minecraft.item.PotionItem) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ContainerBlock(net.minecraft.block.ContainerBlock) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ItemScanTool (com.ldtteam.structurize.items.ItemScanTool)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)2 AirBlock (net.minecraft.block.AirBlock)2 Block (net.minecraft.block.Block)2 ContainerBlock (net.minecraft.block.ContainerBlock)2 ItemStack (net.minecraft.item.ItemStack)2 PotionItem (net.minecraft.item.PotionItem)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2