ServerEvents.loaded(event => {
  event.server.runCommandSilent(
    `scoreboard objectives add sleeping minecraft.custom:minecraft.sleep_in_bed`
  )
})
ServerEvents.tick(event => {
  const { server, server: { persistentData } } = event
  server.runCommandSilent(`execute as @a if score @s sleeping matches 1 at @s if block ~ ~0.1 ~ #minecraft:beds run time add 5.2s`)
  server.runCommandSilent(`execute as @a if score @s sleeping matches 1 at @s unless block ~ ~0.05 ~ #minecraft:beds run scoreboard players reset @s sleeping`)
})