How to prevent the closest player from breaking blocks?
Solution 1:
You can put the closest player into adventure mode:
/gamemode 2 @p
Or give them an extreme level of mining fatigue:
/effect @p mining_fatigue 1000000 100
To undo these (and allow them to break blocks again), you would put them back into survival mode:
/gamemode 0 @p
Or remove the mining fatigue:
/effect @p mining_fatigue 0
Solution 2:
What I would do is have two command blocks in a chain. The first command block would have:
/gamemode 0 @a
Then the second in the chain would have:
/gamemode 2 @p
This would allow the nearest player to be unable to break blocks, and also if the nearest player changes, then it would allow the first player to break blocks again and put the new closest player in adventure mode.
If you want the player to still be able to place blocks, then I would put
/effect @p mining_fatigue 1000000 100
instead of
/gamemode 2 @p
as the previous answer suggested.