> For the complete documentation index, see [llms.txt](https://edseries-plugins.gitbook.io/p/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edseries-plugins.gitbook.io/p/edmortars/getting-started/storage.md).

# Storage (YAML / MySQL)

EdMortars saves each player's unlocked mortar types, upgrade levels and cooldowns of a minute or more. Shorter cooldowns between shots are kept in memory only.

## Choosing the storage

```yaml
storage:
  type: yaml          # yaml (default) or mysql
  mysql:
    host: 'localhost'
    port: 3306
    database: 'minecraft'
    username: 'root'
    password: ''
    table-prefix: 'edmortars_'
    use-ssl: false
    properties: 'useUnicode=true&characterEncoding=utf8&serverTimezone=UTC'
```

| Type    | Where the data goes                                                                       |
| ------- | ----------------------------------------------------------------------------------------- |
| `yaml`  | One file per player: `plugins/EdMortars/data/<uuid>.yml`. The default; nothing to set up. |
| `mysql` | A MySQL or MariaDB database. Several servers can share it.                                |

`storage` is read once at startup: restart the server after changing it (`/edmortars reload` doesn't switch it).

### MySQL

* No extra download: EdMortars uses the MySQL driver that Paper already ships (or the MariaDB driver if that one is missing).
* The tables are created on start: `<prefix>players`, `<prefix>unlocked`, `<prefix>levels` and `<prefix>cooldowns` (InnoDB, utf8mb4, keyed by the player UUID).
* `table-prefix` may only contain letters, digits and `_`.
* `properties` are extra JDBC URL parameters (`key=value&key=value`). A 5 second connect timeout and a 30 second socket timeout are added unless you set `connectTimeout` / `socketTimeout` yourself.
* **If EdMortars can't connect on start**, it logs a clear error with the host, port and database, and uses the YAML files instead, so the server still runs. Fix the settings and restart.
* If the connection drops while the server runs, it is reopened on the next save or load. Changed data stays in memory and is saved again on the next try; players whose data couldn't be loaded are retried every 10 seconds.

## How data is loaded and saved

* A player's data is loaded before they join (async pre-login), so their mortar is ready when their mine loads.
* Only players whose data changed are saved: every `save-interval` seconds, when they unlock or upgrade, when they quit and when the server stops.
* Every save (and with MySQL every database call) runs on one background thread, in order, never on the main thread.

## Several servers on one database

With `type: mysql` a player's data is always read again from the database when they join, so a copy cached before they played on another server is never used. Each server saves the player when they leave.

The same player should not be online on two servers that share the database at the same time: each server would save its own copy and the last save wins. A normal proxy (BungeeCord / Velocity) already keeps a player on one server at a time.

## Moving data between YAML and MySQL

```
/edmortars migrate yaml mysql
/edmortars migrate mysql yaml
```

The command copies every stored player from the first storage to the second, in the background, and reports how many players it copied. Changed data of online players is saved first. The MySQL settings come from the current `config.yml`, so you can fill the database before switching. Existing players in the target storage are overwritten; nothing is deleted from the source.

Switching from YAML to MySQL:

1. Fill in `storage.mysql` in `config.yml` (keep `type: yaml`) and run `/edmortars reload`.
2. Run `/edmortars migrate yaml mysql` and wait for the "Copied the data of N player(s)" message.
3. Set `storage.type: mysql` and restart.

Do it while the server is quiet: changes made between the migration and the restart are only in the old storage. The YAML files stay in `plugins/EdMortars/data/` as a backup.
