// Hand-written examples for Docs entries that no example elsewhere in the documentation covers.
// An entry starts with '@ ' followed by the entry's syntax exactly as the Docs page shows it.
// Every example here is compiled when the documentation is checked, so it has to be real code.

@ %server.max_players%
send "&7%server.online_players% of %server.max_players% players online"

@ %server.time%
set {player.last_seen} to server.time

@ %event.world%, %event.x%, %event.y%, %event.z%
on block break:
    log "%player.name% broke a block at %event.x%, %event.y%, %event.z% in %event.world%"

@ %discord.user%
on discord command "/hello":
    reply "Hello, %discord.user%!"

@ %discord.channel%
on discord command "/where":
    reply "You are in #%discord.channel%"

@ <amount> in front
give 16 bread to player

@ ( )
set _total to (_price + _tax) * _amount

@ random integer between A and B
set _roll to random integer between 1 and 6

@ random number between A and B
set _chance to random number between 0 and 1

@ > < >= <=
if {player.coins} >= 100:
    send "&aYou can afford it."

@ is a number / is not a number
if arg.1 is not a number:
    send "&cUsage: /pay <amount>"
    stop

@ {_list.<n>}
set _parts to split "Coins:500" by ":"
send "You have %{_parts.2}% coins"

@ remove <value> from <variable>
remove player.name from {global.winners}

@ join <list> with <separator>
send "Online: " + join server.players with ", "

@ trimmed <text>
set _name to trimmed args

@ replace <a> with <b> in <text>
set _pretty to replace "_" with " " in "diamond_sword"

@ last <n> characters of <text>
set _ending to last 3 characters of player.name

@ characters <a> to <b> of <text>
set _middle to characters 2 to 4 of "Hello"

@ length of <text>
if length of args > 50:
    send "&cThat is too long."

@ rounded <number>
send "TPS: " + rounded server.tps

@ append <text> to file at <path>
append "\n%player.name% joined" to file at "plugins/HyperScript/log.txt"

@ delete file at <path>
delete file at "plugins/HyperScript/notes/old.txt"

@ execute player command <text>
execute player command "spawn"

@ give <who> <item> or give <item> to <who>
give player 3 diamond
give 16 bread to player

@ attacker
on entity damage:
    if attacker is set and victim is "villager":
        cancel event

@ %event.click_type%
on inventory click:
    if event.click_type is "SHIFT_LEFT":
        cancel event

@ %event.recipients%
on player chat:
    log "%player.name% wrote to: %event.recipients%"

@ %event.location%
on block break:
    spawn particle "flame" at event's location

@ permission: value
command /fly:
    permission: "server.fly"
    trigger:
        execute console command "fly %player.name%"

@ permission <who> remove <node>
permission player remove "server.fly"

@ delete line <n> of <who>'s scoreboard
delete line 3 of player's scoreboard

@ headers <text>, <text>, ...
async:
    send post request to "https://api.example.com/v1/events" with body "{\"type\":\"join\"}" headers "Authorization: Bearer abc123"

@ hide player count
on server ping:
    hide player count

@ set server icon to <path>
on server ping:
    set server icon to "plugins/HyperScript/icon.png"

@ set quit message to <text>
on player quit:
    set quit message to "&c- &f%player.name%"

@ hide join message / hide quit message
on player join:
    hide join message

@ set chat message to <text>
on player chat:
    if message contains "badword":
        set chat message to "(removed)"

// ---- Entries where the automatic match picked a line that shows something else ----

@ /
set _average to {player.total} / {player.games}

@ %
if {player.blocks} % 50 == 0:
    send "&bAnother 50 blocks mined!"

@ -
set _left to {player.coins} - 50

@ *
set _double to {player.coins} * 2

@ and, or, not
if {player.coins} >= 50 and not {global.shop_closed}:
    send "&aThe shop is open."

@ is / is not
if event.cause is "FALL":
    cancel event

@ <list> + <value>
set _everyone to server.players + "Console"

@ <text> + <text>
set _greeting to "Hello, " + player.name

@ send <text> to <player name>
send "&e%player.name% says hi!" to arg.1

@ wait <number> seconds
set _delay to 5
wait _delay seconds

@ file at <path> exists
if file at "plugins/HyperScript/notes.txt" exists:
    send read file at "plugins/HyperScript/notes.txt"

@ damage
on entity damage:
    if damage >= 10:
        send "&cThat hit hard!" to victim

@ block
on block break:
    if block is "diamond_ore":
        broadcast "&b%player.name% found diamonds!"

@ slot
on inventory click:
    if slot is 1:
        send "&7You clicked the first slot."

@ item
on right click:
    if item is "compass":
        send "&bYou are in %player.world%"

@ permission <who> add <node> / permission <who> remove <node>
permission player add "server.fly"
permission player remove "server.fly"

@ permission <who> add <node>
permission player add "server.fly"

@ sorted <list>
set _names to sorted server.players

@ reversed <list>
set _newest_first to reversed {global.winners}

@ x of <location>, y of <location>, z of <location>
set _height to y of player's location

@ world of <location>
send "Your home is in " + world of {player.home}

@ set y of <variable> to <number>
set {_loc} to player's location
add 10 to y of {_loc}
teleport player to {_loc}
