# TPS Bar

Shows TPS, MSPT and ping, memory, or a compass on a boss bar.

Install it from the server console with `addon install tps-bar`.

- Version: 1.2.1, released Not released yet
- Runs on: JSPrismarine 0.23.0 or newer
- Published by: JSPrismarine ([source](https://github.com/JSPrismarine/JSPrismarine/tree/master/addons/tps-bar), [issues](https://github.com/JSPrismarine/JSPrismarine/issues))
- Written by: JSPrismarine
- License: (MIT OR MPL-2.0)
- Tags: Performance
- Pack SHA-256: `ab760a6e57ba855590104f5c9db23b9f664ccc2d753e99a7010839cbe7f84a96`

## Commands

Each command's name is also its permission node in `permissions.json`. With no entry for the node, the command's level decides, so a command above level 0 needs an operator or a `level` meta. An entry that grants the node lets a player run the command at any level, and a node with a leading `-` takes it away, even from an operator. [The command reference](https://jsprismarine.dev/guide/commands.md#who-can-run-a-command) explains both.

| Command | Description | Permission | Level | Granted to |
| --- | --- | --- | --- | --- |
| `/jsp:tpsbar`, also `/tpsbar` | Shows or hides a bar with the server's TPS, MSPT and your ping. | `jsp:tpsbar` | 1 | Operators |
| `/jsp:rambar`, also `/rambar` | Shows or hides a bar with the memory the server's heap uses. | `jsp:rambar` | 1 | Operators |
| `/jsp:compass`, also `/compass` | Shows or hides a bar with the directions around where you face. | `jsp:compass` | 1 | Operators |

To let every player run `/jsp:tpsbar`, type `perms group default permission set jsp:tpsbar` on the console.

## README

From the addon's README.md, version 1.2.1.

Boss bars that show how the server keeps up: its ticks per second (TPS), the milliseconds each
tick's work takes (MSPT) and your ping, the memory its heap holds, and a compass. The RAM bar and
the compass follow [Purpur](https://purpurmc.org/)'s, as [Purpur Bars](https://modrinth.com/plugin/purpur-bars)
brings them to other servers.

![The TPS bar three times: green with an idle server, gold at 32 MSPT, and red at 65 MSPT and 15 TPS](https://jsprismarine.dev/repo/addons/tps-bar/media/bar.png)

## Using it

An operator runs a bar's command to turn it on, and again to turn it off:

- `/tpsbar`: TPS, MSPT and ping.
- `/rambar`: the memory the server's heap holds.
- `/compass`: the directions around where you face.

To let every player use one, grant its node, `jsp:tpsbar`, `jsp:rambar` or `jsp:compass`, to the
`default` group in `permissions.json`, or run `/perms group default permission set jsp:tpsbar`.

A bar is theirs alone: each player turns it on for themselves. The server remembers the choice, so
the bar comes back when they rejoin and after a restart. A player can have every bar on at once.

Java Edition players see the same bars, with the ping their keep-alives measure.

### The TPS bar

The bar redraws once a second. Each number is colored by its own thresholds:


| Number    | Green        | Gold       | Red         |
| --------- | ------------ | ---------- | ----------- |
| TPS       | 19.5 or more | 15 or more | below 15    |
| MSPT      | below 25     | below 50   | 50 or more  |
| Ping (ms) | below 100    | below 200  | 200 or more |


The bar takes the worse of the two colors, in green, yellow or red. It fills as MSPT
approaches 50, the milliseconds a tick has
at 20 TPS, so a full bar means the server cannot keep up.

The ping does not change the bar's color, since it says how your connection keeps up rather than
the server.

MSPT is the average over the last ten or so ticks rather than the last tick alone, so one slow
tick does not turn the bar red for a whole second. Ping shows `?` until your connection has
measured a round trip.

### The RAM bar

The bar shows the bytes the server's JavaScript heap holds out of the most it may grow to, and the
share that makes, such as `RAM: 512M/4.0G (12%)`. It fills with that share and redraws once a
second. Buffers outside the heap, such as chunk data, are not counted. Like Purpur's, the numbers
and the bar turn at different shares:


| Share of the limit in use | Green     | Gold or yellow | Red         |
| ------------------------- | --------- | -------------- | ----------- |
| The numbers               | below 60% | below 85%      | 85% or more |
| The bar                   | below 50% | below 75%      | 75% or more |


### The compass

The bar shows a strip of directions centered on where you face, with `S`, `SW`, `W` and so on
between markers, and turns with you four times a second.

## The config file

The addon writes `addons/tps-bar.config.json`, beside the addon's folder, the first time it loads,
and adds any setting the file lacks:

| Key                   | Default                                                                         | What it does                                                                                           |
| --------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `showTpsBarByDefault` | `false` | Shows the TPS bar to every player who has not turned it off with `/tpsbar`. |

The server watches the file, so a change takes effect without a restart. A player's own choice
always wins over the default. On a JSPrismarine too old to give addons config files, there is no file
and the TPS bar stays off until a player turns it on.

## Installing it

From the server console:

```text
addon install tps-bar
```

It needs JSPrismarine 0.23.0 or newer. The RAM
bar needs a release whose `performance` reports the heap, and on an older one `/rambar` says so.
The pack also loads on Bedrock Dedicated Server, where each command says its bar needs
JSPrismarine, since only JSPrismarine gives scripts these figures.
