Bukkit: Replacing block just drops item of new block

I'm new to Java and Spigot-API. I want to do a BlockBreakEvent which detects if a GOLD_ORE block got destroyed by a player. If so, it should replace that GOLD_ORE block with a STONE block. However it doesn't work and instead of replacing the block it drops the item which is a cobblestone of course.

My code:

public class GoldOreListener implements Listener {

    @EventHandler
    public void onGoldOreDestroyed(BlockBreakEvent event)
    {
        Block block = event.getBlock();
        Player player = event.getPlayer();

        Material material = block.getType();

        if (material == Material.GOLD_ORE)
        {
            Location locationOfBlock = block.getLocation();
            Material newMaterial = Material.STONE;

            System.out.println(locationOfBlock.getBlock());
            locationOfBlock.getBlock().setType(newMaterial);
        }

    }
}

Output of locationOfBlock.getBlock():

CraftBlock{pos=BlockPosition{x=-158, y=83, z=303},type=GOLD_ORE,data=Block{minecraft:gold_ore},fluid=net.minecraft.world.level.material.FluidTypeEmpty@1507c3c3}

It's normal because this event is called before the block is really breaked. So, change the block in the event call will does nothing and will be overrided by the real effect.

You should cancel the event like that :

@EventHandler
public void onGoldOreDestroyed(BlockBreakEvent event) {
    Block block = event.getBlock();
    Material material = block.getType();
    if (material == Material.GOLD_ORE) {
         event.setCancelled(true); // cancel here
         block.setType(Material.STONE);
    }
}

You can also wait one tick, but this is clearly not recommended.