// 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 {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 {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 {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}

@ block at <position>
if block at player's location is "water":
    send "&bYou are standing in water."

@ send <text> to player
send "&aSaved." to player

@ send <text> to all players
send "&6The event starts in one minute!" to all players

@ remove <item> from <who>
if player has 5 diamond:
    remove 5 diamond from player

@ has <item>
if player has 5 diamond:
    send "&aYou can afford the upgrade."

@ does not have <item>
if player does not have 1 iron pickaxe:
    send "&cBring a pickaxe."

@ parse <text> as number
set {_amount} to parse arg.1 as number
if {_amount} is not set:
    send "&cThat is not a number."

@ parse <text> as integer
set {_whole} to parse "7.9" as integer

@ parse <value> as text
set {_label} to parse 52 as text

@ parse <text> as csv
set {_rows} to parse "diamond,120%nl%stick,0.5" as csv
send "&7%size of {_rows}% rows; the first costs %item 2 of item 1 of {_rows}%"

@ csv of file at <path>
set {_rows} to csv of file at "plugins/HyperScript/prices.csv"
if {_rows} is not set:
    send "&cThere is no prices.csv."
    stop
send "&7The first cell is %item 1 of item 1 of {_rows}%."

@ csv of file at <path> with headers
set {_rows} to csv of file at "plugins/HyperScript/prices.csv" with headers
for each {_row} in {_rows}:
    send "&e%{_row.item}% &7costs &f%{_row.price}%"

@ column <which> of <rows>
set {_rows} to csv of file at "plugins/HyperScript/prices.csv" with headers
set {_prices} to column "price" of {_rows}
send "&7Prices: %{_prices}%"

@ csv of <rows>
set {_rows} to [["player", "coins"], [player.name, {%player%.coins}]]
set file at "plugins/HyperScript/coins.csv" to csv of {_rows}

@ show text <text> in front of <who>
show text "&6Welcome!%nl%&7Have a look around" in front of player

@ show text <text> in front of <who> for <duration>
show text "&aSaved." in front of player for 3 seconds

@ show text <text> in front of <who> until <condition>
show text "&7Sneak to close this" in front of player until player is sneaking

@ show text <text> in front of <who> while <condition>
show text "&cYou are in the arena" in front of player while player is in region "arena"

@ show text <text> in front of <who> at distance <n>
show text "&eLook here" in front of player at distance 4 for 5 seconds

@ show text <text> in front of <who> locked
show text "&aSaved." in front of player locked for 3 seconds

@ hide text in front of <who>
hide text in front of player

@ parse <text> as time
set {_long} to parse arg.1 as time
if {_long} is not set:
    send "&cSay how long, such as 1h 30m."
    stop
send "&aMuted for %{_long}%."

@ return [<value>]
function double({_n}):
    return {_n} * 2

@ function <name>(<locals>):
function reward({_who}, {_amount}):
    add {_amount} to {%{_who}%.coins}
    return {%{_who}%.coins}

@ local function <name>(<locals>):
local function prefix():
    return "&7[&bShop&7] "

@ command
on player command:
    if command is "plugins":
        cancel event

@ amount
on item pickup:
    send "&7Picked up %event.amount% %event.item%"

@ %event.from%
on world change:
    send "&7You left %event.from% for %player.world%"

@ %hyperscript_<name>%
set {event_active} to true
# Any plugin that uses PlaceholderAPI can now show it:
# "Event running: %hyperscript_event_active%"

@ %hyperscript_player_<name>%
set {%player%.coins} to 100
# Any plugin that uses PlaceholderAPI can now show it to that player:
# "Coins: %hyperscript_player_coins%"

@ min(a, b, ...) / max(a, b, ...)
set {_level} to max(1, {%player%.level})
set {_cheapest} to min([30, 12, 45])

@ abs(n)
set {_apart} to abs(player.y - 64)

@ round(n)
set {_whole} to round(2.5)

@ floor(n) / ceil(n)
set {_pages} to ceil(size of {warps} / 9)

@ rounded up <n> / rounded down <n>
set {_minutes} to rounded up ({_seconds} / 60)

@ sqrt(n)
set {_side} to sqrt(25)

@ duration(seconds)
set {_left} to duration({%player%.ready} - server.time)
send "&cWait %{_left}%."

@ duration(<seconds>)
send "&7Uptime: " + duration(125)

@ distance between <a> and <b>
if distance between player's location and {spawn} > 100:
    send "&7You are far from spawn."

@ is banned / is not banned
if arg.1 is banned:
    send "&c%arg.1% is banned."

@ items <a> to <b> of <list>
set {_top} to items 1 to 5 of reversed sorted {scores}

@ index of <value> in <list>
set {_place} to index of player.name in {queue}

@ random item of <list>
send random item of ["Hello!", "Hi there!", "Welcome!"]

@ keys of {<table>}
for each {_name} in keys of {warp}:
    send "&7 - &b%{_name}%"

@ break / continue
for each {_name} in {queue}:
    if {_name} is "Steve":
        continue
    send "&7Next: %{_name}%"
    break

@ send <text> with click command <text>
send "&a[Go home]" with click command "/home"

@ send <text> with hover <text>
send "&e[?]" with hover "&7Hover text can explain things."

@ with click command <text>
send "&a[Accept]" with click command "/accept"

@ with click suggestion <text>
send "&7[Reply]" with click suggestion "/msg Alex "

@ with click url <text>
send "&b[Website]" with click url "https://example.com"

@ with hover <text>
send "&6Rules" with hover "&7Be kind.\n&7No griefing."

@ set helmet of <who> to <item>
set helmet of player to 1 diamond helmet enchanted with protection 4

@ clear inventory of <who>
clear inventory of player

@ helmet, chestplate, leggings, boots
set chestplate of player to 1 iron chestplate
delete boots of player

@ tool
if tool of player is not set:
    send "&7Your hand is empty."

@ offhand
set offhand of player to 1 shield

@ inventory slot <n>
set inventory slot 1 of player to 1 compass named "&bMenu"

@ kick, ban, unban
kick arg.1 because "&cPlease calm down."
ban arg.1 for 7 days because "&cGriefing"

@ kick <who> [because <text>]
kick arg.1 because "&cPlease calm down."

@ ban <who> [for <duration>] [because <text>]
ban arg.1 for 7 days because "&cGriefing"

@ unban <who>
unban arg.1

@ <who> is banned / is not banned
if arg.1 is not banned:
    send "&7%arg.1% is not banned."

@ refuse login [because <text>]
on player login:
    if {maintenance}:
        refuse login because "&eBack soon!"

@ add <who> to team <name>
add player to team "red"

@ remove <who> from team
remove player from team

@ remove <who> from team <name>
remove player from team "red"

@ set color of team <name> to <colour>
set color of team "red" to red

@ set prefix of team <name> to <text> / set suffix of team <name> to <text>
set prefix of team "red" to "&c[Red] "

@ set friendly fire of team <name> to <true or false>
set friendly fire of team "red" to false

@ delete team <name>
delete team "red"

@ team of <who>
if team of player is "red":
    send "&cGo red!"

@ players of team <name>
for each {_mate} in players of team "red":
    send "&cRed team, assemble!" to {_mate}

@ <on|off>, <red|blue|green>
command /event <on|off>:
    trigger:
        send "&7You chose %arg.1%."

@ <player> or <target>
command /greet <player>:
    trigger:
        send "&aHello from %player.name%!" to arg.1

@ %event.name%
on player login:
    log "%event.name% is connecting from %event.address%"

@ %event.uuid%
on player login:
    log "%event.name% has the id %event.uuid%"


@ %event.address%
on player login:
    log "%event.name% is connecting from %event.address%"

@ heal <who> / feed <who>
heal player
feed player

@ health of <who>
if health of player < 6:
    send "&cYou are badly hurt!"

@ max health of <who>
set max health of player to 40

@ food of <who>
set food of player to 20

@ level of <who>
add 5 to level of player

@ gamemode of <who>
set gamemode of player to creative

@ flight of <who>
set flight of player to true

@ apply <effect> [<level>] to <who> [for <duration>]
apply speed 2 to player for 30 seconds

@ clear effects of <who> / clear <effect> effect of <who>
clear effects of player
clear speed effect of player

@ ignite <who> [for <duration>] / extinguish <who>
ignite arg.1 for 3 seconds
extinguish player

@ freeze <who> / unfreeze <who>
freeze arg.1
send "&cYou have been frozen." to arg.1

@ vanish <who> / unvanish <who>
vanish player
send "&7Nobody can see you now."

@ <who> has effect <effect> / does not have effect <effect>
if player has effect speed:
    send "&bYou are fast."

@ has effect / does not have effect
if player does not have effect night vision:
    apply night vision to player for 5 minutes

@ <who> is frozen / is vanished / is flying
if arg.1 is frozen:
    send "&7%arg.1% is frozen."

@ is frozen / is vanished / is flying
if player is flying:
    send "&7Enjoy the view."

@ is tagged / is not tagged
if tool of player is tagged "wand":
    send "&dThe wand hums."

@ heal, feed, apply <effect>, freeze, vanish
heal player
apply regeneration 2 to player for 10 seconds

@ top <n> players by {<name>}
set {_place} to 0
for each {_name} in top 10 players by {coins}:
    add 1 to {_place}
    send "&e#%{_place}% &f%{_name}%"

@ rank of <who> by {<name>}
set {_mine} to rank of player by {coins}
send "&7You are #%{_mine}%"

@ gui page
open gui with title "&8Menu" with 1 rows for player:
    slot 5 is "paper" named "&fPage %gui page%"

@ page <n> of <list> with <k> per page
set {_shown} to page 2 of {names} with 9 per page

@ pages of <list> with <k> per page
set {_count} to pages of {names} with 9 per page

@ next page / previous page
open gui with title "&8Menu" with 1 rows for player:
    slot 1 is "arrow" named "&ePrevious":
        previous page
    slot 9 is "arrow" named "&eNext":
        next page

@ set gui page to <n>
open gui with title "&8Menu" with 1 rows for player:
    slot 5 is "compass" named "&eBack to the first page":
        set gui page to 1

@ refresh gui
open gui with title "&8Clicker" with 1 rows for player:
    slot 5 is "gold_ingot" named "&6Clicks: %{%player%.clicks}%":
        add 1 to {%player%.clicks}
        refresh gui

@ every day at <hh:mm>:
every day at 18:00:
    broadcast "&6The evening event starts now!"

@ every monday at <hh:mm>:
every monday at 00:00:
    delete {weekly_winner}

@ %event.region%
on region enter:
    send action bar "&7Entering &f%event.region%" to player

@ %event.opponent%
on combat start:
    send "&cYou are fighting %event.opponent%. Logging out now counts as a death."

@ teleport <who> to <location> after <duration>
teleport player to spawn of world "world" after 3 seconds

@ teleport <who> to <location> after <duration> unless they move
teleport player to spawn of world "world" after 5 seconds unless they move

@ send action bar <text> to <who> for <duration>
send action bar "&aSaved." to player for 5 seconds

@ send action bar <text> to <who> until <condition>
send action bar "&7Sneak to continue" to player until player is sneaking

@ send action bar <text> to <who> while <condition>
send action bar "&cIn combat" to player while player is in combat

@ set block at <position> to <block> for <duration>
set block at player to glass for 5 seconds

@ show floating text <text> at <position>
on entity damage:
    show floating text "&c-%event.damage%" at victim

@ show floating text <text> at <position> for <duration>
show floating text "&6+10 coins" at player for 2 seconds

@ point <who> to <location>
point player to spawn of world "world"

@ point <who> to <location> for <duration>
point player to {quest.chest} for 1 minute

@ point <who> to <location> until <condition>
point player to {quest.chest} until {%player%.quest} is "done"

@ stop pointing <who>
stop pointing player

@ make <entity> glow for <who>
on entity click:
    make event entity glow for player for 10 seconds

@ make <entity> stop glowing for <who>
on entity click:
    make event entity stop glowing for player

@ put <who> in combat
put player in combat for 30 seconds

@ take <who> out of combat
take player out of combat

@ <who> is in combat
command /spawn:
    trigger:
        if player is in combat:
            send "&cNot while you are fighting."
            stop
        teleport player to spawn of world "world" after 3 seconds unless they move

@ <who> is afk
for each {_name} in server.players:
    if {_name} is afk:
        send "&7%{_name}% is away."

@ short(n)
send "&7You have &6%short({%player%.coins})% &7coins."

@ bar of <part> out of <whole>
send action bar "&7XP " + bar of {%player%.xp} out of 100 to player

@ %event.streak%
on kill streak:
    if event.streak is 5:
        broadcast "&6%player.name% is on a killing spree!"

@ kill streak of <who>
send "&7Your streak: &c%kill streak of player%"

@ reset kill streak of <who>
reset kill streak of player

@ random safe location within <n> blocks of <location>
command /rtp:
    cooldown: 1 minute
    trigger:
        set {_place} to random safe location within 2000 blocks of spawn of world "world"
        if {_place} is not set:
            send "&cNo safe place was found. Try again."
            stop
        teleport player to {_place} after 3 seconds unless they move

@ mute <who>
mute arg.1

@ mute <who> for <duration>
mute arg.1 for 10 minutes

@ mute <who> because <reason>
mute arg.1 for 1 hour because "spamming"

@ unmute <who>
unmute arg.1

@ <who> is muted
if arg.1 is muted:
    send "&7%arg.1% is muted."

@ mute time left of <who>
set {_left} to mute time left of player
send "&7You can talk again in %{_left}%."

@ mute reason of <who>
set {_why} to mute reason of player
send "&7You were muted for: %{_why}%"

@ make <who> invulnerable
make player invulnerable

@ make <who> invulnerable for <duration>
on player respawn:
    make player invulnerable for 5 seconds

@ make <who> invulnerable until <condition>
make player invulnerable until player is not in region "spawn"

@ make <who> invulnerable while <condition>
make player invulnerable while player is in region "spawn"

@ make <who> vulnerable
make player vulnerable

@ unmake <who> invulnerable
unmake player invulnerable

@ <who> is invulnerable
if player is invulnerable:
    send "&7Nothing can hurt you right now."

@ start stopwatch <name>
start stopwatch "race"

@ stop stopwatch <name>
stop stopwatch "race"
set {_time} to stopwatch "race" of player
send "&aYou finished in %{_time}%."

@ reset stopwatch <name>
reset stopwatch "race"

@ stopwatch <name> of <who>
set {_time} to stopwatch "race" of player
send action bar "&e%{_time}%" to player

@ stopwatch <name> of <who> is running
if stopwatch "race" of player is running:
    send "&7You are in a race."

@ last location of <who>
command /back:
    trigger:
        set {_place} to last location of player
        if {_place} is not set:
            send "&cThere is nowhere to go back to."
            stop
        teleport player to {_place}

@ death location of <who>
set {_place} to death location of player
if {_place} is set:
    teleport player to {_place}

@ keep inventory
on player death:
    keep inventory

@ keep experience
on player death:
    keep experience

@ loop from 1 to 10: / loop from 10 to 0 by 2: / loop {_list}:
command /count:
    trigger:
        loop from 1 to 10:
            send "&7%loop-value%"
        loop from 10 to 0 by 2:
            send "&e%loop-value%"
        loop {queue}:
            send "&7%loop-index%. &f%loop-value%"

@ loop-value / loop-index
command /table:
    trigger:
        loop from 1 to 3:
            loop from 1 to 3:
                send "&7%loop-value-1% x %loop-value-2% = &f%loop-value-1 * loop-value-2%"

@ loop all players with permission "staff": / loop {_list} where ...:
command /helpme:
    trigger:
        loop all players with permission "staff.alerts":
            send "&c%player.name% needs help." to loop-player
        else:
            send "&7No staff are online."
        loop {queue} where loop-value is not player.name:
            send "&7%loop-index%. &f%loop-value%"

@ loop blocks within 3 blocks of player:
command /douse:
    trigger:
        loop blocks within 3 blocks of player:
            if block at loop-value is "fire":
                set block at loop-value to air

@ blocks within <n> blocks of <location>
command /stones:
    trigger:
        set {_n} to 0
        loop blocks within 4 blocks of player where block at loop-value is "stone":
            add 1 to {_n}
        send "&7Stone around you: &f%{_n}%"

@ blocks from <location> to <location>
command /floor:
    trigger:
        set {_a} to player's location offset by -2, -1, -2
        set {_b} to player's location offset by 2, -1, 2
        loop blocks from {_a} to {_b}:
            set block at loop-value to glass

@ items in inventory of <who>
command /carrying:
    trigger:
        loop items in inventory of player:
            send "&7%loop-index%. &f%loop-value%"
        else:
            send "&7You carry nothing."

@ stop if ... / continue if ... / break unless ...
command /buy:
    trigger:
        stop with "&cThat costs 100 coins." if {%player%.coins} < 100
        subtract 100 from {%player%.coins}
        loop all players:
            continue if loop-player is player.name
            send "&e%player.name% bought something." to loop-player

@ stop if <condition> / stop unless <condition>
command /vip:
    trigger:
        stop unless player has permission "vip.use"
        send "&6Welcome to the lounge."

@ stop with <text> [if <condition>]
command /heal:
    trigger:
        stop with "&cYou are in a fight." if player is in combat
        heal player

@ after 5 seconds:
command /bomb:
    trigger:
        send "&cFive seconds..."
        after 5 seconds:
            send "&4Boom."
        send "&7Run!"

@ after <duration>:
on player join:
    after 3 seconds:
        send "&aWelcome, %player.name%."

@ wait between <duration> and <duration>
command /fish:
    trigger:
        send "&7You cast the line..."
        wait between 2 and 6 seconds
        send "&bA bite!"

@ multiply <variable> by <value> / divide <variable> by <value>
command /double:
    trigger:
        multiply {%player%.coins} by 2
        send "&aDoubled: &f%{%player%.coins}%"

@ send <text> to all players with permission <node>
command /staffchat <words:text>:
    trigger:
        send "&d[Staff] %player.name%: &f%arg.1%" to all players with permission "staff.chat"

@ plural(n, word)
command /homes:
    trigger:
        set {_n} to size of {%player%.homes}
        set {_said} to plural({_n}, "home")
        send "&7You have &f%{_said}%&7."

@ on <event>, <event>:
on player join, player respawn:
    give 1 bread to player
    send "&7Here is something to eat."

@ amount of <item> in inventory of <who>
command /diamonds:
    trigger:
        set {_n} to amount of diamond in inventory of player
        send "&bYou carry &f%{_n}% &bdiamonds."

@ any of <list> <condition>
command /anyrich:
    trigger:
        set {_coins} to [5, 250, 40]
        if any of {_coins} is above 100:
            send "&6Somebody is rich."

@ all of <list> <condition>
command /ready:
    trigger:
        set {_marks} to [3, 4, 5]
        if all of {_marks} are above 2:
            send "&aEverybody passed."

@ set <variable>, <variable> to <value>
command /resetgame:
    trigger:
        set {game.red}, {game.blue} to 0
        send "&7Scores reset."

@ set <variable> to <value> for <duration>
command /boost:
    trigger:
        set {%player%.boost} to 2 for 10 minutes
        send "&aDouble coins for ten minutes."

@ add <n>% to <variable> / subtract <n>% from <variable>
command /sale:
    trigger:
        set {_price} to 200
        subtract 25% from {_price}
        send "&eToday only: &f%{_price}% coins"

@ return if <condition> / return unless <condition>
function pay({_who}, {_amount}):
    return if {_amount} < 1
    add {_amount} to {%{_who}%.coins}

@ [name:type = value]
command /coins [amount:number = 1]:
    trigger:
        add arg.1 to {%player%.coins}
        send "&a+%arg.1% coins"

@ on <event> of <kind>:
on block break of diamond ore:
    add 1 to {%player%.diamonds}
    send "&bDiamonds found: &f%{%player%.diamonds}%"

@ on chat containing <text>:
on chat containing "discord":
    send "&9Our Discord: &fdiscord.gg/example"

@ randomly: with 70%:, 30%:
command /crate:
    trigger:
        randomly:
            70%:
                give 1 bread to player
            25%:
                give 1 diamond to player
            otherwise:
                give 1 gold block to player

@ random <n> of <list>
command /pickthree:
    trigger:
        set {_lucky} to random 3 of server.players
        send "&6Winners: &f%{_lucky}%" to all players

@ <list> sorted by <value>
command /longest:
    trigger:
        set {_words} to ["banana", "kiwi", "apple"]
        set {_ordered} to {_words} sorted by length of loop-value highest first
        send "&7%{_ordered}%"

@ <text> shortened to <n>
command /tag <words:text>:
    trigger:
        set {_tag} to arg.1 shortened to 12
        send "&7Your tag: &f%{_tag}%"

@ <text> wrapped to <n>
command /about:
    trigger:
        set {_about} to "&7A sword that was made long ago and has never lost a fight."
        loop {_about} wrapped to 24:
            send loop-value

@ save state of <who> as <name>
command /joinarena:
    trigger:
        save state of player as "before-arena"
        clear inventory of player
        give 1 iron sword to player

@ restore state of <who> from <name>
command /leavearena:
    trigger:
        restore state of player from "before-arena"
        send "&7Everything is as it was."

@ <name:duration>
command /slow <target:player> <time:duration>:
    permission: "staff.slow"
    trigger:
        set {%arg.1%.slowed} to true for arg.2
        send "&7%arg.1% is slowed."

@ <name:boolean>
command /pvp <on:boolean>:
    permission: "staff.pvp"
    trigger:
        set {pvp} to arg.1
        send "&7PvP: &f%arg.1%"

@ <name:item>
command /gimme <what:item>:
    permission: "staff.gimme"
    trigger:
        send "&7You asked for &f%arg.1%&7."

@ <name:world>
command /daytime <where:world>:
    permission: "staff.time"
    trigger:
        set time in world arg.1 to 1000

@ <name:offline player>
command /seen <who:offline player>:
    trigger:
        send "&7%arg.1% was last on &f%last seen of arg.1%"

@ <name:text>
command /announce <words:text>:
    permission: "staff.announce"
    trigger:
        send "&6[!] &f%arg.1%" to all players

@ <on|off>
command /fly <on|off>:
    permission: "fly.use"
    trigger:
        send "&7Flying: &f%arg.1%"

@ for <n> seconds counting down
command /round:
    trigger:
        create bossbar "round" titled "&cRound ends" for all players for 30 seconds counting down

@ on unload:
on load:
    create bossbar "event" titled "&6Double coins weekend" for all players

on unload:
    remove bossbar "event"

@ closest match of <text> in <list>
command /kit <name>:
    trigger:
        set {_kits} to ["starter", "miner", "builder"]
        if {_kits} contains arg.1:
            send "&aHere is your %arg.1% kit."
            stop
        set {_meant} to closest match of arg.1 in {_kits}
        if {_meant} is set:
            send "&cThere is no kit %arg.1%. Did you mean &f%{_meant}%&c?"

@ <list> as sentence
command /who:
    trigger:
        set {_names} to server.players as sentence
        send "&7Online: &f%{_names}%"

@ nearest block of <type> within <n> blocks of <location>
command /findore:
    trigger:
        set {_ore} to nearest block of diamond ore within 12 blocks of player
        if {_ore} is set:
            send "&bDiamonds at &f%{_ore}%"
        else:
            send "&7Nothing close by."

@ send <text> with click copy <text>
command /ip:
    trigger:
        send "&b[Click to copy the address]" with click copy "play.example.net"

@ send <text> to <who> when they join
command /thank <who:offline player>:
    trigger:
        send "&a%player.name% says thank you!" to arg.1 when they join
        send "&7They will be told."

@ warmup:
command /spawn:
    warmup: 3 seconds
    trigger:
        teleport player to {spawn}

@ cost:
command /heal:
    cost: 50
    trigger:
        heal player
        send "&aHealed."

@ cost message:
command /feed:
    cost: 20
    cost message: "&cFood costs %cost% coins."
    trigger:
        feed player

@ permission <who> add <node> for <duration>
command /trialfly:
    trigger:
        permission player add "server.fly" for 1 hour
        send "&aYou can fly for an hour."

@ ask <who> <text> as number into <variable>
command /deposit:
    trigger:
        ask player "&eHow much?" as number into {_amount}
        if {_amount} is set:
            add {_amount} to {%player%.bank}

@ fill empty slots with <item>
command /menu:
    trigger:
        open gui with title "&8Menu" with 3 rows for player:
            fill empty slots with "gray_stained_glass_pane"
            slot 14 is "diamond" named "&bShop":
                send "&7The shop is not open yet."

@ border with <item>
command /framed:
    trigger:
        open gui with title "&8Kits" with 3 rows for player:
            border with "black_stained_glass_pane"
            slot 14 is "iron_sword" named "&fStarter"

@ on close:
command /bank:
    trigger:
        open gui with title "&6Bank" for player:
            slot 5 is "gold_ingot" named "&eYour coins: %{%player%.coins}%"
            on close:
                send "&7Come again."

@ refresh every <duration>
command /clock:
    trigger:
        open gui with title "&8Clock" for player:
            refresh every 1 second
            slot 5 is "clock" named "&f%server.time%"

@ set name of <place> to <text>
command /rename <words:text>:
    trigger:
        set name of tool of player to arg.1
        send "&aRenamed."

@ set lore of <place> to <text>, <text>
command /describe:
    trigger:
        set lore of tool of player to "&7Forged in the deep", "&7Owner: %player.name%"

@ add <text> to lore of <place>
command /bind:
    trigger:
        add "&cSoulbound" to lore of tool of player

@ remove line <n> of lore of <place>
command /unline:
    trigger:
        remove line 1 of lore of tool of player

@ delete lore of <place>
command /plain:
    trigger:
        delete lore of tool of player

@ delete <variable> for all players
command /newseason:
    permission: "staff.season"
    trigger:
        delete {coins} for all players
        send "&eA new season begins." to all players

@ set <variable> to <value> for all players
command /gift:
    permission: "staff.gift"
    trigger:
        set {tokens} to 5 for all players

@ delete all variables of <who>
command /wipe <who:offline player>:
    permission: "staff.wipe"
    trigger:
        delete all variables of arg.1
        send "&7Everything of %arg.1% is gone."

@ send <list> to <who> in pages of <n>
command /warps:
    trigger:
        set {_names} to keys of {warp}
        send {_names} to player in pages of 8 titled "&6Warps"

@ set chat slow mode to <duration>
command /slow <time:duration>:
    permission: "staff.slow"
    trigger:
        set chat slow mode to arg.1
        send "&eChat is slowed down." to all players

@ slot <n> takes items:
command /sell:
    trigger:
        open gui with title "&8Sell diamonds" with 3 rows for player:
            fill empty slots with "gray_stained_glass_pane"
            slot 14 takes items shown as "hopper" named "&ePut diamonds here":
                if type of {_item} is "diamond":
                    add amount of {_item} * 10 to {%player%.coins}
                    send "&aSold for %amount of {_item} * 10% coins."
                else:
                    give {_item} to player
                    send "&cOnly diamonds are bought here."

@ cooldown of command <name>
command /kitstatus:
    trigger:
        set {_left} to cooldown of command "/kit"
        if {_left} is set:
            send "&7Your kit is ready in &f%{_left}%"
        else:
            send "&aYour kit is ready."

@ yaml value <key> of file at <path>
command /shopprice:
    trigger:
        set {_price} to yaml value "prices.diamond" of file at "plugins/HyperScript/shop.yml"
        send "&7A diamond costs &f%{_price}%"

@ quest "<name>":
quest "lumberjack":
    goal: break 20 oak log
    reward:
        give 10 bread to player

@ goal: break <n> <block>
quest "builder":
    goal: place 100 stone
    reward:
        send "&aA hundred stones placed."

@ goal: do <n>
quest "helper":
    goal: do 3
    reward:
        send "&aYou helped three times."

command /helped <target:player>:
    permission: "staff.helped"
    trigger:
        advance quest "helper" for arg.1

@ reward:
quest "hunter":
    goal: kill 5 zombie
    reward:
        give 1 iron sword to player
        send "&aFive zombies down."

@ start quest <name>
quest "digger":
    goal: break 10 stone

command /dig:
    trigger:
        start quest "digger"
        send "&eBreak ten stone."

@ stop quest <name>
quest "runner":
    goal: do 5

command /giveup:
    trigger:
        stop quest "runner"
        send "&7Quest dropped."

@ advance quest <name>
quest "talker":
    goal: do 2

command /talk:
    trigger:
        advance quest "talker"

@ quest progress <name>
quest "stonecutter":
    goal: break 30 stone

command /progress:
    trigger:
        set {_done} to quest progress "stonecutter"
        send "&7%{_done}% of 30"

@ quest goal <name>
quest "baker":
    goal: do 12

command /bakergoal:
    trigger:
        set {_loaves} to quest goal "baker"
        send "&7Bake %{_loaves}% loaves."

@ quest state <name>
quest "guard":
    goal: kill 3 zombie

command /guardquest:
    trigger:
        if quest state "guard" is "none":
            start quest "guard"

@ all quests
command /quests:
    trigger:
        send "&7Quests: &f%all quests%"

@ on quest complete "<name>":
quest "finisher":
    goal: do 1

on quest complete "finisher":
    broadcast "&6%player.name% finished a quest!"

@ slots <a> to <b> are <item>
command /frame:
    trigger:
        open gui with title "&8Kits" with 3 rows for player:
            slots 1 to 9 are "black_stained_glass_pane" named " "
            slots 11, 13, 15 are "iron_sword" named "&fStarter":
                send "&aYou picked a kit."

@ textured <value>
command /globe:
    trigger:
        give 1 player head textured "b1dd4fe4a429abd665dfdb3e21321d6efa6a6b5e7b956db9c5d59c9efab25" named "&bGlobe" to player

@ worlds:
command /mine:
    worlds: "survival", "resource"
    trigger:
        give 1 iron pickaxe to player

@ worlds message:
command /arena:
    worlds: "minigames"
    worlds message: "&cThe arena is in the minigames world."
    trigger:
        send "&aWelcome to the arena."

@ worlds: <name>, <name>
on block break:
    worlds: "survival", "resource"
    add 1 to {%player%.mined}

@ permission: <node>
on player join:
    permission: "vip.perks"
    send "&6Welcome back, VIP."

@ update scoreboard of <who> every <duration>:
on player join:
    set title of player's scoreboard to "&e&lMy server"
    update scoreboard of player every 2 seconds:
        set line 1 of player's scoreboard to "&7Coins: &f%{%player%.coins}%"
        set line 2 of player's scoreboard to "&7Online: &f%server.online_players%"

@ stop updating scoreboard of <who>
command /quiet:
    trigger:
        stop updating scoreboard of player
        send "&7Your sidebar is no longer kept up to date."

@ goal: craft <n> <item>
quest "breadmaker":
    goal: craft 8 bread
    reward:
        send "&aEight loaves baked."

@ goal: fish <n>
quest "fisher":
    goal: fish 5
    reward:
        give 1 diamond to player

@ goal: walk <n> blocks
quest "walker":
    goal: walk 500 blocks
    reward:
        send "&aHalf a kilometre on foot."

@ goal: reach <n> {<variable>}
quest "rich":
    goal: reach 1000 {coins}
    reward:
        broadcast "&6%player.name% has a thousand coins!"

@ repeat: daily
quest "daily miner":
    goal: break 20 stone
    repeat: daily
    reward:
        add 50 to {%player%.coins}

@ time limit: <duration>
quest "sprint":
    goal: walk 200 blocks
    time limit: 1 minute
    reward:
        send "&aFast enough!"

@ active quests
command /myquests:
    trigger:
        set {_mine} to active quests
        send "&7Your quests: &f%{_mine}%"

@ on quest progress "<name>":
quest "collector":
    goal: break 10 stone

on quest progress "collector":
    send action bar "&7Stone: &f%{_progress}% &7of %{_goal}%" to player

@ set <variable> to <block name>
command /rainbow:
    trigger:
        set {_block1} to Red concrete
        set {_block2} to Orange concrete
        set {_block3} to Yellow concrete
        set {_spot} to player's location
        set block at {_spot} to {_block1}
        wait 1 second
        set block at {_spot} to {_block2}
        wait 1 second
        set block at {_spot} to {_block3}

@ firework
command /party:
    trigger:
        give 3 firework to player
        send "&dLight them up!"

@ countdown <duration>:
countdown 5 seconds:
    send title "&e%seconds left%" to player
send title "&aGo!" to player

@ seconds left
countdown 10 seconds:
    if seconds left <= 3:
        play sound "block.note_block.pling" to player

@ once for <who>:
on player join:
    once for player:
        send "&6Welcome! &7Type /help to get started."

@ once per day for <who>:
command /daily:
    trigger:
        once per day for player:
            add 100 to {%player%.coins}
            send "&a+100 coins."
        else:
            send "&7You have had today's reward."

@ once <name> for <who>:
once "starter kit" for player:
    give 1 stone sword to player

@ once:
on load:
    once:
        log "This server ran HyperScript for the first time."

@ money(n)
send "&7Balance: &a%money({%player%.coins})%"

@ spawn particle <name> at <position> visible to <who>
spawn particle "heart" at player visible to player

@ spawn particle <name> with speed <n> at <position>
spawn particle "flame" count 20 with speed 0.1 at player

@ spawn particle <name> spread <x>, <y>, <z> at <position>
spawn particle "cloud" count 30 spread 2, 0.2, 2 at player

@ spawn particle <name> of <block or item> at <position>
on block break:
    spawn particle "block" of stone count 30 at player

@ spawn particle "dust" colored <colour> fading to <colour> at <position>
spawn particle "dust" colored "#ff0000" fading to "#000000" count 20 at player

@ draw particle <shape> ... for <duration>
draw particle circle with radius 2 using particle "flame" at player for 10 seconds

@ draw particle <shape> ... until <condition>
draw particle circle with radius 2 using particle "flame" at player until player is sneaking

@ draw particle <shape> ... while <condition>
draw particle sphere with radius 2 using particle "dust" colored "#55ffff" around player while player is in region "arena"

@ draw particle <shape> ... around <who>
draw particle circle with radius 1 using particle "dust" colored "#ff66cc" around player for 30 seconds

@ draw particle <shape> ... visible to <who>
draw particle sphere with radius 1 using particle "end_rod" at {quest.chest} visible to player for 1 minute

@ draw particle <shape> ... colored <colour> to <colour>
draw particle circle with radius 3 using particle "dust" colored "#ff0000" to "#0000ff" at player

@ draw particle <shape> ... spinning
draw particle star with radius 2 using particle "flame" at player spinning for 5 seconds

@ draw particle <shape> ... growing to radius <r> over <duration>
draw particle circle with radius 0.5 using particle "cloud" at player growing to radius 6 over 1 second

@ draw particle <shape> ... rising <n> blocks over <duration>
draw particle spiral with radius 1.5 using particle "end_rod" at player rising 3 blocks over 2 seconds

@ draw particle box from <position> to <position> using particle <name>
draw particle box from 0, 60, 0 to 10, 70, 10 using particle "flame" for 10 seconds

@ draw particle outline of region <name> using particle <name>
draw particle outline of region "spawn" using particle "end_rod" visible to player for 10 seconds

@ draw particle helix with radius <r> and height <h> using particle <name> at <position>
draw particle helix with radius 1 and height 3 using particle "flame" around player for 5 seconds

@ draw particle spiral with radius <r> using particle <name> at <position>
draw particle spiral with radius 3 using particle "end_rod" at player

@ draw particle star with radius <r> using particle <name> at <position>
draw particle star with radius 2 using particle "flame" at player

@ draw particle heart with size <n> using particle <name> at <position>
draw particle heart with size 2 using particle "dust" colored "#ff3366" at player for 3 seconds

@ draw particle beam from <position> to <position> using particle <name>
draw particle beam from player to {_target} using particle "end_rod" over 1 second

@ draw particle text <text> using particle <name> at <position>
draw particle text "GG" using particle "dust" colored "#ffaa00" at player for 3 seconds

@ box
draw particle box from 0, 60, 0 to 10, 70, 10 using particle "flame" for 10 seconds

@ spiral
draw particle spiral with radius 3 using particle "end_rod" at player

@ star
draw particle star with radius 2 using particle "flame" at player spinning for 5 seconds

@ heart
draw particle heart with size 2 using particle "dust" colored "#ff3366" at player for 3 seconds

@ beam
draw particle beam from player to 0, 80, 0 using particle "end_rod" over 1 second

@ around <who> (in place of at <position>)
draw particle circle with radius 1 using particle "flame" around player for 30 seconds

@ fading to "<#rrggbb>"
spawn particle "dust" colored "#ff0000" fading to "#000000" count 20 at player

@ spread <n> or spread <x>, <y>, <z>
spawn particle "cloud" count 30 spread 2, 0.2, 2 at player

@ give <who> a trail of <particle>
give player a trail of "flame"

@ give <who> a trail of <particle> for <duration>
give player a trail of "dust" colored "#ff66cc" for 30 seconds

@ remove trail of <who>
remove trail of player

@ play particle effect <name> at <position>
particle effect "level up":
    draw particle helix with radius 1 and height 2 using particle "end_rod" at effect location rising 1 blocks over 1 second
    draw particle circle with radius 0.5 using particle "flame" at effect location growing to radius 3 over 1 second

on level up:
    play particle effect "level up" at player

@ kit <name>:
kit "starter":
    cooldown: 1 day
    items:
        1 stone sword
        16 bread

command /kit:
    trigger:
        claim kit "starter"

@ items:
kit "miner":
    cooldown: 6 hours
    items:
        1 iron pickaxe
        16 bread
        3 diamond

@ once: true
kit "founder":
    once: true
    permission: "kit.founder"
    items:
        1 diamond sword named "&6Founder's blade"

command /founder:
    trigger:
        claim kit "founder"

@ claim kit <name>
kit "tools":
    cooldown: 1 hour
    items:
        1 iron pickaxe

command /tools:
    trigger:
        claim kit "tools"

@ give kit <name> to <who>
kit "welcome":
    items:
        3 diamond

on first join:
    give kit "welcome" to player

@ <who> can claim kit <name>
kit "daily":
    cooldown: 1 day
    items:
        3 diamond

command /daily:
    trigger:
        if player can claim kit "daily":
            claim kit "daily"
            send "&aSee you tomorrow."
        else:
            set {_wait} to cooldown of kit "daily"
            send "&7Come back in %{_wait}%."

@ cooldown of kit <name>
kit "daily":
    cooldown: 1 day
    items:
        3 diamond

command /when:
    trigger:
        set {_wait} to cooldown of kit "daily"
        if {_wait} is set:
            send "&7In %{_wait}%."
        else:
            send "&aNow."

@ reset kit <name>
kit "daily":
    cooldown: 1 day
    items:
        3 diamond

command /resetdaily <target:player>:
    permission: op
    trigger:
        reset kit "daily" for arg.1

@ kits
kit "starter":
    items:
        1 stone sword

command /kits:
    trigger:
        send "&7Kits: &f%kits%"

@ lerp(a, b, t)
set {_colour} to lerp("#ff0000", "#00ff00", player.health / 20)
spawn particle "dust" colored {_colour} count 10 at player

@ mix(a, b)
set {_purple} to mix("#ff0000", "#0000ff")

@ lighten(colour, amount)
set {_pale} to lighten("#336699", 0.5)

@ darken(colour, amount)
set {_deep} to darken("#336699", 0.5)

@ rainbow(t)
every 2 ticks for all players:
    add 0.02 to {_turn}
    spawn particle "dust" colored rainbow(server.time / 5) at player

@ rgb(red, green, blue)
set {_orange} to rgb(255, 136, 0)

@ %event.word%
on blocked word:
    log "%player.name% wrote the blocked word %event.word%"

@ statistic <name> of <who>
set {_deaths} to statistic "deaths" of player
send "&7You have died &c%{_deaths}% &7times."

@ statistic <name> of <who> for <thing>
set {_stone} to statistic "mine_block" of player for "stone"
send "&7Stone mined: &f%{_stone}%"

@ all commands
send "&7This server has %size of all commands% commands."

@ commands of <who>
set {_mine} to commands of player
send "&7You can use %size of {_mine}% commands."

@ all permissions of <who>
for each {_node} in all permissions of player:
    send "&7- %{_node}%"

@ give selection wand to <who>
give selection wand to player

@ selection start of <who>
command /makearena <name>:
    permission: op
    trigger:
        if selection size of player is not set:
            send "&cMark two corners with the wand first."
            stop
        create region arg.1 from selection start of player to selection end of player
        send "&aMade %arg.1%."

@ selection end of <who>
set {_far} to selection end of player

@ selection size of <who>
send "&7You marked %selection size of player% blocks."

@ clear selection of <who>
clear selection of player

@ save structure <name> from <position> to <position>
save structure "house" from selection start of player to selection end of player

@ place structure <name> at <position>
place structure "house" at player

@ place structure <name> at <position> rotated <degrees>
place structure "house" at player rotated 90

@ structure <name> exists
if structure "house" exists:
    place structure "house" at player

@ delete structure <name>
delete structure "house"

@ block word <text>
block word "badword"

@ unblock word <text>
unblock word "badword"

@ blocked words
send "&7Blocked: %blocked words%"

@ dialogue <name>:
dialogue "blacksmith":
    send "&6Blacksmith: &fWhat do you need?"
    choice "A sword":
        give 1 iron sword to player
        send "&6Blacksmith: &fHere you go."
    choice "Nothing":
        send "&6Blacksmith: &7Come back any time."

command /blacksmith:
    trigger:
        start dialogue "blacksmith"

@ choice <text>:
command /pick:
    trigger:
        send "&7Which team?"
        choice "&cRed":
            set {%player%.team} to "red"
        choice "&9Blue":
            set {%player%.team} to "blue"
        send "&aYou are on team %{%player%.team}%."

@ start dialogue <name>
dialogue "guide":
    send "&bGuide: &fWelcome to the server."

on first join:
    start dialogue "guide"

@ brewing recipe for <item>:
brewing recipe for 1 gold block:
    from: stone
    with: diamond

@ sin(angle), cos(angle), tan(angle)
set {_x} to cos(45) * 3
set {_z} to sin(45) * 3
spawn particle "flame" at player's location offset by {_x}, 1, {_z}

@ asin(n), acos(n), atan(n)
set {_angle} to atan(1)
send "&7That slope is %{_angle}% degrees."

@ sin(angle)
set {_x} to cos(45) * 3
set {_z} to sin(45) * 3
spawn particle "flame" at player's location offset by {_x}, 1, {_z}

@ cos(angle)
set {_x} to cos(90) * 2

@ tan(angle)
set {_slope} to tan(30)

@ asin(n)
set {_angle} to asin(0.5)

@ acos(n)
set {_angle} to acos(0.5)

@ atan(n)
set {_angle} to atan(1)

@ atan2(up, along)
set {_angle} to atan2(1, 1)

@ yaw from <location> to <location>
set {_way} to yaw from player's location to {spawn}
set player's yaw to {_way}

@ pitch from <location> to <location>
set {_tilt} to pitch from player's location to {spawn}
set player's pitch to {_tilt}

@ <location> moved <n> blocks towards <location>
set {_step} to player's location moved 3 blocks towards {spawn}
teleport player to {_step}

@ random text of <n> characters
set {_code} to random text of 8 characters
send "&7Your voucher: &f%{_code}%"

@ random code of <n> digits
set {_pin} to random code of 4 digits

@ new id
set {_id} to new id

@ <date> formatted as <pattern> in time zone <zone>
set {_berlin} to now formatted as "HH:mm" in time zone "Europe/Berlin"
send "&7In Berlin it is %{_berlin}%."

@ %event.lines%
on sign change:
    log "%player.name% wrote: %event.lines%"

@ %event.clicked%
on entity click:
    send "&7You clicked &f%event.clicked%"

@ %event.level%, %event.old_level%
on level up:
    send "&aLevel %event.old_level% -> %event.level%"

@ starts with / ends with
on player chat:
    if message starts with "!":
        cancel event
        send "&7Commands start with / here."

@ matches
if not (arg.1 matches "[a-zA-Z0-9_]{3,16}"):
    send "&cThat is not a valid name."

@ chance of <n>%
on block break:
    if chance of 5%:
        give 1 diamond to player
        send "&bLucky find!"

@ random player
set {_winner} to random player
broadcast "&6%{_winner}% wins the draw!"

@ shuffled <list>
set {_order} to shuffled server.players

@ unique <list>
set {_once} to unique ["a", "b", "a"]

@ sum of <list> / average of <list>
set {_total} to sum of [10, 20, 30]
set {_mean} to average of [10, 20, 30]

@ players within <n> blocks of <location>
for each {_near} in players within 10 blocks of player:
    send "&7%player.name% waves at you." to {_near}

@ <text> parsed as number
set {_amount} to arg.1 parsed as number
if {_amount} is not set:
    send "&cThat is not a number."

@ now formatted as <pattern>
send "&7It is " + now formatted as "HH:mm"

@ %server.date%
log "Backup finished on %server.date% at %server.clock%"

@ %server.clock%
send "&7Server time: &f%server.clock%"

@ %server.weekday%
if server.weekday is "saturday":
    send "&6Double coins today!"

@ %server.hour%, %server.minute%
if server.hour >= 22:
    send "&7It is late. Good night!"

@ options:
options:
    prefix: "&8[&6Shop&8] "
command /shop:
    trigger:
        send "{@prefix}&7Welcome."

@ command /name:
command /hello:
    trigger:
        send "&aHello!"

@ on <event>:
on player join:
    send "&aWelcome!"

@ on load:
on load:
    if {motd} is not set:
        set {motd} to "&aWelcome!"

@ every <time>:
every 5 minutes:
    broadcast "&7Remember to vote!"

@ function name():
function greet():
    send "&aHello!"

@ # Requires: 1.5.9
# Requires: 1.5.9
on player join:
    send "&aWelcome!"

@ # Tags: chat, welcome
# Tags: chat, welcome
on player join:
    send "&aWelcome!"

@ on server start:
on server start:
    log "The server is up. %server.online_players% player(s) online."

@ on server stop:
on server stop:
    set {last_shutdown} to now

@ %server.worlds%
for each {_world} in server.worlds:
    send "&7 - &f%{_world}%"

@ %server.operators%, %server.banned%, %server.whitelist%
send "&7Operators: &f%server.operators%"

@ %server.plugins%
send "&7Plugins: &f%server.plugins%"

@ %server.uptime%
send "&7The server has been up for &f%server.uptime%"

@ %server.memory_used%, %server.memory_max%
send "&7Memory: &f%server.memory_used% &7of &f%server.memory_max% &7MB"

@ pow(a, b)
set {_cost} to 100 * pow(2, {%player%.upgrades})

@ round(n, places)
set {_ratio} to round({%player%.kills} / max(1, {%player%.deaths}), 2)

@ percent(part, whole)
set {_done} to percent({%player%.quests_done}, 20)
send "&7Quests: &f%{_done}%%"

@ commas(n)
set {_shown} to commas({%player%.coins})
send "&6Balance: &e%{_shown}% coins"

@ ordinal(n)
set {_place} to ordinal(rank of player by {coins})
send "&7You are in &f%{_place}% &7place."

@ roman(n)
set {_level} to roman({%player%.prestige})
send "&dPrestige %{_level}%"

@ today / tomorrow
if {%player%.last_vote} < today:
    send "&eYou have not voted today."

@ time since <date>
set {_ago} to time since {%player%.last_death}
send "&7You last died %{_ago}% ago."

@ first join date of <who> / last seen of <who>
set {_seen} to last seen of arg.1
send "&7%arg.1% was last on: &f%{_seen}%"

@ is between <a> and <b>
if player.y is between 0 and 16:
    send "&bDiamond level!"

@ is in <list>
if arg.1 is in ["on", "off"]:
    send "&aOK."

@ is empty
if {queue} is empty:
    send "&7Nobody is waiting."

@ is a list / a location / an item / a date / an entity / a table / text
if {%player%.home} is a location:
    teleport player to {%player%.home}

@ is a player
if arg.1 is not a player:
    send "&c%arg.1% is not online."

@ is alphanumeric
if arg.1 is not alphanumeric:
    send "&cUse letters and digits only."

@ is sneaking / sprinting / swimming / blocking / sleeping / on ground / in water
on right click:
    if player is sneaking:
        send "&7A sneaky click."

@ is op / is online
if arg.1 is online:
    send "&a%arg.1% is here."

@ has played before
if arg.1 has played before:
    send "&7%arg.1% has been here."

@ is holding <item> / is wearing <item>
if player is holding diamond sword:
    send "&bNice sword."

@ can see <player>
if player can see arg.1:
    send "&7You can see %arg.1%."

@ <world> is raining / is day / is night
if player.world is night:
    send "&7It is dark. Watch out."

@ <block> is solid
if block at (location below player's location) is solid:
    send "&7You are on firm ground."

@ numbers from <a> to <b>
for each {_n} in numbers from 3 to 1:
    send "&e%{_n}%..."

@ count of <value> in <list>
set {_votes} to count of "yes" in {votes}

@ min of <list> / max of <list>
set {_best} to max of {scores}

@ capitalized <text>
send capitalized "hello there"

@ title case <text>
set {_nice} to title case "diamond_sword"
send "&7You found a %{_nice}%"

@ uncoloured <text>
log uncoloured "&aGreen text"

@ word <n> of <text>
set {_first} to word 1 of args

@ <text> repeated <n> times
send "&8" + ("-" repeated 20 times)

@ run <function>(...) in <duration>
function remind({_who}):
    send "&eTime is up!" to {_who}
command /timer:
    trigger:
        run remind(player.name) in 30 seconds

@ console only: true
command /maintenance:
    console only: true
    trigger:
        set {maintenance} to true

@ <name:player>
command /greet <target:player>:
    trigger:
        send "&aHello!" to arg.1

@ <name:number>
command /setprice <price:number>:
    trigger:
        set {price} to arg.1

@ <name:integer>
command /roll <sides:integer>:
    trigger:
        send "&7You rolled " + random integer between 1 and arg.1

@ [name:type]
command /heal [target:player]:
    trigger:
        if arg.1 is set:
            heal arg.1
        else:
            heal player

@ strike lightning at <location>
strike lightning at player's location

@ create explosion at <location> [with power <n>]
create explosion at player's location with power 3 without breaking blocks

@ fill from <location> to <location> with <block>
fill from 0, 64, 0 in "world" to 4, 64, 4 in "world" with stone

@ break block at <location>
break block at location below player's location

@ break block at <location> without particles
set {_loc} to location below player's location
break block at {_loc} without particles

@ break block at <location> over <duration>
set {_loc} to location below player's location
break block at {_loc} over 5 seconds
send "&7The floor will not hold much longer."

@ break block at <location> without drops
set {_loc} to location below player's location
break block at {_loc} without drops

@ place <block> at <position>
set {_loc} to location below player's location
place gold block at {_loc}

@ block data at <position>
command /turnback:
    trigger:
        set {_loc} to location below player's location
        set {_data} to block data at {_loc}
        set block at {_loc} to air
        wait 3 seconds
        set block at {_loc} to {_data}

@ <block> is liquid
if block at player's location is liquid:
    send "&bYou are swimming."

@ <block> is passable
if block at (location below player's location) is passable:
    send "&7There is nothing under your feet."

@ <block> is air
if block at (location above player's location) is air:
    send "&7Nothing above you."

@ fill from <location> to <location> with <block> replacing <block>
fill from {arena.a} to {arena.b} with air replacing stone

@ fill from <location> to <location> with <block> hollow
fill from {room.a} to {room.b} with glass hollow

@ break blocks from <location> to <location>
break blocks from {wall.a} to {wall.b} over 3 seconds without drops

@ show cracks <n> on block at <location>
set {_loc} to location below player's location
show cracks 7 on block at {_loc}

@ clear cracks on block at <location>
set {_loc} to location below player's location
clear cracks on block at {_loc}

@ drop block <block> at <location>
drop block sand at location above player's location

@ push <who> away from <location> [with force <n>]
push player away from {boss.place} with force 1.5

@ push <who> left / right [with force <n>]
push player left with force 0.8

@ launch <who> [upward] [at speed <n>] [without fall damage]
on right click:
    if block is "slime_block":
        launch player upward at speed 2 without fall damage

@ tell <who> <text>
command /hi <target:player>:
    trigger:
        tell arg.1 "&e%player.name% says hi!"
        tell player "&7Sent."

@ on right click on <block>:
on right click on gold block:
    send "&6That is solid gold."

@ location <n> blocks behind <who>
set {_spot} to location 2 blocks behind player
summon zombie at {_spot}

@ location <n> blocks left of <who>
set {_spot} to location 3 blocks left of player
place stone at {_spot}

@ grow tree at <location>
grow tree at player's location

@ drop <item> at <location>
drop 1 diamond at event's location

@ set spawn of world <name> to <location>
set spawn of world "world" to player's location

@ set world border of world <name> to <size> [over <duration>]
set world border of world "world" to 500 over 5 minutes

@ make <who> say <text>
make player say "I love this server!"

@ open workbench for <who> / open enderchest for <who>
open workbench for player

@ fly speed of <who> / walk speed of <who>
set walk speed of player to 0.4

@ saturation of <who> / air of <who>
if air of player < 3:
    send "&cYou are running out of breath!"

@ held slot of <who>
set held slot of player to 1

@ compass target of <who>
set compass target of player to {spawn}

@ bed location of <who>
command /bed:
    players only: true
    trigger:
        if bed location of player is not set:
            send "&7You have not slept in a bed yet."
            stop
        teleport player to bed location of player

@ yaw of <who> / pitch of <who> / direction of <who>
send "&7You are facing &f" + direction of player

@ ip of <who> / locale of <who>
log "%player.name% uses the language " + locale of player

@ time played of <who>
send "&7Played: &f" + time played of player

@ fall distance of <who>
if fall distance of player > 20:
    send "&cBrace yourself!"

@ event entity
on mob spawn:
    set {_mob} to event entity
    set name of {_mob} to "&cWild thing"

@ clicked entity
on entity click:
    push clicked entity upward with force 0.6

@ target entity of <who>
set {_looking} to target entity of player
if {_looking} is set:
    send "&7You are looking at &f%{_looking}%"

@ push <who> upward / downward / forward / backward [with force <n>]
push player upward with force 1.2

@ push <who> towards <location> [with force <n>]
push player towards {spawn} with force 0.8

@ remove entity <entity>
summon zombie at player's location
set {_mob} to last summoned entity
wait 10 seconds
remove entity {_mob}

@ remove all <type> within <n> blocks of <location>
remove all zombies within 20 blocks of player's location

@ <location> offset by <x>, <y>, <z>
teleport player to player's location offset by 0, 10, 0

@ location above <location> / location below <location>
set block at location below player's location to stone

@ midpoint between <a> and <b>
set {_middle} to midpoint between {arena.corner1} and {arena.corner2}

@ highest block at <location>
teleport player to location above highest block at player's location

@ biome at <location>
send "&7Biome: &f" + biome at player's location

@ light level at <location>
if light level at player's location < 8:
    send "&7Mobs can spawn here."

@ target block of <who>
set {_looked} to target block of player
if {_looked} is set:
    strike fake lightning at {_looked}

@ <location> is within <n> blocks of <location>
if player's location is within 10 blocks of {spawn}:
    send "&aYou are near spawn."

@ <location> is loaded
if {arena} is loaded:
    summon zombie at {arena}


@ players only: true
command /sethome:
    players only: true
    trigger:
        set {%player%.home} to player's location

@ increase <variable> by <n> / decrease <variable> by <n>
increase {%player%.coins} by 10
decrease {%player%.lives} by 1

@ toggle <variable>
toggle {%player%.pvp_on}
send "&7PvP: %{%player%.pvp_on}%"

@ swap <variable> and <variable>
swap {team.red.score} and {team.blue.score}

@ default <variable> to <value>
on load:
    default {motd} to "&aWelcome!"

@ has space for <item>
if player has space for 5 diamond:
    give 5 diamond to player
else:
    send "&cYour inventory is full."

@ is bedrock / is dead
if player is bedrock:
    send "&7Bedrock players: use /menu instead of the book."

@ <a> if <condition> else <b>
set {_state} to "&aon" if {%player%.pvp_on} else "&coff"
send "&7PvP is %{_state}%"

@ <list> without <value>
for each {_other} in server.players without player.name:
    send "&7%player.name% says hi" to {_other}

@ <list> sorted by {<name>}
set {_richest} to server.players sorted by {coins}
send "&6Richest online: &e" + item 1 of {_richest}

@ map each <list> to <expression>
set {_shouted} to map each ["red", "blue"] to uppercase it

@ <text> padded to <n>
for each {_name} in server.players:
    send "&f" + ({_name} padded to 16) + "&e%{%{_name}%.coins}%"

@ clamp(n, least, most)
set {%player%.mana} to clamp({%player%.mana} + 5, 0, 100)

@ random(a, b)
set {_roll} to random(1, 6)
send "&7You rolled a &f%{_roll}%"

@ run <function>(...) in <duration> as <name>
function end_boost({_who}):
    set walk speed of {_who} to 0.2
command /boost:
    trigger:
        set walk speed of player to 0.4
        run end_boost(player.name) in 30 seconds as "boost %player.name%"

@ cancel run <name>
cancel run "boost %player.name%"

@ respawn <who>
on player death:
    wait 1 tick
    respawn player

@ show <who> a book titled <text> with pages <text>, <text>
show player a book titled "Rules" with pages "&lRules\n\n1. Be kind.", "2. No griefing."

@ hide <who> from <who> / show <who> to <who>
hide player from arg.1
send "&7%arg.1% can no longer see you."

@ clear title of <who>
clear title of player

@ tab name of <who>
set tab name of player to "&6[VIP] &f%player.name%"

@ free slots of <who>
if free slots of player < 3:
    send "&eYour inventory is nearly full."

@ ping of <who>
send "&7Ping of %arg.1%: &f" + ping of arg.1

@ spawn firework at <location>
spawn firework at player's location colored red, yellow shaped star with power 1

@ play effect <name> at <location>
play effect ender_signal at player's location

@ set line <n> of sign at <location> to <text>
set line 1 of sign at {shop.sign} to "&a[Open]"

@ items in chest at <location>
for each {_item} in items in chest at {reward.chest}:
    give {_item} to player

@ add <item> to chest at <location> / clear chest at <location>
clear chest at {reward.chest}
add 3 diamond to chest at {reward.chest}

@ set gamerule <name> of world <name> to <value>
set gamerule keepInventory of world "world" to true

@ set difficulty of world <name> to <level>
set difficulty of world "world" to hard

@ set pvp of world <name> to <true or false>
set pvp of world "world" to false

@ set pvp of region <name> to <true or false>
on load:
    set pvp of region "spawn" to false

@ set build of region <name> to <true or false>
on load:
    set build of region "spawn" to false

@ players in region <name>
for each {_name} in players in region "arena":
    send "&cThe match starts now!" to {_name}

@ spawn of world <name>
teleport player to spawn of world "world"

@ tab complete: <list>
command /warp <name>:
    tab complete: keys of {warp}
    trigger:
        teleport player to {warp.%arg.1%}

@ disabled: true
command /beta:
    disabled: true
    trigger:
        send "&7Not ready yet."

@ subcommand <name>:
command /team:
    subcommand join <red|blue>:
        trigger:
            add player to team arg.1
    subcommand leave:
        trigger:
            remove player from team

@ on shield block:
on shield block:
    add 1 to {%player%.blocks_made}

@ type of <item>
set {_held} to tool of player
if type of {_held} is "diamond_sword":
    send "&bA fine blade."

@ amount of <item>
set {_held} to tool of player
send "&7You are holding " + amount of {_held} + " item(s)."

@ send toast <text> [with icon <item>] [as goal] [to <who>]
send toast "&aQuest complete!" with icon diamond as challenge to player

@ give head of <name> to <who>
on player kill:
    give head of victim to player

@ set item cooldown of <item> for <who> to <duration>
on right click:
    if event.item is "blaze_rod":
        if item cooldown of blaze rod for player > 0 seconds:
            stop
        set item cooldown of blaze rod for player to 5 seconds
        strike lightning at target block of player

@ stop sound <name> [for <who>] / stop all sounds [for <who>]
stop sound "music_disc.cat" for player

@ absorption of <who>
set absorption of player to 8

@ protocol version of <who>
if protocol version of player < 765:
    send "&eYou are on an old version; some things may look different."

@ client brand of <who>
log "%player.name% plays with " + client brand of player

@ create hologram <name> at <location> with lines <text>, <text>
command /sethologram:
    permission: "holograms.manage"
    trigger:
        create hologram "welcome" at player's location with lines "&6&lWelcome", "&7Type &f/help &7to begin"

@ set line <n> of hologram <name> to <text>
every 1 minute:
    set line 2 of hologram "welcome" to "&7Online: &f%server.online_players%"

@ delete hologram <name>
delete hologram "welcome"

@ holograms
send "&7Holograms: &f" + join holograms with ", "

@ set item <n> of <variable> to <value>
set {podium} to ["Steve", "Alex", "Bob"]
set item 1 of {podium} to player.name
send "&6First place: &f" + item 1 of {podium}

@ ask <who> <text> into <variable>
command /clan <action>:
    trigger:
        ask player "&eWhat should your clan be called?" into {_name} for at most 30 seconds
        if {_name} is not set:
            send "&cToo slow."
            stop
        send "&aClan %{_name}% created."

@ ask <who> <text> with options <text>, <text> into <variable>
ask player "&ePick a team:" with options "Red", "Blue" into {_team}
if {_team} is set:
    add player to team lowercase {_team}

@ confirm <text>:
command /delhome:
    trigger:
        confirm "&cDelete your home? This cannot be undone.":
            delete {%player%.home}
            send "&eHome deleted."

@ items in ender chest of <who>
send "&7Your ender chest holds " + size of (items in ender chest of player) + " stack(s)."

@ add <item> to ender chest of <who> / clear ender chest of <who>
add 3 diamond to ender chest of player
send "&bA gift is waiting in your ender chest."

@ format(n, pattern)
set {_ratio} to {%player%.kills} / max({%player%.deaths}, 1)
send "&7K/D: &f" + format({_ratio}, "0.00")

@ json of <value>
set {_body.player} to player.name
set {_body.coins} to {%player%.coins} + 0
send post request to "https://example.com/hook" with body json of {_body}

@ owned by <name>
give 1 player head owned by "Notch" named "&6Notch's head" to player

@ with potion <kind>
give 1 splash potion with potion strong_healing to player

@ with segments <n>
create bossbar "lives" titled "&cLives" with color red with segments 10 with progress 70 for player

@ location of <who>
if distance between player's location and location of arg.1 > 10:
    send "&c%arg.1% is too far away."

@ owned by <name>
open gui with title "&8Online" with 1 rows for player:
    slot 1 is "player_head" owned by player.name named "&f%player.name%"

@ create world <name>
command /makearena:
    permission: "worlds.manage"
    trigger:
        send "&7Making the arena..."
        create world "arena" flat without structures
        teleport player to spawn of world "arena"

@ load world <name> / unload world <name>
command /closearena:
    permission: "worlds.manage"
    trigger:
        unload world "arena"
        send "&7The arena is closed."

@ delete world <name>
command /resetarena:
    permission: "worlds.manage"
    trigger:
        confirm "&cDelete the arena world and everything in it?":
            delete world "arena"
            create world "arena" flat without structures
            send "&aThe arena is new again."

@ created worlds
send "&7Worlds made here: &f" + join created worlds with ", "

@ <who>'s location
loop all players:
    draw particle circle with radius 2 using particle "flame" at loop-player's location

@ fire event <name>
on player kill:
    set {_victim} to victim
    fire event "kill" with {_victim}

on event "kill":
    add 1 to {%player%.kills}
    send "&7You defeated &f%{_victim}%"

@ schedule <function>(...) in <duration>
function end_vip({_who}):
    delete {%{_who}%.vip}
    send "&7Your VIP time is over." to {_who}

command /vip <target:player>:
    permission: "vip.give"
    trigger:
        set {%arg.1%.vip} to true
        schedule end_vip(arg.1) in 30 days as "vip %arg.1%"

@ cancel schedule <name>
cancel schedule "vip %arg.1%"

@ set fake block at <position> to <block>
on right click:
    if event.block is "stone":
        set fake block at event's location to gold block
        send "&6Only you can see that."

@ clear fake block at <position>
command /reveal:
    players only: true
    trigger:
        set fake block at player to glass
        wait 5 seconds
        clear fake block at player

@ item <name>:
item magic wand:
    blaze rod named "&dMagic wand" with lore "&7Right-click to cast" glowing

command /wand:
    trigger:
        give player magic wand

@ recipe for <item>:
recipe for 4 oak planks:
    ingredients: oak log

@ /hyperscript debug <player>
command /test:
    trigger:
        # Run /hyperscript debug <your name>, then /test, to watch these lines run.
        set {_roll} to random integer between 1 and 6
        if {_roll} > 3:
            send "&aHigh: %{_roll}%"
        else:
            send "&cLow: %{_roll}%"

@ is in region <name> / is not in region <name>
on block break:
    if player is in region "spawn":
        cancel event
        send "&cNot here."

@ is on cooldown <name> / is not on cooldown <name>
command /kit:
    trigger:
        if player is on cooldown "kit":
            set {_left} to cooldown "kit"
            send "&cWait %{_left}%."
            stop
        start cooldown "kit" of 1 hour
        give player 16 bread

@ start cooldown <name> of <duration>
on right click with stick:
    if player is on cooldown "zap":
        stop
    start cooldown "zap" of 3 seconds
    strike lightning at player

@ end cooldown <name>
command /resetkit <player>:
    permission: kits.admin
    trigger:
        end cooldown "kit" for arg.1
        send "&aDone."

@ cooldown <name>
command /kittime:
    trigger:
        set {_left} to cooldown "kit"
        if {_left} is set:
            send "&7Kit ready in &f%{_left}%"
        else:
            send "&aYour kit is ready."

@ shape: "<row>", "<row>", "<row>"
recipe for 1 golden apple:
    shape: " g ", "gag", " g "
    g: gold ingot
    a: apple

@ <letter>: <item>
recipe for 2 arrow:
    shape: "f", "s"
    f: feather
    s: stick

@ ingredients: <item>, <item>
recipe for 1 name tag:
    ingredients: paper, 2 stick

@ on right click with <item>:
on right click with compass:
    send "&7You are at &f%player.x%, %player.y%, %player.z%"

@ set fake blocks from <location> to <location> to <block>
command /cage:
    trigger:
        set {_a} to player's location offset by -1, 0, -1
        set {_b} to player's location offset by 1, 2, 1
        set fake blocks from {_a} to {_b} to glass
        send "&7A cage only you can see."

@ clear fake blocks from <location> to <location>
command /uncage:
    trigger:
        set {_a} to player's location offset by -1, 0, -1
        set {_b} to player's location offset by 1, 2, 1
        clear fake blocks from {_a} to {_b}

@ clear all fake blocks
on world change:
    clear all fake blocks

@ with lore <text>, <text>, ...
give player 1 diamond sword named "&6Excalibur" with lore "&7A fine blade", "&7Handle with care"

@ random item of <list> weighted by <list>
command /crate:
    trigger:
        set {_prizes} to ["bread", "gold_ingot", "diamond"]
        set {_prize} to random item of {_prizes} weighted by [70, 25, 5]
        give player 1 "%{_prize}%"
        send "&aYou won &f%{_prize}%&a!"

@ save inventory of <who> as <name>
command /arena:
    trigger:
        save inventory of player as "before-arena"
        clear inventory of player
        give player 1 iron sword
        send "&7Your things are safe. &f/leave &7gives them back."

@ restore inventory of <who> from <name>
command /leave:
    trigger:
        if player has saved inventory "before-arena":
            restore inventory of player from "before-arena"
            delete saved inventory "before-arena"
            send "&aYour things are back."

@ delete saved inventory <name>
on player join:
    # Left over from a round that never ended properly.
    if player has saved inventory "before-arena":
        restore inventory of player from "before-arena"
        delete saved inventory "before-arena"

@ has saved inventory <name> / does not have saved inventory <name>
on player quit:
    if player has saved inventory "before-arena":
        log "%player% left in the middle of a round"

@ summon ... at <position> with health <n> holding <item> dropping <item>, ...
command /boss:
    permission: boss.spawn
    trigger:
        summon zombie named "&cThe Warden" at player glowing with health 200 with damage 12 holding diamond sword wearing diamond helmet dropping 5 diamond, 1 nether star
        broadcast "&cA boss has appeared!"

@ with health <n>
summon iron golem named "&bGuardian" at player with health 400

@ with speed <n>
summon 5 zombie at player with speed 1.6

@ with damage <n>
summon zombie named "&4Brute" at player with damage 20

@ holding <item>
summon zombie at player holding iron sword enchanted with sharpness 3

@ wearing <item>, <item>
summon zombie at player wearing diamond helmet, iron chestplate, iron boots

@ dropping <item>, <item>
summon chicken named "&6Golden hen" at player dropping 3 gold ingot

@ glowing, silent, baby
summon villager at player glowing silent baby

@ set drops to <item>, <item>
on entity death:
    if event.entity is "creeper":
        set drops to 3 gunpowder, 1 tnt

@ add <item> to drops
on entity death:
    if event.entity is "zombie":
        if chance of 10%:
            add 1 emerald to drops

@ shoot <projectile> from <who>
on right click with blaze rod:
    if player is on cooldown "fireball":
        stop
    start cooldown "fireball" of 2 seconds
    shoot small fireball from player with speed 2

@ copy blocks from <location> to <location> as <name>
command /savearena:
    permission: arena.admin
    trigger:
        copy region "arena" as "arena-clean"
        send "&aThe arena as it is now was saved."

@ paste <name>
command /resetarena:
    permission: arena.admin
    trigger:
        paste "arena-clean"
        broadcast "&7The arena was reset."

@ delete copy <name>
command /forgetarena:
    permission: arena.admin
    trigger:
        delete copy "arena-clean"

@ smelting recipe for <item>:
smelting recipe for 2 gold ingot:
    from: gold block
    time: 5 seconds
    experience: 1

@ messages:
messages:
    en:
        welcome: "&aWelcome, %player%!"
    de:
        welcome: "&aWillkommen, %player%!"

on player join:
    send message "welcome"

@ message <name>
messages:
    en:
        greeting: "&7Hello!"
    es:
        greeting: "&7Hola!"

command /greet <player>:
    trigger:
        send message "greeting" for arg.1 to arg.1

@ make <creature> follow <who>
command /pet:
    trigger:
        summon wolf named "&b%player%'s pet" at player
        set {%player%.pet} to last summoned entity
        make {%player%.pet} follow player

@ make <creature> walk to <location>
command /callguard:
    trigger:
        summon iron golem at player
        make last summoned entity walk to location 10 blocks in front of player

@ make <creature> stay still / make <creature> move again
command /statue:
    trigger:
        summon zombie named "&7Statue" at player silent
        make last summoned entity stay still

@ make <who> ride <creature> / make <who> dismount
command /mount:
    trigger:
        summon horse at player
        make player ride last summoned entity

@ invisible
summon armor stand at player invisible holding diamond sword

@ small, marker, with arms, without gravity, without base plate
command /trophy:
    trigger:
        summon armor stand named "&6Champion" at player small with arms without base plate holding golden apple wearing diamond helmet

@ move camera of <who> from <location> to <location> over <duration>
on first join:
    set {_high} to player's location offset by 0, 25, 0
    move camera of player from {_high} to player's location over 4 seconds

@ stop camera of <who>
command /skip:
    trigger:
        stop camera of player
        send "&7Skipped."

@ set border of <who> to <n> blocks around <location>
command /plot:
    trigger:
        set border of player to 32 blocks around player's location
        send "&7This is your plot."

@ reset border of <who>
on world change:
    reset border of player

@ invite <who> to party
command /invite <player>:
    players only: true
    trigger:
        invite arg.1 to party
        send "&7%player% invites you to a party." to arg.1

@ accept party invite / decline party invite
command /accept:
    players only: true
    trigger:
        accept party invite
        if player is in a party:
            send "&a%player% joined." to party of player

@ leave party
command /leaveparty:
    players only: true
    trigger:
        leave party
        send "&7You left the party."

@ remove <who> from party
command /partykick <player>:
    players only: true
    trigger:
        remove arg.1 from party

@ disband party
command /disbandparty:
    players only: true
    trigger:
        send "&cThe party was ended." to party of player
        disband party

@ party of <who>
on chat:
    if message starts with "!":
        cancel event
        send "&d[Party] &f%player%: %message%" to party of player

@ party leader of <who>
command /leader:
    trigger:
        if player is in a party:
            send "&7Your party is led by &f" + party leader of player

@ party invites of <who>
command /invites:
    trigger:
        send "&7Invited by: &f" + party invites of player

@ <who> is in a party
on hit:
    if attacker is in a party:
        if party of attacker contains victim:
            cancel event

@ on queue <name> of <n>:
on queue "duels" of 2:
    for each {_name} in {_players}:
        send "&aA match was found!" to {_name}

@ add <who> to queue <name>
command /duel:
    players only: true
    trigger:
        add player to queue "duels"
        send "&7Waiting for an opponent..."

@ remove <who> from queue <name>
command /leavequeue:
    players only: true
    trigger:
        remove player from all queues
        send "&7You are no longer waiting."

@ queue <name>
command /waiting:
    trigger:
        send "&7In line: &f" + size of queue "duels"

@ <who> is in queue <name>
command /duel2:
    players only: true
    trigger:
        if player is in queue "duels":
            send "&cYou are already waiting."
            stop
        add player to queue "duels"

@ enchantment <name>:
enchantment lifesteal:
    max level: 3
    on hit:
        add {_level} to health of player

@ max level: <n>
enchantment thorns of fire:
    max level: 2
    on hurt:
        ignite attacker for 3 seconds

@ on hit:
enchantment lightning:
    on hit:
        if chance of 20%:
            strike lightning at victim

@ on hurt:
enchantment dodge:
    on hurt:
        if chance of 10%:
            cancel event
            send "&7Dodged!"

@ on block break:
enchantment prospector:
    on block break:
        if event.block is "stone":
            if chance of 5%:
                give player 1 gold nugget

@ {_body}
on web request "/announce":
    broadcast "&e[Web] &f%{_body}%"

@ {_method}
on web request "/ping":
    log "%{_method}% from %{_address}%"

@ {_path}
on web request:
    log "Something asked for %{_path}%"

@ {_query}
on web request "/give":
    log "Asked with: %{_query}%"

@ {_address}
on web request "/vote":
    log "A vote arrived from %{_address}%"

@ /hyperscript test [script]
function double({_n}):
    return {_n} * 2

test "doubling":
    expect double(4) is 8

@ test "<what it shows>":
function price({_amount}):
    return {_amount} * 5

test "five coins each":
    expect price(3) is 15

@ expect <condition>
test "numbers add up":
    set {_total} to 2 + 2
    expect {_total} is 4

@ test log
command /hello:
    trigger:
        send "&aHello!"

test "hello says hello":
    execute player command "/hello"
    expect test log contains "Hello!"

@ /hyperscript search <word>
command /hello:
    trigger:
        send "&aHello, %player%!"

@ /hyperscript install <id>
command /hello:
    trigger:
        send "&aHello, %player%!"

@ /hyperscript update
command /hello:
    trigger:
        send "&aHello, %player%!"

@ replace regex <pattern> with <b> in <text>
on chat:
    # Hide anything that looks like an address.
    set chat message to replace regex "\\d+\\.\\d+\\.\\d+\\.\\d+" with "[hidden]" in message

@ regex matches of <pattern> in <text>
command /numbers <text>:
    trigger:
        set {_found} to regex matches of "\\d+" in args
        send "&7Numbers: &f" + join {_found} with ", "

@ regex groups of <pattern> in <text>
command /setting <text>:
    trigger:
        set {_parts} to regex groups of "(\\w+)=(\\d+)" in arg.1
        if size of {_parts} is 2:
            send "&7" + item 1 of {_parts} + " is " + item 2 of {_parts}

@ try parse <text> as number
command /pay <amount>:
    trigger:
        set {_amount} to try parse arg.1 as number
        if {_amount} is not set:
            send "&c%arg.1% is not a number."
            stop
        send "&aPaying %{_amount}%."

@ game version of <who>
on player join:
    if game version of player is not "1.21.4":
        send "&eYou are on %game version of player%. Some things look best on 1.21.4."

@ drop loot <table> at <location>
command /dungeonloot:
    permission: loot.admin
    trigger:
        drop loot "chests/simple_dungeon" at player's location

@ fill chest at <location> with loot <table>
command /restock:
    permission: loot.admin
    trigger:
        fill chest at target block of player with loot "chests/village/village_weaponsmith"
        send "&aRestocked."

@ advancement "<name>":
advancement "first kill":
    title: "&cFirst blood"
    description: "Win a fight against another player"
    icon: iron sword
    frame: challenge

@ title: / description:
advancement "rich":
    title: "&6Rich"
    description: "Own a thousand coins"

@ icon: <item>
advancement "miner":
    icon: diamond pickaxe

@ frame: task, goal or challenge
advancement "dragon":
    frame: challenge

@ parent: "<name>"
advancement "miner":
    icon: diamond pickaxe

advancement "master miner":
    parent: "miner"
    icon: netherite pickaxe

@ announce: false
advancement "tutorial":
    announce: false

@ hidden: true
advancement "secret room":
    hidden: true

@ grant advancement <name> to <who>
advancement "welcome":
    title: "Welcome"

on first join:
    grant advancement "welcome" to player

@ revoke advancement <name> from <who>
advancement "welcome":
    title: "Welcome"

command /again:
    trigger:
        revoke advancement "welcome" from player

@ <who> has advancement <name>
advancement "vip":
    title: "VIP"

command /lounge:
    trigger:
        if player has advancement "vip":
            send "&aWelcome in."
        else:
            send "&cMembers only."

@ send discord message <text> to channel <id>
on player join:
    send discord message "%player% joined the server" to channel "123456789012345678"

@ on discord message <id>:
on discord message "123456789012345678":
    broadcast "&9[Discord] &f%{_user}%&7: %{_message}%"

@ /hyperscript docs <word>
command /hello:
    trigger:
        send "&aHello, %player%!"

@ limit: <n> per <duration>
on chat:
    limit: 3 per 5 seconds
    add 1 to {%player%.messages}

@ ask <who> <text> with anvil into <variable>
command /pet:
    players only: true
    trigger:
        ask player "Name your pet" with anvil into {_name}
        if {_name} is "":
            send "&7Maybe later."
            stop
        set {%player%.pet} to {_name}
        send "&aYour pet is called %{_name}%."

@ open trades <title>:
command /baker:
    players only: true
    trigger:
        open trades "&eBaker":
            1 emerald for 6 bread
            3 emerald for 1 cake

@ <cost> for <result>
command /miner:
    players only: true
    trigger:
        open trades "&7Miner":
            16 cobblestone for 1 emerald

@ <cost> and <cost> for <result>
command /smith:
    players only: true
    trigger:
        open trades "&6Smith":
            4 emerald and 1 stick for 1 iron sword

@ create npc <name> at <location>
command /setguide:
    permission: npc.admin
    players only: true
    trigger:
        create npc "&aGuide" at player's location
        send "&aThe guide stands here now."

@ create npc <name> as <entity> at <location>
command /setguard:
    permission: npc.admin
    players only: true
    trigger:
        create npc "&7Guard" as iron golem at player's location

@ delete npc <name>
command /removeguide:
    permission: npc.admin
    trigger:
        delete npc "guide"

@ on npc click <name>:
on npc click "guide":
    send "&aGuide: &fThe arena is that way."

@ npc <name>
command /announce:
    permission: npc.admin
    trigger:
        make npc "guide" say "The event starts in five minutes!"

@ all npcs
command /npcs:
    trigger:
        send "&7Characters: &f" + join all npcs with ", "

@ run sql <statement>
on load:
    run sql "CREATE TABLE IF NOT EXISTS visits (player VARCHAR(16), day VARCHAR(10))"

@ sql rows of <query>
command /visits:
    trigger:
        async:
            set {_rows} to sql rows of "SELECT day FROM visits WHERE player = ?" with player.name
            send "&7You have visited on %size of {_rows}% day(s)."

@ with <value>, <value>
on player join:
    run sql "INSERT INTO visits (player, day) VALUES (?, ?)" with player.name, server.date

@ <text> as offlineplayer
command /seen <player>:
    trigger:
        set {_who} to arg.1 as offlineplayer
        if {_who} has not played before:
            send "&c%arg.1% has never played here."
            stop
        send "&7%{_who}% was last on " + last seen of {_who} formatted as "d MMMM yyyy"

@ uuid of <who>
command /uuid <player>:
    trigger:
        set {_who} to arg.1 as offlineplayer
        if {_who} has played before:
            send "&7%{_who}%: &f" + uuid of {_who}

@ name of <who>
command /realname <player>:
    trigger:
        send "&7That is &f" + name of arg.1

@ all offline players
command /everyone:
    permission: staff.everyone
    trigger:
        async:
            set {_all} to all offline players
            send "&7%size of {_all}% player(s) have played here."

@ <who> has played before
command /known <player>:
    trigger:
        if arg.1 has played before:
            send "&a%arg.1% has been here."
        else:
            send "&c%arg.1% has never joined."

@ type: <creature>
mob "Guard Dog":
    type: wolf
    health: 40

command /dog:
    players only: true
    trigger:
        spawn mob "Guard Dog" at player's location

@ name: <text>
mob "elite":
    type: zombie
    name: "&c&lElite Zombie"
    health: 60

@ health: <n>
mob "Tank":
    type: iron golem
    health: 400

@ damage: <n>
mob "Brute":
    type: zombie
    damage: 12

@ speed: <n>
mob "Runner":
    type: zombie
    speed: 1.6
    baby: true

@ holding: <item>
mob "Knight":
    type: zombie
    holding: diamond sword

@ wearing: <item>, <item>
mob "Knight":
    type: zombie
    wearing: diamond helmet, diamond chestplate

@ drops: <item>, <item>
mob "Treasure Zombie":
    type: zombie
    drops: 5 diamond, 1 golden apple

@ experience: <n>
mob "Sage":
    type: villager
    experience: 200
    drops: nothing

@ glowing: true / silent: true / baby: true
mob "Marked One":
    type: zombie
    glowing: true
    silent: true

@ on spawn:
mob "Herald":
    type: zombie
    on spawn:
        broadcast "&cA herald has appeared!"

@ on death:
mob "Bounty":
    type: zombie
    health: 80
    on death:
        if player is set:
            add 100 to {%player%.coins}
            send "&a+100 coins for the bounty."

@ spawn mob <name> at <location>
command /boss:
    permission: op
    players only: true
    trigger:
        spawn mob "Frost Giant" at player's location
        set {_giant} to last summoned entity
        make {_giant} target player

@ mob name of <entity>
command /summongiant:
    permission: op
    players only: true
    trigger:
        spawn mob "Frost Giant" at player's location
        set {_made} to last summoned entity
        send "&7That is a &f" + mob name of {_made}

@ currency "<name>":
currency "tokens":
    start: 5

command /tokens:
    players only: true
    trigger:
        set {_tokens} to currency "tokens" of player
        send "&7Tokens: &e%{_tokens}%"

@ currency <name> of <who>
on player kill:
    add 1 to currency "tokens" of player
    send "&e+1 token."

@ pay <n> of currency <name> from <who> to <who>
command /tip <player>:
    players only: true
    trigger:
        if currency "tokens" of player < 1:
            send "&cYou have no tokens."
            stop
        pay 1 of currency "tokens" from player to arg.1
        send "&aYou tipped %arg.1% a token."

@ placeholder "<name>":
placeholder "visits":
    return {%player%.joins}

@ lerp(from, to, t)
set {_height} to lerp(60, 80, 0.5)
send "&7Half way up is %{_height}%."

@ between(text, before, after)
set {_inner} to between("Hello [world]!", "[", "]")
send "&7%{_inner}%"

@ nearest player to <location>
set {_who} to nearest player to player's location
if {_who} is set:
    send "&7Closest: &f%{_who}%"

@ block (below/above) <who>
on player jump:
    if block below player is "slime_block":
        push player upward with force 2

@ <number> is [not] (even/odd)
if level of player is even:
    send "&7An even level."

@ chance of <n>%:
on block break:
    chance of 10%:
        give player 1 emerald
        send "&aLucky!"
