I'm making a Minecraft server for my friends and I, but one of them is a notorious X-Rayer. I came up with a way to stop him: hide the ore blocks (by turning them into stone/netherrack), then turn them back when a player is nearby. I thought about ways to do this, but I cannot think of a solution. Is there any way to do this?
Unfortunately this won't be reasonably doable with vanilla Minecraft. You'll need a modded server, with Forge or Bukkit.
If you use a Bukkit server, you'll be able to use the Orebfuscator plugin to do this for you. For versions newer than 1.13, there's a third-party updated version available on GitHub.