Minecraft – How to stop players from spawning at their beds in Minecraft 1.14

minecraft-commandsminecraft-java-edition

I have been making a custom UHC map for a while now. It wouldn't be PVP-based, just try to last the longest, but the catch is that after dying, that's it: you are back to spawn, then teleported to a new random location in the world, from -1000000 to 1000000.
If the players were to sleep, their spawn point would be their bed, which would mean that if they'd die, they could respawn at their bed, collect items, and go on with their day. This is not how I want it to work (UHC is where you only regenerate with golden apples or potions, so hearts are valuable).

Best Answer

You can track people who sleep with the sleep_in_bed scoreboard:

/scoreboard objectives add sleeping minecraft.custom:minecraft.sleep_in_bed

Then you can remove beds around people who are sleeping:

/execute at @e[scores={sleeping=1..}] run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace #beds

And finally reset the score:

/scoreboard players reset @e sleeping