Database β Configuration
database.yml
Section titled βdatabase.ymlβ# Master switch. Plugin runs without a database when false.enabled: false
# Backend type: MYSQL or POSTGRESQLtype: MYSQL
host: localhostport: 3306database: minecraftusername: rootpassword: ""
pool: maximum-pool-size: 10 connection-timeout-ms: 30000
# Extra JDBC driver properties (optional)properties: useSSL: "false" characterEncoding: "utf8"Keep
database.ymlout of version control when it contains real credentials. Add it to.gitignore.
DatabaseConfig
Section titled βDatabaseConfigβDatabaseConfig is a typed AbstractConfig wrapper over database.yml. It reads all connection settings and assembles a DatabaseCredentials record:
DatabaseConfig config = new DatabaseConfig(plugin);
boolean enabled = config.enabled();DatabaseType type = config.type(); // MYSQL or POSTGRESQLDatabaseCredentials creds = config.credentials();DatabaseCredentials is an immutable record:
record DatabaseCredentials( String host, int port, String database, String username, String password, int maximumPoolSize, long connectionTimeoutMs, Map<String, String> properties)DatabaseManager
Section titled βDatabaseManagerβDatabaseManager (a Service) wraps everything:
// Construction (in DatabaseModule.onEnable):SchedulerService scheduler = service(SchedulerService.class);DatabaseManager dbManager = new DatabaseManager(plugin, new DatabaseConfig(plugin), scheduler.asyncExecutor());dbManager.start(); // connects + applies schema if enabledprovide(DatabaseManager.class, dbManager);
// Usage anywhere else:DatabaseManager db = service(DatabaseManager.class);Database database = db.database(); // throws if disabledOptional<Database> safe = db.optional(); // safe accessboolean active = db.isEnabled();DatabaseModule.onDisable() calls dbManager.close() to shut down the HikariCP pool gracefully.
Choosing pool size
Section titled βChoosing pool sizeβ| Server size | Recommended maximum-pool-size |
|---|---|
| Development / single-node small server | 5 |
| Medium server (< 100 concurrent players) | 10 |
| Large server or shared DB | 20+ |
HikariCP recommends: pool size = (number of CPU cores * 2) + disk spindles.