# The JSPrismarine script module

A behavior pack script can import `@jsprismarine/server` to reach what only JSPrismarine offers.
The same pack still loads on Bedrock Dedicated Server (BDS), as long as it detects the module and
falls back when the module is missing. This page shows that pattern and lists what the module
holds today.

## Detect the module and fall back

Leave `@jsprismarine/server` out of `manifest.json`, and load it with `import()` inside `try`:

```js
import { world } from '@minecraft/server';

/** The JSPrismarine module, or undefined on a server without it. */
const loadJsprismarine = async () => {
    try {
        return await import('@jsprismarine/server');
    } catch {
        return undefined;
    }
};

world.afterEvents.worldLoad.subscribe(async () => {
    const jsp = await loadJsprismarine();
    if (jsp === undefined) {
        world.sendMessage('Running on Bedrock Dedicated Server');
        return;
    }
    const { name, version, minecraftVersion } = jsp.jsprismarine;
    world.sendMessage(`Running on ${name} ${version}, for Minecraft ${minecraftVersion}`);
});
```

On BDS the import rejects with
`ReferenceError: Module [@jsprismarine/server] is unrecognized. If this is a Native module, did you remember to add it to your manifest.json?`,
the `catch` returns `undefined`, and the pack goes on without it. On JSPrismarine the import
resolves to the module.

Each part of the pattern matters on BDS:

- **No manifest entry.** BDS refuses to load a pack that declares a module it does not know, even
  with `"optional": true`. The whole pack fails, and only the content log says why.
- **`import()`, not a static `import`.** BDS rejects a static import of the module too, and the
  file that holds it fails to load. When that file is the pack's entry, none of the pack's scripts
  run. JSPrismarine resolves both forms, because a module whose name starts with `@jsprismarine/`
  needs no manifest entry there.
- **Inside `try`, or with `.catch()`.** A rejection nobody handles ends the callback that awaited
  it.

Every `@minecraft/` module still needs its manifest entry on JSPrismarine, as on BDS. An import of
any other `@jsprismarine/` name rejects with the same message BDS gives.

## What the module holds

Every export is frozen. `jsprismarine` holds plain values that stay the same while the server
runs. `performance`, `getPing`, `bossBars`, `playerList` and `serverList` reach the running
server: each property of `performance` and `serverList` reads the server when the script reads
it, so a script that wants the numbers for the current tick reads them again.


| Member                                           | Type                     | What it is                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------ | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `jsprismarine`                                   | object                   | The server the pack runs on.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `jsprismarine.name`                              | `"JSPrismarine"`         | The server software, always `JSPrismarine`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `jsprismarine.version`                           | string                   | The JSPrismarine version, such as `0.22.0`, without a leading `v`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `jsprismarine.minecraftVersion`                  | string                   | The newest Minecraft Bedrock release the server speaks, the one it advertises.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `jsprismarine.protocolVersion`                   | number                   | The Bedrock network protocol version of `minecraftVersion`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `jsprismarine.maxPlayers`                        | number                   | How many players may be online at once, the server's `max-players` setting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `performance`                                    | object                   | How fast the server ticks and how much memory its JavaScript heap holds. Each property reads the server when the script reads it.                                                                                                                                                                                                                                                                                                                                                                                                               |
| `performance.tps`                                | number                   | Ticks per second over the last second. The server aims for 20, and runs above it while it catches up.                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `performance.tpsAverages`                        | `readonly number[]`      | Ticks per second averaged over the windows `/tps` reports, shortest first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `performance.lastTickMs`                         | number                   | How long the last tick's work took, in milliseconds, without the wait before the next tick. Zero before the first tick.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `performance.averageTickMs`                      | number                   | How long a tick's work has taken lately, in milliseconds, as a moving average over the recent ticks. Zero before the first tick.                                                                                                                                                                                                                                                                                                                                                                                                                |
| `performance.heapUsedBytes`                      | number                   | The bytes the server's JavaScript heap holds now, garbage not yet collected included. Buffers and native memory outside the heap are not counted.                                                                                                                                                                                                                                                                                                                                                                                               |
| `performance.heapAllocatedBytes`                 | number                   | The bytes the runtime has reserved for the heap, which `heapUsedBytes` fills.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `performance.heapLimitBytes`                     | number                   | The most bytes the heap may grow to before the runtime runs out of memory, which `--max-old-space-size` sets on Node.js.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `getPing(player)`                                | function                 | The player's round trip time in milliseconds, or `undefined` while their connection has no sample, after they leave, or when their transport measures none.                                                                                                                                                                                                                                                                                                                                                                                     |
| `bossBars`                                       | object                   | Boss bars on one player's screen. A bar belongs to the pack that showed it and goes away when the player leaves or the pack's scripts stop, as on `/reload`.                                                                                                                                                                                                                                                                                                                                                                                    |
| `bossBars.show(player, options)`                 | function                 | Shows a boss bar to one player, alongside every bar already on their screen. A bar for a player who left is never valid.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `playerList`                                     | object                   | The player list every client shows, in the pause menu. A name a pack sets there reverts when the pack's scripts stop, as on `/reload`. Chat and the name above the head keep the login name.                                                                                                                                                                                                                                                                                                                                                    |
| `playerList.setDisplayName(player, name)`        | function                 | Changes the name every client, and every later joiner, shows for the player in its player list, and nothing else. Throws for an empty name. Does nothing for a player who left.                                                                                                                                                                                                                                                                                                                                                                 |
| `playerList.reset(player)`                       | function                 | Gives the player's entry its login name back, at once rather than when the scripts stop.                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `serverList`                                     | object                   | What a server list shows of the server, the same over every way a client asks: Bedrock's server list and LAN, the query protocol and Java Edition's multiplayer screen. Each property reads what the list shows now. A change belongs to the pack that made it and goes when the pack's scripts stop, as on `/reload`; where two packs change one property, the one that changed it last shows.                                                                                                                                                 |
| `serverList.motd`                                | string                   | The MOTD, the server's first line, which `§` format codes color. `config.json`'s `motd` until a pack changes it.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `serverList.levelName`                           | string                   | The second name, which a Bedrock client shows below the MOTD for a server on its LAN. `JSPrismarine` until a pack changes it.                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `serverList.onlinePlayers`                       | number                   | How many players the list says are online. The players connected over every transport until a pack changes it.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `serverList.maxPlayers`                          | number                   | The player limit the list shows. `max-players` until a pack changes it. A change shows in the list only: the server still turns a player away at `max-players`.                                                                                                                                                                                                                                                                                                                                                                                 |
| `serverList.update(options)`                     | function                 | Changes what the server list shows. A property the options leave out keeps the value the pack gave it before, or the server's own. Throws a `TypeError` for a MOTD or second name with a `;`, which the Bedrock ping cannot carry, and for a count that is not a whole number from 0 to 2147483647.                                                                                                                                                                                                                                             |
| `serverList.reset()`                             | function                 | Takes back every change the pack made, at once rather than when its scripts stop, so the list shows another pack's change or the server's own values again.                                                                                                                                                                                                                                                                                                                                                                                     |
| `config`                                         | object                   | The pack's config file: `<folder>.config.json` beside the pack's folder, which for an addon installed as `addons/<name>/` is `addons/<name>.config.json`. The owner edits it and the pack reads it. The server parses it; the pack checks the shape itself.                                                                                                                                                                                                                                                                                     |
| `config.value`                                   | `unknown`                | The parsed JSON of the file, as a new frozen value each read, or `undefined` while there is no file. A file that fails to parse keeps the last value, and the content log says so once.                                                                                                                                                                                                                                                                                                                                                         |
| `config.afterEvents`                             | `AddonConfigEvents`      | What the file does.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `config.write(value)`                            | function                 | Rewrites the file with the value as JSON, so the pack's commands and the owner's editor change the same thing. `change` fires for it as for an edit. Throws a `TypeError` for a value JSON cannot carry.                                                                                                                                                                                                                                                                                                                                        |
| `permissions`                                    | object                   | The groups, nodes and meta of `permissions.json`, resolved as the server resolves them for a command. A write persists to the file as `/perms` would, and `afterEvents.permissionsChange` fires after any write, from a script, `/perms`, `/op` or an edit of the file.                                                                                                                                                                                                                                                                         |
| `permissions.afterEvents`                        | `PermissionsAfterEvents` | The events the permission files raise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `permissions.has(player, node)`                  | function                 | Whether the player holds the node after resolution: their own nodes, then their groups heaviest first and each group's parents, where a specific node beats a wildcard and a negation wins a tie. An operator holds every node.                                                                                                                                                                                                                                                                                                                 |
| `permissions.groupsOf(player)`                   | function                 | The groups the player holds directly, heaviest first, `default` and an operator's `operator` included.                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `permissions.primaryGroupOf(player)`             | function                 | The heaviest group the player holds directly, or `default`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `permissions.metaOf(player, key)`                | function                 | The resolved value of a meta key such as `prefix`, `suffix` or `level`: the player's own, then their groups' in resolution order. `undefined` when nothing sets it.                                                                                                                                                                                                                                                                                                                                                                             |
| `permissions.grant(player, node, expires)`       | function                 | Adds a node to the player. Throws a `RangeError` for a node not spelled as `scope.name`, `scope.*` or `*` with at most one leading `-`, or for an expiry that is not an ISO 8601 instant with a time zone in the future.                                                                                                                                                                                                                                                                                                                        |
| `permissions.revoke(player, node)`               | function                 | Removes a node from the player. Does nothing when they do not have it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `permissions.grantToGroup(group, node, expires)` | function                 | Adds a node to the group named. Throws as `grant` does for the node and the expiry, and an `Error` for a group the file does not have.                                                                                                                                                                                                                                                                                                                                                                                                          |
| `permissions.revokeFromGroup(group, node)`       | function                 | Removes a node from the group named. Does nothing when it does not have it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `permissions.addToGroup(player, group, expires)` | function                 | Adds a player to a group, until `expires` when one is given. Throws an `Error` for a group the file does not have.                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `permissions.removeFromGroup(player, group)`     | function                 | Removes a player from a group. Does nothing when they are not in it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `levels`                                         | object                   | The server's levels, each a world of its own with its dimensions, players' records and scripts. A level is named by its name, unique among the attached ones, or by its UUID. The pack's scripts run in one level; a pack that every level loads runs once in each.                                                                                                                                                                                                                                                                             |
| `levels.current`                                 | `LevelInfo`              | The level the pack's scripts run in.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `levels.list()`                                  | function                 | Every level the server knows: the attached ones first, then the detached ones `levels.json` keeps.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `levels.levelOf(player)`                         | function                 | The level the player is in. Throws a `TypeError` for a player who left.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `levels.transfer(player, level, options)`        | function                 | Moves the player to an attached level: to where they last were there, or to its spawn when they have never been in it or `toSpawn` is set. They leave their record behind and pick up the level's, except the parts a `player-data-groups` group shares. Resolves to whether the move landed. Rejects for a level that is not attached.                                                                                                                                                                                                         |
| `levels.create(name, options)`                   | function                 | Creates a level, records it in `levels.json` and attaches it. Rejects for a name that is taken or not 1 to 64 letters, digits, `_` or `-`.                                                                                                                                                                                                                                                                                                                                                                                                      |
| `levels.attach(level)`                           | function                 | Attaches a detached level `levels.json` records, so players can go there again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `levels.detach(level)`                           | function                 | Saves a level, moves its players to the entry level and detaches it. Its files stay. Rejects for the entry level and a level `config.json` names. Detaching the pack's own level stops its scripts there, so the promise never settles.                                                                                                                                                                                                                                                                                                         |
| `events`                                         | object                   | The order before-event callbacks run in across packs. Bedrock runs them in the order they subscribed; a callback given a priority runs with the others of its priority, lower priorities first, so a protection pack at `highest` decides after the packs at `normal`. Every callback sees the `cancel` and the values the ones before it set. A callback's priority ends when it is unsubscribed or the pack's scripts stop, as on `/reload`. After-events have no priority: they fire only for what happened, so their order changes nothing. |
| `events.setPriority(signal, callback, priority)` | function                 | Gives a callback the pack subscribed to a before-event signal, such as `world.beforeEvents.playerBreakBlock`, a priority. Every subscription of that callback to that signal gets it. A `monitor` callback runs last and sees the outcome but cannot change it: the server puts back `cancel` and every value it set once it returns. Throws a `TypeError` for an after-event signal, a callback the pack has not subscribed to the signal, or a priority the module does not name.                                                             |
| `players`                                        | object                   | Who a player is beyond the entity id of one login, which changes each time they join: the account, the client and the connection. `key` is the id that stays the same.                                                                                                                                                                                                                                                                                                                                                                          |
| `players.identity(player)`                       | function                 | The account, client and connection of an online player. Throws a `TypeError` for a player who left.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `players.find(player)`                           | function                 | A player who joined the server, online or not, by their key, name, XUID or UUID. A name is matched without regard to case; when several accounts joined under it, the one that joined last answers. `undefined` for a player the server does not know, or one whose last join is older than the server's user cache keeps.                                                                                                                                                                                                                      |


The members take and give these types, which `@jsprismarine/script-types` declares:


| Type                                            | Kind                      | What it is                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ----------------------------------------------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Player`                                        | interface                 | A `Player` from `@minecraft/server`. The members take only a real one; this names what they read, so the pack's own `Player` type fits.                                                                                                                                                                                                                                                                                                                  |
| `Player.id`                                     | string                    | The player's entity id.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `BossBarColor`                                  | string                    | A boss bar's color. One of `pink`, `blue`, `red`, `green`, `yellow`, `purple`, `rebeccaPurple`, `white`.                                                                                                                                                                                                                                                                                                                                                 |
| `BossBarOptions`                                | interface                 | What a boss bar shows.                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `BossBarOptions.text?`                          | string                    | The title above the bar. Empty when a bar is shown without it.                                                                                                                                                                                                                                                                                                                                                                                           |
| `BossBarOptions.progress?`                      | number                    | How full the bar is, from 0 to 1, clamped to that range. Full when a bar is shown without it.                                                                                                                                                                                                                                                                                                                                                            |
| `BossBarOptions.color?`                         | `BossBarColor`            | The bar's color. Pink when a bar is shown without it.                                                                                                                                                                                                                                                                                                                                                                                                    |
| `BossBar`                                       | interface                 | A boss bar on one player's screen.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `BossBar.player`                                | `Player`                  | The player who sees the bar.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `BossBar.isValid`                               | boolean                   | Whether the bar is still there: false once it is hidden, once the player leaves and once the pack's scripts stop.                                                                                                                                                                                                                                                                                                                                        |
| `BossBar.update(options)`                       | function                  | Changes what the bar shows. A property the options leave out keeps its value. Does nothing to a bar that is no longer valid.                                                                                                                                                                                                                                                                                                                             |
| `BossBar.hide()`                                | function                  | Takes the bar off the screen for good. Does nothing to a bar that is no longer valid.                                                                                                                                                                                                                                                                                                                                                                    |
| `LevelInfo`                                     | interface                 | One level, as the server knew it when the pack asked.                                                                                                                                                                                                                                                                                                                                                                                                    |
| `LevelInfo.id`                                  | string                    | The level's UUID, which stays the same across restarts and renames.                                                                                                                                                                                                                                                                                                                                                                                      |
| `LevelInfo.name`                                | string                    | The level's name.                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `LevelInfo.attached`                            | boolean                   | Whether the level is attached, so players can be in it.                                                                                                                                                                                                                                                                                                                                                                                                  |
| `LevelInfo.entry`                               | boolean                   | Whether players join the server in this level.                                                                                                                                                                                                                                                                                                                                                                                                           |
| `LevelInfo.players`                             | `readonly string[]`       | The names of the players in the level, empty for a detached one.                                                                                                                                                                                                                                                                                                                                                                                         |
| `LevelTransferOptions`                          | interface                 | How `levels.transfer` moves a player.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `LevelTransferOptions.toSpawn?`                 | boolean                   | Sends the player to the level's spawn even when they were there before.                                                                                                                                                                                                                                                                                                                                                                                  |
| `LevelCreateOptions`                            | interface                 | The world a new level gets.                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `LevelCreateOptions.preset?`                    | string                    | The world preset, such as `minecraft:flat`. `minecraft:normal` when left out.                                                                                                                                                                                                                                                                                                                                                                            |
| `LevelCreateOptions.seed?`                      | string                    | The world seed, read as `config.json` reads one. A random seed when left out.                                                                                                                                                                                                                                                                                                                                                                            |
| `PlayerEdition`                                 | string                    | The edition of Minecraft a player plays. One of `bedrock`, `java`.                                                                                                                                                                                                                                                                                                                                                                                       |
| `KnownPlayer`                                   | interface                 | A player who joined the server, as the server last saw them.                                                                                                                                                                                                                                                                                                                                                                                             |
| `KnownPlayer.key`                               | string                    | The id that stays the same from one login to the next, the one the server files a player's permissions, operator status and bans under: `xbox:` and the XUID of an Xbox Live account the server verified, `java:` and the profile UUID of a Java Edition account Mojang verified, or `offline:` and the name on an offline-mode server. `/perms`, `/op` and `/deop` take it as a target. Keep a player's own data, such as balances and stats, under it. |
| `KnownPlayer.name`                              | string                    | The name the player last joined with.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `KnownPlayer.xuid?`                             | string                    | The Xbox Live id, for a Bedrock player the server verified. Absent for any other player.                                                                                                                                                                                                                                                                                                                                                                 |
| `KnownPlayer.uuid`                              | string                    | The player's UUID. A Java Edition account's profile id; on an offline-mode Bedrock server the client draws one per install, so it can change.                                                                                                                                                                                                                                                                                                            |
| `KnownPlayer.edition`                           | `PlayerEdition`           | The edition the player joined with.                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `PlayerIdentity`                                | interface                 | An online player: their account, as `KnownPlayer` gives it, and the client and connection they joined with.                                                                                                                                                                                                                                                                                                                                              |
| `PlayerIdentity.key`                            | string                    | The id that stays the same from one login to the next, as `KnownPlayer.key`.                                                                                                                                                                                                                                                                                                                                                                             |
| `PlayerIdentity.name`                           | string                    | The name the player joined with.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `PlayerIdentity.xuid?`                          | string                    | The Xbox Live id the login carried. Absent for a Java player and a login without one. On an offline-mode server the client chooses it, so file data under `key` instead.                                                                                                                                                                                                                                                                                 |
| `PlayerIdentity.uuid`                           | string                    | The player's UUID, as `KnownPlayer.uuid`.                                                                                                                                                                                                                                                                                                                                                                                                                |
| `PlayerIdentity.edition`                        | `PlayerEdition`           | The edition of the player's client.                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `PlayerIdentity.protocolVersion`                | number                    | The network protocol version the client speaks, of the player's edition.                                                                                                                                                                                                                                                                                                                                                                                 |
| `PlayerIdentity.clientVersion?`                 | string                    | The game version the client reported, such as `1.26.50`. Absent when it reported none, as a Java client never does.                                                                                                                                                                                                                                                                                                                                      |
| `PlayerIdentity.deviceOs?`                      | string                    | The client's operating system as the Bedrock login names it, such as `WIN32`, `GOOGLE` or `IOS`. Absent for a Java player and a simulated one. `ClientSystemInfo.platformType` of `@minecraft/server` gives the coarser platform.                                                                                                                                                                                                                        |
| `PlayerIdentity.address`                        | string                    | The IP address the client connected from.                                                                                                                                                                                                                                                                                                                                                                                                                |
| `PlayerIdentity.port`                           | number                    | The port the client connected from.                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `ServerListOptions`                             | interface                 | What `serverList.update` changes. A property left out keeps its value.                                                                                                                                                                                                                                                                                                                                                                                   |
| `ServerListOptions.motd?`                       | string                    | The MOTD, without a `;`.                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `ServerListOptions.levelName?`                  | string                    | The second name, without a `;`.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `ServerListOptions.onlinePlayers?`              | number                    | The online count to show, a whole number from 0 to 2147483647.                                                                                                                                                                                                                                                                                                                                                                                           |
| `ServerListOptions.maxPlayers?`                 | number                    | The player limit to show, a whole number from 0 to 2147483647.                                                                                                                                                                                                                                                                                                                                                                                           |
| `AddonConfigEvents`                             | interface                 | Events about the pack's config file.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `AddonConfigEvents.change`                      | `AddonConfigChangeSignal` | Fires on the first flush after the server's watch reports the settled change to the file, by an editor or by `config.write`. The watch waits for a burst of writes to settle, so one save gives one event.                                                                                                                                                                                                                                               |
| `AddonConfigChangeSignal`                       | interface                 | Subscribes to changes of the config file, as a `@minecraft/server` signal does.                                                                                                                                                                                                                                                                                                                                                                          |
| `AddonConfigChangeSignal.subscribe(callback)`   | function                  | Calls the callback after each change, with the new value. Gives the callback back, for `unsubscribe`.                                                                                                                                                                                                                                                                                                                                                    |
| `AddonConfigChangeSignal.unsubscribe(callback)` | function                  | Stops calling a callback `subscribe` took.                                                                                                                                                                                                                                                                                                                                                                                                               |
| `AddonConfigChangeEvent`                        | interface                 | A change of the config file.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `AddonConfigChangeEvent.value`                  | `unknown`                 | The parsed JSON of the file after the change, frozen, or `undefined` when the file is gone. A file that fails to parse gives the last value.                                                                                                                                                                                                                                                                                                             |
| `PermissionsAfterEvents`                        | interface                 | The events the permission files raise, after the fact.                                                                                                                                                                                                                                                                                                                                                                                                   |
| `PermissionsAfterEvents.permissionsChange`      | `PermissionsChangeSignal` | Fires after any write to the permission files, whoever made it, and after the files are read again on `/reload` or a change on disk.                                                                                                                                                                                                                                                                                                                     |
| `PermissionsChangeSignal`                       | interface                 | Where a pack subscribes to permission changes.                                                                                                                                                                                                                                                                                                                                                                                                           |
| `PermissionsChangeSignal.subscribe(callback)`   | function                  | Calls `callback` after each change, with the player and the group it touched, and returns the callback. A pack's subscriptions end when its scripts stop.                                                                                                                                                                                                                                                                                                |
| `PermissionsChangeSignal.unsubscribe(callback)` | function                  | Stops calling a callback `subscribe` returned.                                                                                                                                                                                                                                                                                                                                                                                                           |
| `PermissionsChangeEvent`                        | interface                 | What a permission change touched.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `PermissionsChangeEvent.target?`                | `PermissionsChangeTarget` | The group or the user the write touched. Absent after the files were read again on `/reload` or a change on disk, which may have changed anything.                                                                                                                                                                                                                                                                                                       |
| `PermissionsChangeTarget`                       | type                      | The group a group write touched, by name, or the user a user write touched, by the name their record shows, with their `Player` while they are online.                                                                                                                                                                                                                                                                                                   |
| `EventPriority`                                 | string                    | When a before-event callback runs among the others of its signal, earliest first. `normal` until a pack sets another. One of `lowest`, `low`, `normal`, `high`, `highest`, `monitor`.                                                                                                                                                                                                                                                                    |
| `BeforeEventSignal`                             | interface                 | A before-event signal of `@minecraft/server`, such as `world.beforeEvents.chatSend`. This names what the module reads, so the pack's own signal types fit.                                                                                                                                                                                                                                                                                               |
| `BeforeEventSignal.subscribe(callback)`         | function                  | Adds a callback, as the signal of `@minecraft/server` does. Typed to take any signal's callback.                                                                                                                                                                                                                                                                                                                                                         |


## Show a boss bar

`bossBars.show` puts a bar on one player's screen and returns it. The pack keeps the bar to change
it with `update` and take it down with `hide`. This one shows the server's ticks per second, the
milliseconds the last tick took and the player's ping, and refreshes once a second:

```js
import { system, world } from '@minecraft/server';

world.afterEvents.worldLoad.subscribe(async () => {
    const jsp = await loadJsprismarine();
    if (jsp === undefined || !('bossBars' in jsp)) return;
    const bars = new Map();
    system.runInterval(() => {
        // A bar is invalid once its player leaves, so dropping those keeps the map to the players online.
        for (const [id, bar] of bars) if (!bar.isValid) bars.delete(id);
        for (const player of world.getAllPlayers()) {
            const { tps, lastTickMs } = jsp.performance;
            const ping = jsp.getPing(player);
            const options = {
                text: `TPS: ${tps.toFixed(1)} MSPT: ${lastTickMs.toFixed(1)} Ping: ${ping ?? '?'}ms`,
                progress: Math.min(1, lastTickMs / 50),
                color: tps >= 19.5 ? 'green' : 'red'
            };
            const bar = bars.get(player.id);
            if (bar?.isValid) bar.update(options);
            else bars.set(player.id, jsp.bossBars.show(player, options));
        }
    }, 20);
});
```

`loadJsprismarine` is the function from [the first example](#detect-the-module-and-fall-back).

A bar belongs to the scripts that showed it. It goes when the player leaves, and every bar goes
when the scripts stop, on `/reload` or at shutdown, so a pack never leaves one behind. A player who
has bars from several packs sees the one shown last, and the one before it again once that one is
hidden. `getPing` answers `undefined` until the player's connection has measured a round trip:
RakNet's from the acknowledgments of its datagrams, NetherNet's from SCTP's under the data
channels.

## Rename a player in the player list

`playerList.setDisplayName` changes the name every client shows for a player in the pause menu's
player list, and nothing else: chat and the name above the head keep the login name. A player who
joins later sees the name too. This one shows each player's ping after their name, refreshed once
a second, and sends a name only when it changed:

```js
import { system, world } from '@minecraft/server';

world.afterEvents.worldLoad.subscribe(async () => {
    const jsp = await loadJsprismarine();
    if (jsp === undefined || !('playerList' in jsp)) return;
    const shown = new Map();
    system.runInterval(() => {
        for (const player of world.getAllPlayers()) {
            const name = `${player.name} §7${jsp.getPing(player) ?? '?'}ms`;
            if (shown.get(player.id) === name) continue;
            shown.set(player.id, name);
            jsp.playerList.setDisplayName(player, name);
        }
    }, 20);
});
```

An empty name throws a `TypeError`. `playerList.reset(player)` gives the entry its login name
back at once, and every name the scripts set reverts when they stop, on `/reload` or at shutdown.
A name set for a player who left changes nothing, and a player who rejoins starts with their login
name again.

## Change what the server list shows

`serverList` changes what a server list shows of the server: the MOTD, the second name and the
two player counts. The change shows the same way however a client asks, in Bedrock's server list
and LAN view, through the query protocol and on Java Edition's multiplayer screen. This one puts
the day in the MOTD, once a second:

```js
import { system, world } from '@minecraft/server';

world.afterEvents.worldLoad.subscribe(async () => {
    const jsp = await loadJsprismarine();
    if (jsp === undefined || !('serverList' in jsp)) return;
    system.runInterval(() => {
        jsp.serverList.update({ motd: `§bMy server §7- day ${world.getDay()}` });
    }, 20);
});
```

A property `update` leaves out keeps its value, and `serverList.reset()` takes every change the
pack made back. The changes also go when the pack's scripts stop, on `/reload` or at shutdown.
Where two packs change one property, the one that changed it last shows, and a reset shows the
other pack's change again. A MOTD or second name with a `;` throws a `TypeError`, since the
Bedrock ping separates its fields with it, and so does a count that is not a whole number.

`maxPlayers` changes only what the list shows: the server still turns a player away at
`max-players`. [The MOTD addon](https://jsprismarine.dev/addons/motd.md) renders the MOTD from
templates with placeholders, colors and animations.

## Identify players

`Player.id` is the entity id of one login, so it changes each time a player joins. `players`
gives a pack the account behind the player instead. `players.identity` reads an online player:
their key, name, XUID and UUID, the edition, protocol version, game version and operating system
of their client, and the address and port they connected from. `players.find` looks up a player
who has joined, online or not. This pack keeps a balance per player under their key:

```js
import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe(async ({ player, initialSpawn }) => {
    if (!initialSpawn) return;
    const jsp = await loadJsprismarine();
    if (jsp === undefined || !('players' in jsp)) return;
    const { key, edition } = jsp.players.identity(player);
    const balance = world.getDynamicProperty(`balance:${key}`) ?? 0;
    player.sendMessage(`Welcome back to ${edition} play, ${player.name}: ${balance} coins`);
});
```

The key names the account the server files permissions, operator status and bans under, in the
form `/perms`, `/op` and `/deop` take: `xbox:` and the XUID of an account Xbox Live verified,
`java:` and the profile UUID of a Java Edition account Mojang verified, or `offline:` and the name
on an offline-mode server. A [linked account](https://jsprismarine.dev/guide/running.md#linked-accounts) has the key of the
account it plays as. Keep a player's own data under the key rather than under the XUID: on an
offline-mode server the client chooses the XUID it sends.

`players.find` takes a key, a name in any case, an XUID or a UUID, and answers the player's
`key`, `name`, `xuid`, `uuid` and `edition`, or `undefined` for a player it does not know. It
reads [the user cache](https://jsprismarine.dev/guide/running.md#the-user-cache), which forgets an account
a month after its last join, so a pack that must find
players for longer keeps what it needs under their key. When several accounts joined under one
name, such as an Xbox account and a Java Edition account, the one that joined last answers; look
up a key to pick one.

A value the server does not know is left out: `xuid` for a player without one, `clientVersion`
when the client reported none, and `deviceOs` for a Java or simulated player. `deviceOs` is the
operating system as the Bedrock login names it, such as `WIN32`, `GOOGLE` or `IOS`;
`player.clientSystemInfo.platformType` of `@minecraft/server` gives the coarser platform, and
`player.inputInfo.lastInputModeUsed` the input mode. `players.identity` throws a `TypeError` for a
player who left. Every pack can read a player's address, so install only packs you trust with it.

## The placeholders module

JSPrismarine has a second module, `@jsprismarine/placeholders`, loaded the same way as
`@jsprismarine/server`: left out of the manifest, with one `import()` inside `try`, so the pack
still runs on BDS, where the import rejects.

```js
/** The placeholder registry, or undefined on a server without it. */
const loadPlaceholders = async () => {
    try {
        return await import('@jsprismarine/placeholders');
    } catch {
        return undefined;
    }
};
```

The split follows one rule. `@jsprismarine/server` holds the members that read or change the
running server and its players: its version, how fast it ticks, a player's ping, a boss bar on a
player's screen. A feature with a type vocabulary of its own, one that would stand as a library by
itself, gets its own `@jsprismarine/<name>` module, and the placeholders are the first. An import
of any other `@jsprismarine/` name rejects with the message BDS gives for an unknown module.

A placeholder is a token such as `{player:ping}` in a text. The module is the registry every pack
shares: one pack registers a namespace with the keys it answers, and any pack renders a text
through `resolve`, so a sidebar, a chat format or a tab list shows the same values without talking
to the pack that computes them. The
[standard placeholders addon](https://jsprismarine.dev/addons/standard-placeholders.md) registers the `player`,
`server` and `world` namespaces most servers want.


| Member                          | Type     | What it is                                                                                                                                                                                                                                                                                                                          |
| ------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `register(namespace, provider)` | function | Registers a namespace. Throws a `TypeError` for a namespace or key that is not lowercase letters, digits and underscores starting with a letter, or for a provider with no keys, and an `Error` for a namespace that is registered already.                                                                                         |
| `resolve(text, player)`         | function | Replaces each `{namespace:key}` in the text with its value, for the player when one is given. A token nobody provides, or whose provider gives `undefined` or throws, stays as written, and so does any other text between braces. The watchdog's errors are the exception: a resolver that runs out of the budget ends the render. |
| `namespaces()`                  | function | Every registered namespace with its keys, oldest first, as a new frozen list each call.                                                                                                                                                                                                                                             |
| `parse(shorthand)`              | function | Parses the shorthand `{player:name} &7{player:ping}ms` into a template: each token a `placeholder` node, the rest `text` nodes, and `&` before a format code `§`.                                                                                                                                                                   |
| `render(template, player)`      | function | Renders a template, or a shorthand string, for the player when one is given: the text, and the tick an animation in it next changes the text. Throws a `TypeError` for a node the renderer does not know or a condition that does not parse.                                                                                        |


Its types, which `@jsprismarine/script-types` declares too. `Player` is `@jsprismarine/server`'s:


| Type                                       | Kind                      | What it is                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------------------------ | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PlaceholderProvider`                      | interface                 | What a pack registers for a namespace: the keys it answers, and the function that answers them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `PlaceholderProvider.keys`                 | `readonly string[]`       | The keys the provider answers, each lowercase letters, digits and underscores starting with a letter. A token with another key stays as written.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `PlaceholderProvider.resolve(key, player)` | function                  | The value of one key, for the player when the text is rendered for one: the pack's own `Player` of `@minecraft/server`, with every member it has. A number renders through `String()`. `undefined` leaves the token as written, and so does a throw, which the content log reports once per namespace. It runs inside the budget of the script that renders, and the watchdog's errors end the render rather than leaving the token.                                                                                                                                                                                                                                                                                                          |
| `PlaceholderRegistration`                  | interface                 | A namespace a pack registered.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `PlaceholderRegistration.unregister()`     | function                  | Takes the namespace out of the registry, so its tokens stay as written. A pack's namespaces go on their own when its scripts stop.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `PlaceholderNamespace`                     | interface                 | One registered namespace.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `PlaceholderNamespace.namespace`           | string                    | Its name, the part of a token before the colon.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `PlaceholderNamespace.keys`                | `readonly string[]`       | The keys its provider answers.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `Template`                                 | interface                 | A template: a tree in the shape of Bedrock's rawtext, the format `/tellraw` takes, with a few more node kinds. `placeholders.parse` makes one from shorthand, and a file or a script can hold one.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `Template.rawtext`                         | `readonly TemplateNode[]` | The nodes, rendered in order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `TemplateNode`                             | type                      | One node of a template: a `text`; a `placeholder` named `namespace:key`; an `if` with a condition over placeholders and literals (`==`, `!=`, `<`, `<=`, `>`, `>=`, `contains`, `startsWith`, joined by `&&` and `\|\|`, with parentheses; two sides that both parse as numbers compare as numbers) and its `then` and `else` nodes; an `animate` with `frames` and an `interval` in ticks; a `gradient` with `#rrggbb` colors over its `rawtext`, each character in the nearest `§` color; and rawtext's `translate`, which renders as its key, `score`, which reads the scoreboard, and `selector`, which reads as the names of the entities the server's selector grammar matches, so `@a[tag=vip]` works. A bare string is a `text` node. |
| `RenderedTemplate`                         | interface                 | What `placeholders.render` gave.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `RenderedTemplate.text`                    | string                    | The rendered text.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `RenderedTemplate.nextChangeTick?`         | number                    | The tick at which an animation in the template next changes the text, so a consumer that refreshes on an interval renders again then. Absent when the template holds no animation with more than one frame.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |


```js
import { world } from '@minecraft/server';

world.afterEvents.worldLoad.subscribe(async () => {
    const [jsp, placeholders] = await Promise.all([loadJsprismarine(), loadPlaceholders()]);
    if (jsp === undefined || placeholders === undefined) return;
    placeholders.register('demo', {
        keys: ['name', 'ping', 'slots'],
        resolve(key, player) {
            if (key === 'slots') return jsp.jsprismarine.maxPlayers;
            if (player === undefined) return undefined;
            return key === 'name' ? player.name : jsp.getPing(player);
        }
    });
});

// Each player who spawns in, the ones online at `worldLoad` included, gets the rendered line.
world.afterEvents.playerSpawn.subscribe(async ({ player, initialSpawn }) => {
    const placeholders = await loadPlaceholders();
    if (!initialSpawn || placeholders === undefined) return;
    player.sendMessage(placeholders.resolve('{demo:name}, your ping is {demo:ping}ms', player));
});
```

A namespace and a key match `[a-z][a-z0-9_]*`: lowercase
letters, digits and underscores, starting with a letter. Any other text between braces is not a
token and stays as written, so there is no escape syntax. A
token nobody provides stays as written too, so a missing addon shows in the text rather than
disappearing from it. The same goes for a key whose resolver gives `undefined`, such as `name`
above when the text is rendered for no player, and for one whose resolver throws: the content log
reports the first throw of each namespace, and the token stays. The watchdog's errors are the
exception: a resolver that runs out of the budget ends the render, as it would end any callback.

A resolver runs inside the budget of the script that renders, so read a value rather than compute
one. A number renders through `String()`. `register` throws a `TypeError` for a malformed name or
a provider without keys, and an `Error` for a namespace that is registered already; `namespaces()`
lists the names in use with their keys. A namespace belongs to the pack that registered it:
`unregister` on the returned registration ends it, and every namespace of a pack goes when its
scripts stop, as on `/reload`.

## Render a template

A template is a tree in the shape of Bedrock's rawtext, the format `/tellraw` takes, with a few
more node kinds, so an owner can write one in a file and a command can take the shorthand.
`placeholders.parse` turns the shorthand `{player:name} &7{player:ping}ms` into a tree, and
`placeholders.render` renders a tree, or the shorthand itself, for a player:

```js
const template = {
    rawtext: [
        { placeholder: 'player:name' },
        { if: '{player:ping} > 150', then: [' §c', { placeholder: 'player:ping' }], else: [' §7', { placeholder: 'player:ping' }] },
        { animate: { interval: 10, frames: [['.'], ['..'], ['...']] } },
        { gradient: { colors: ['#ff5555', '#5555ff'], rawtext: ['VIP'] } }
    ]
};
const { text, nextChangeTick } = placeholders.render(template, player);
```

The node kinds are `text` (a bare string is one), `placeholder`, `if` with `then` and `else`,
`animate` with `frames` and an `interval` in ticks, `gradient` with `#rrggbb` colors over its
`rawtext`, and rawtext's own `translate`, `score` and `selector`. The renderer gives text, so it
renders those three on the server: `translate` as its key, `score` from the scoreboard, and
`selector` as the names of the entities the server's selector grammar matches, so `@a[tag=vip]`
works. A condition compares placeholders and literals with
`==`, `!=`, `<`, `<=`, `>`, `>=`, `contains` and `startsWith`, joined by
`&&` and `||` with parentheses; two sides that both parse
as numbers compare as numbers, otherwise as text. A gradient colors each character with the nearest of Bedrock's `§` colors and ends with
`§r`. `render` throws a `TypeError` for a node it does not know or a condition that does not
parse, and says where in the tree.

`nextChangeTick` is the tick at which an animation in the template next changes the text, the
soonest across every animation with more than one frame the render reached. A consumer that refreshes on an interval
renders again at that tick too, so an animation runs at its own pace and a template without one
costs nothing between refreshes.

## Read the pack's config file

`config` is the pack's config file, `<folder>.config.json` beside the pack's folder, which for an
addon installed as `addons/<name>/` is `addons/<name>.config.json`. `config.value` is the file's
parsed JSON, frozen, or `undefined` while there is no file; `config.write(value)` rewrites it; and
`config.afterEvents.change` fires with the new value on the first flush after the server's watch
reports the change, by an editor or by `write`. The watch waits
150 milliseconds after the last write before it
reads the file once, so an editor's burst of writes gives one event with the final text. A file
that fails to parse keeps the last value, and the content log says so once. The member parses and
nothing more, so the pack checks the shape.
[Writing an addon](https://jsprismarine.dev/guide/writing-addons.md#configure-it) shows the pattern.

## Read and change permissions

`permissions` reads and writes the groups, nodes and meta of `permissions.json`, which
[the running guide](https://jsprismarine.dev/guide/running.md#permissions) describes, resolved the way the server resolves them
for a command. A write persists to the file as `/perms` would, and `afterEvents.permissionsChange`
fires after any write, whoever made it, and after the file is read again. This pack greets a player
with their prefix and primary group, and grants a rank for a day:

```js
import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe(async ({ player, initialSpawn }) => {
    if (!initialSpawn) return;
    const jsp = await loadJsprismarine();
    if (jsp === undefined || !('permissions' in jsp)) return;
    const { permissions } = jsp;
    const prefix = permissions.metaOf(player, 'prefix') ?? '';
    player.sendMessage(`Welcome, ${prefix}${player.name} of ${permissions.primaryGroupOf(player)}`);
    if (!permissions.has(player, 'minecraft.command.me')) {
        const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString();
        permissions.addToGroup(player, 'trial', tomorrow);
    }
});
```

`loadJsprismarine` is the function from [the first example](#detect-the-module-and-fall-back).
`grant`, `revoke`, `addToGroup` and `removeFromGroup` take a `Player` and write that player's
record; `grantToGroup` and `revokeFromGroup` take a group's name and write the group. A bad node
or expiry throws a `RangeError` at the call, a group the file lacks an `Error`, and a `Player` who
left a `TypeError`, before anything is written. The write itself lands later: it joins the
server's queue of permission writes, reaches the file and then the server's own view, so `has`
right after `grant` can still answer the old value. Subscribe to `afterEvents.permissionsChange`
to act once a write has landed; a write that fails to reach the file is logged by the server and
does not throw at the call. The server also
registers the `perms` placeholder namespace with `primary_group`, `groups`, `prefix`, `suffix`
and `weight`, so a tab list or chat format reads a rank through `placeholders.resolve` without a
call; an unset prefix or suffix renders as empty text.

## Manage levels

`levels` lists the server's levels and moves players between them, and creates, attaches and
detaches levels as `/world` does ([Managing worlds while the server
runs](https://jsprismarine.dev/guide/running.md#managing-worlds-while-the-server-runs)). A level is named by its name or its
UUID. This pack sends a player who types `!arena` to a level, creating it the first time:

```js
import { world } from '@minecraft/server';

world.beforeEvents.chatSend.subscribe((event) => {
    if (event.message !== '!arena') return;
    event.cancel = true;
    void (async () => {
        const jsp = await loadJsprismarine();
        if (jsp === undefined || !('levels' in jsp)) return;
        const { levels } = jsp;
        if (!levels.list().some((level) => level.name === 'arena')) {
            await levels.create('arena', { preset: 'minecraft:flat' });
        }
        await levels.transfer(event.sender, 'arena');
    })();
});
```

`current`, `list` and `levelOf` answer at once. `transfer`, `create`, `attach` and `detach` take
a while, so each answers a promise that settles on a script tick after the server finishes.
A promise rejects with the server's message for a level that is not attached, a name that is
taken, or a level that cannot be detached. Scripts run once in each level, so a pack every level
loads sees each level's `current`. Detaching the pack's own level stops its scripts there, and
that promise never settles.

## Order before-event callbacks across packs

Bedrock runs the callbacks of a before-event in the order they subscribed, whichever pack they
come from. Every callback gets the same event, so one sees the `cancel` and the values the ones
before it set, and the last one to write decides. `events.setPriority` lets a pack choose where
its callback runs. This protection pack has the final say over block breaks near the world's
center, whatever another pack's callback decided:

```js
import { world } from '@minecraft/server';

const protect = (event) => {
    const { x, z } = event.block.location;
    if (Math.abs(x) < 64 && Math.abs(z) < 64 && !event.player.hasTag('builder')) event.cancel = true;
};
world.beforeEvents.playerBreakBlock.subscribe(protect);

loadJsprismarine().then((jsp) => {
    if (jsp !== undefined && 'events' in jsp) {
        jsp.events.setPriority(world.beforeEvents.playerBreakBlock, protect, 'highest');
    }
});
```

Subscribe the callback as usual, then give it a priority. On Bedrock Dedicated Server the module
is absent, the pack skips the call, and the callback runs in subscription order.

The priorities, from first to last, are
`lowest`, `low`, `normal`, `high`, `highest` and `monitor`.
A callback starts at `normal`, so with no priority set the order is Bedrock's. Callbacks of one
priority keep the order they subscribed in. A `monitor` callback runs last and sees the outcome
but cannot change it: once it returns, the server puts back `cancel` and every value it set, such
as a chat message, so the next callback and the server see the outcome the others left. Use it to
log or count what happens.

A priority belongs to the subscription. `unsubscribe` ends it, and subscribing the callback again
starts at `normal`. After-events take no priority: they fire only for what happened, so their
order changes nothing. `setPriority` throws a `TypeError` for an after-event signal, a callback the
pack has not subscribed to the signal, and a priority not on the list.

Later JSPrismarine versions add members. To use one that an older server may lack, check for it
before you call it, the same way you check for the module:

```js
const jsp = await loadJsprismarine();
if (jsp !== undefined && 'someNewMember' in jsp) {
    // JSPrismarine new enough to have it
}
```

## Types for TypeScript

`@jsprismarine/script-types` holds the declarations of both modules. The npm name
`@jsprismarine/server` belongs to the server package, so the declarations package has its own name
and declares the modules inside. Add it to `types` in your `tsconfig.json`, and
`import('@jsprismarine/server')` and `import('@jsprismarine/placeholders')` are typed:

```json
{
    "compilerOptions": {
        "types": ["@jsprismarine/script-types"]
    }
}
```

Install it as a development dependency of your pack's project:

```bash
npm install --save-dev @jsprismarine/script-types
```

Its `dist/index.d.ts` comes from the same definition the server builds the module from.
