Astral Realms Documentation Help

Functions

Inline functions are short, named utilities you can call from any string that already supports placeholders — menu item names, lore, titles, dialog labels, action arguments, requirement values, chat messages, anywhere the placeholder parser runs. They are designed for the same role that helper methods play in code: take a few values, return one value, drop the result back into the surrounding string.

Syntax

$name(arg1, arg2, ...)
  • The leading $ introduces a function call. $e(...) is reserved for arithmetic expressions (see Placeholders) and is not parsed as a function.

  • The name accepts [a-zA-Z0-9_-] characters — letters, digits, underscores, and hyphens, so dash-named built-ins like format-number, format-date, and random-int are inline-callable. Arguments are separated by commas (,); commas inside nested parentheses are not treated as separators.

  • Each argument is a normal placeholder string. Placeholders inside arguments resolve before the function runs, so you can freely mix raw values, %placeholder%, nested $other(...) calls, and $e(...) expressions.

  • The function's return value is converted to a string and substituted in-place — so a function call is just an inline value, exactly like a %placeholder%.

items: counter: item-stack: material: PAPER name: "<gold>Score: $add(%variables_score%, 1)" lore: - "<gray>Capped: $add(%variables_score%, 1, 100)" - "<gray>Rounded HP: $round(%player_health%, 1)"

Resolution Order

Functions are looked up in this order:

  1. The per-plugin function registry (anything registered by your own plugin).

  2. The global function registry shared across the network.

If the name is not found, the call is left as UNPARSED_FUNCTION in the resulting string — useful as a visible flag that the registry was wrong or the plugin failed to load.

Built-in Functions

All built-ins live in the global registry, so they are available in every menu, dialog, and item string without any extra configuration.

Numbers

add(input, number, max?)

Adds number to input. If max is supplied, the result is capped: min(input + number, max).

- "[set-variable] qty $add(%variables_qty%, 1, 64)"

subtract(input, number, min?)

Subtracts number from input. If min is supplied, the result is floored: max(input - number, min).

- "[set-variable] qty $subtract(%variables_qty%, 1, 0)"

increment(value, max?)

Returns value + 1. If max is supplied and value >= max, returns value unchanged. Preserves the input's number type (int stays int, double stays double).

- "[set-variable] page $increment(%variables_page%, 9)"

decrement(value, min?)

Returns value - 1. If min is supplied and value <= min, returns value unchanged. Preserves the input's number type.

- "[set-variable] page $decrement(%variables_page%, 0)"

min(number1, number2)

Returns the smaller of two numbers as a double. If either is null it returns the other; if both are null it returns 0.0.

name: "<gray>Best price: $min(%parameters_offer%, %variables_listed%)"

max(number1, number2)

Returns the larger of two numbers as a double, with the same null handling as min.

name: "<gray>Floor: $max(%parameters_offer%, 100)"

random-int(min, max)

Returns a pseudo-random integer uniformly distributed in the inclusive range [min, max]. Null handling: both null → 0; only min null → returns max; only max null → returns min.

- "[set-variable] roll $random-int(1, 6)" name: "<gray>Bonus damage: +$random-int(%variables_min%, %variables_max%)"

round(number, decimals?)

Rounds the value to decimals decimal places. decimals defaults to 0. Integers and longs pass through unchanged.

lore: - "<gray>HP: $round(%player_health%, 1)" - "<gray>Avg: $round(%variables_average%)"

format-number(value, pattern?)

Formats a number using a java.text.DecimalFormat pattern. Defaults to 0.00 when pattern is omitted, null, or blank.

lore: - "<gray>Balance: $format-number(%vault_eco_balance%)" - "<gray>Stock: $format-number(%variables_stock%, #,###)"

Time

format-date(epoch-millis, mode?)

Formats a long containing milliseconds-since-epoch. mode selects the output:

mode

Output

format (default)

HH:mm:ss dd/MM/yyyy

remaining

Milliseconds between now and the timestamp (signed long).

remaining-format

Human-readable duration between now and the timestamp.

format-date

Date-only dd/MM/yyyy.

format-duration

Human-readable duration treating the value as a length, not a moment.

anything else

Used as a DateTimeFormatter pattern (e.g. yyyy-MM-dd HH:mm).

lore: - "<gray>Listed: $format-date(%aah_listing_created%)" - "<gray>Expires in: $format-date(%aah_listing_expires%, remaining-format)"

Built-in Function Summary

Name

Signature

Returns

add

(input, number, max?)

input + number, capped at max

subtract

(input, number, min?)

input - number, floored at min

increment

(value, max?)

value + 1, capped at max

decrement

(value, min?)

value - 1, floored at min

min

(number1, number2)

Math.min(...) as double

max

(number1, number2)

Math.max(...) as double

random-int

(min, max)

Random int in [min, max] inclusive

round

(number, decimals?)

Half-up rounded

format-number

(value, pattern?)

DecimalFormat output

format-date

(epoch-millis, mode?)

Formatted timestamp

Registering Your Own Functions

See Custom Functions for the developer API.

Last modified: 25 July 2026