Actions

Datapack

Sleep notify

From Zedwiki

Shows how many players are currently sleeping

Files

sleep_notify/pack.mcmeta

{
    "pack": {
        "pack_format": 1,
        "description": "Shows how many players are currently sleeping"
    }
}

sleep_notify/data/minecraft/tags/functions/load.json

Specifies the setup mcfunction to be ran on server load (or reload)

{
    "replace": "false",
    "values": [
        "sleep_notify:setup"
    ]
}

sleep_notify/data/minecraft/tags/functions/tick.json

Specifies the root mcfunction to be ran every tick

{
    "replace": "false",
    "values": [
        "sleep_notify:root"
    ]
}

sleep_notify/data/sleep_notify/functions/root.mcfunction

The root mcfunction, this is ran every tick (as specified in the tick.json file).

#function sleep_notify/root
execute if entity @a[nbt={Sleeping:1b}] run function sleep_notify:notify

sleep_notify/data/sleep_notify/functions/notify.mcfunction

The notify mcfunction is only ran if one or more players are currently sleeping.

#function sleep_notify/notify
scoreboard players reset * sleep_notify
execute as @a run scoreboard players add online sleep_notify 1
execute as @a[nbt={Sleeping:1b}] run scoreboard players add sleeping sleep_notify 1
title @a actionbar {"text":"","extra":[{"score":{"name":"sleeping","objective":"sleep_notify"},"color":"aqua"},{"text":"/","color":"gray"},{"score":{"name":"online","objective":"sleep_notify"},"color":"dark_aqua"},{"text":" players are sleeping","color":"gray"}]}

sleep_notify/data/sleep_notify/functions/setup.mcfunction

The setup mcfunction adds the scoreboard objective required for tracking sleeping players. This is ran on server start and reload, as specified in load.json.

#function sleep_notify/setup
scoreboard objectives add sleep_notify dummy