Restrict block placement beside certain blocks

I would like to have a way of blocking the placement of blocks next to certain blocks to stop any glitches/dupes/or just bugs, either being on the top/bottom or on sides.

Thanks you!