/** Checking right click actions on blocks. */ public boolean checkBlockInteraction( Resident res, BlockPos bp, PlayerInteractEvent.Action action) { Block blockType = DimensionManager.getWorld(bp.getDim()).getBlock(bp.getX(), bp.getY(), bp.getZ()); for (SegmentBlock segment : segmentsBlocks) { if (segment.getCheckClass().isAssignableFrom(blockType.getClass()) && (segment.getMeta() == -1 || segment.getMeta() == DimensionManager.getWorld(bp.getDim()) .getBlockMetadata(bp.getX(), bp.getY(), bp.getZ())) && (segment.getType() == BlockType.ANY_CLICK || segment.getType() == BlockType.RIGHT_CLICK && action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || segment.getType() == BlockType.LEFT_CLICK && action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) { int dim = bp.getDim(); int x = bp.getX(); int y = bp.getY(); int z = bp.getZ(); if (!hasPermission(res, segment, dim, x, y, z)) { if (segment.hasClientUpdate()) sendClientUpdate( segment.getClientUpdateCoords(), bp, (EntityPlayerMP) res.getPlayer(), null); return true; } } } return false; }
/** Checking item usage for left or right click on block */ public boolean checkItem(ItemStack item, ItemType type, Resident res, BlockPos bp, int face) { for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) { SegmentItem segment = it.next(); if (segment.getType() == type && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) { ForgeDirection direction = ForgeDirection.getOrientation(face); if (segment.isOnAdjacent()) { bp = new BlockPos( bp.getX() + direction.offsetX, bp.getY() + direction.offsetY, bp.getZ() + direction.offsetZ, bp.getDim()); } if (!segment.isDirectionalClientUpdate()) { direction = null; } try { if (segment.checkCondition(item)) { int range = segment.getRange(item); int dim = bp.getDim(); int x = bp.getX(); int y = bp.getY(); int z = bp.getZ(); boolean isProtected; if (range == 0) { isProtected = !hasPermission(res, segment, dim, x, y, z); } else { Volume rangeBox = new Volume(x - range, y - range, z - range, x + range, y + range, z + range); isProtected = !hasPermission(res, segment, dim, rangeBox); } if (isProtected) { if (segment.hasClientUpdate()) { sendClientUpdate( segment.getClientUpdateCoords(), bp, (EntityPlayerMP) res.getPlayer(), direction); } return true; } } } catch (Exception ex) { MyTown.instance.LOG.error( "Failed to check item use on {} at the player {} ({})", item.getDisplayName(), res.getPlayerName(), bp); MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex)); if (ex instanceof GetterException || ex instanceof ConditionException) { this.disableSegment(it, segment, ex.getMessage()); } } } } return false; }