Cannot use Dispenser Tile Entity

Hello. I’m in the process of updating my plugin to 1.17.

I have a program that executes an action when there is a certain item in a dispenser, with the BlockDispenseEvent. It also cancels the event, so that the item is not dropped.

My code was working in 1.16, but in 1.17, when I power my dropper, i have this error:

Cannot invoke "" because the return value of "" is null

Here’s some of my code

	@EventHandler(priority = EventPriority.HIGH)
	public void onDrop(BlockDispenseEvent event) {
		// [...]
		CraftDispenser dispenser = ((CraftDispenser) event.getBlock().getState());
		TileEntityDispenser tileEntity = new TileEntityDispenser(dispenser.getPosition(), dispenser.getHandle());
		CraftBlockProjectileSource projectileSource = new CraftBlockProjectileSource(tileEntity);
		BlockProjectileSource blockSource = (BlockProjectileSource) source;
		Dispenser dispenser = (Dispenser) blockSource.getBlock().getBlockData();
		Vector direction = dispenser.getFacing().getDirection();
		// [...]

I could not find a simple fix. Is this a paper bug?