EssentialsC / Expansions / MySQL Database Expansion

MySQL Database Expansion

Cross-server synchronisation of economy balances using a shared MySQL database.

Overview

The MySQL Database Expansion connects multiple EssentialsC server instances through a shared MySQL database, which acts as the authoritative network store. It is distributed as its own JAR (named EssentialsC-MySQLExpansion) and declares a hard dependency on EssentialsC; if EssentialsC is missing or disabled, the expansion refuses to load.

Balance synchronisation is the implemented channel. Online players' balances are diffed and pushed to the network store on a short timer, offline players' balances are mirrored in both directions, and the local EssentialsC economy can be kept in step with the network so /balance and /baltop reflect balances earned on other servers.

The MySQL database must already exist. The expansion creates its tables automatically, but does not create the database itself.

Installation

The expansion is a standard Bukkit plugin JAR that depends on EssentialsC being loaded first.

1

Install EssentialsC

Make sure EssentialsC is installed and running on every server in your network. The economy module must be enabled in EssentialsC's config.yml.

2

Create the MySQL database

Create a database and user on your MySQL server. Write the credentials into the expansion config before first start.

3

Download the expansion JAR

Download EssentialsC-MySQLExpansion-v<version>.jar from the GitHub Releases page.

4

Drop it into your plugins folder

Place the JAR into each server's /plugins directory alongside EssentialsC.

5

Configure the connection

Edit the generated /plugins/EssentialsC-MySQLExpansion/config.yml with your MySQL credentials. Optionally set a human-readable server-id; leave it blank to have one generated automatically.

6

Restart the server

Restart all servers in your network. The console reports whether the connection succeeded and whether economy sync initialised.


Configuration

All settings live in /plugins/EssentialsC-MySQLExpansion/config.yml. A default file is generated on first run.

config.yml
mysql:
  host: localhost
  port: 3306
  database: essc_test_01
  username: root
  password: 'minecraft'

  # Table prefix so multiple networks can share one database safely.
  table-prefix: 'essc_test_01'

  pool:
    maximum-pool-size: 10
    minimum-idle: 2
    connection-timeout-ms: 30000
    idle-timeout-ms: 600000
    max-lifetime-ms: 1800000
    properties:
      useSSL: false
      autoReconnect: true
      characterEncoding: UTF-8

# Unique identifier for this server. Blank = generated automatically.
server-id: 'survival-01'

debug: true

sync:
  economy:
    enabled: true
    pull-on-join: true
    push-on-quit: true
    push-interval-seconds: 2
    sync-local: true
    mirror-interval-seconds: 5
    baltop-page-size: 10
Key Type Default Description
mysql.host String localhost JDBC host of your MySQL server.
mysql.port Integer 3306 JDBC port (the MySQL default).
mysql.database String essentialsc Database the expansion uses. It must already exist.
mysql.username String root MySQL authentication username.
mysql.password String "" MySQL authentication password.
mysql.table-prefix String essc_net_ Prefix prepended to table names so multiple networks can share one database.
mysql.pool.maximum-pool-size Integer 10 HikariCP maximum pool size.
mysql.pool.minimum-idle Integer 2 HikariCP minimum idle connections.
mysql.pool.connection-timeout-ms Long 30000 Time to wait for a connection before failing.
mysql.pool.idle-timeout-ms Long 600000 Maximum time an idle connection is kept.
mysql.pool.max-lifetime-ms Long 1800000 Maximum lifetime of a pooled connection.
server-id String generated UUID Identifier for this server in the network. Used for diagnostics; a random UUID is generated and persisted if left blank.
debug Boolean false Enable verbose debug logging to the console.
sync.economy.enabled Boolean true Enable the economy sync channel.
sync.economy.pull-on-join Boolean true Pull the network balance into the local economy when a player joins.
sync.economy.push-on-quit Boolean true Push the local balance to the network store when a player quits.
sync.economy.push-interval-seconds Integer 2 How often online players' balances are diffed and pushed to MySQL whenever they change.
sync.economy.sync-local Boolean true Mirror the local EssentialsC economy from the network for offline players so /balance and /baltop reflect network balances.
sync.economy.mirror-interval-seconds Integer 5 How often the local-to-network mirror runs.
sync.economy.baltop-page-size Integer 10 Number of entries shown per page by /mysql baltop.
The config can be reloaded at runtime with /mysql reload – no server restart needed.

Economy Sync

The economy sync engine treats MySQL as the authoritative network store. Two background tasks keep the network and local economies in step.

Push Cycle (default every 2 seconds)

The push task iterates every player currently online on this server and compares their current local balance to the last value pushed to MySQL. If the balance has changed, the new value is written to the network table. EssentialsC does not expose a balance-change event, so changes are detected by diffing on this timer – a small interval means other servers see earnings almost immediately without the player having to join them.

Mirror Cycle (default every 5 seconds)

When sync.economy.sync-local is enabled, the mirror task fetches all network balances and reconciles them with local data for players who are not online on this server. If the local balance diverges from the last known network value, the local economy is updated so EssentialsC's own /balance and /baltop reflect network balances for players who never joined this server.

Join & Quit Handling

When a player joins, the expansion pulls their network balance and applies it locally if one exists, otherwise it keeps the local value. When a player quits, their final local balance is pushed to the network store immediately. On shutdown, every online player's balance is flushed to MySQL before the connection is closed.

Economy sync only runs when EssentialsC's economy module is enabled. If it is disabled, the expansion logs a warning and the sync channel stays off.

Commands

Command Description Permission
/mysql status Shows connection state, database host/port, server ID, economy sync state, number of synced players, and expansion uptime. esscmysql.use
/mysql version Shows the expansion version, MySQL host/port, database, table prefix, server ID, and the enabled state of each sync channel. esscmysql.use
/mysql baltop [page] Shows the network-wide balance leaderboard, one page at a time. esscmysql.use
/mysql reload Reloads config.yml, reconnects the pool, and restarts the sync engine. esscmysql.admin
/mysql test Tests the MySQL connection and reports the round-trip latency. esscmysql.admin
/mysql push <player|all> Immediately pushes one player's or every online player's balance to MySQL. esscmysql.admin
/mysql pull <player|all> Immediately pulls one player's or every online player's balance from MySQL and applies it locally. esscmysql.admin
/mysql help Lists the sub-commands available to you. none

Permissions

Permission Description Default
esscmysql.use Access to the read-only commands: status, version, baltop, and help. Everyone
esscmysql.admin Access to the management commands: reload, test, push, and pull. Operators

Database Schema

The expansion creates a single table, named <table-prefix>network_balances, on first connection. It is created with CREATE TABLE IF NOT EXISTS – no manual schema setup is required. Balance values are stored as DECIMAL(20,2).

SQL
CREATE TABLE IF NOT EXISTS `<prefix>network_balances` (
  `uuid`         CHAR(36)      NOT NULL,
  `username`     VARCHAR(64)   NOT NULL,
  `balance`      DECIMAL(20,2) NOT NULL DEFAULT 0.00,
  `server_id`    VARCHAR(64)   NOT NULL,
  `last_updated` BIGINT       NOT NULL,
  PRIMARY KEY (`uuid`)
)

Writes use INSERT ... ON DUPLICATE KEY UPDATE, so each player has exactly one row keyed by their UUID.

Home, warp, nickname, punishment, and kit synchronisation are not implemented yet. Config toggles and /mysql version report them as future channels; only the economy channel is currently synced.