Allow arbitrary MySQL JDBC connection properties in config.yml

storage.mysql.properties is now a free-form map merged into the JDBC
URL as ?key=value&key=value..., letting hosts that require TLS set
things like sslMode: REQUIRED, or override the useSSL/autoReconnect
defaults, without needing a code change for every possible parameter.
This commit is contained in:
Michael Burgess
2026-08-09 12:44:33 -04:00
parent ca0747196e
commit 2d47962ea1
3 changed files with 32 additions and 2 deletions
@@ -76,7 +76,24 @@ public class StargatePlugin extends JavaPlugin {
String user = getConfig().getString("storage.mysql.username", "stargate");
String pass = getConfig().getString("storage.mysql.password", "");
String prefix = getConfig().getString("storage.mysql.table-prefix", "stargate_");
String url = "jdbc:mysql://" + host + ":" + port + "/" + db + "?useSSL=false&autoReconnect=true";
// Sane defaults, overridable (or removable) via storage.mysql.properties in config.yml -
// e.g. sslMode: REQUIRED, serverTimezone: UTC, useSSL: false, allowPublicKeyRetrieval: true.
java.util.LinkedHashMap<String, String> params = new java.util.LinkedHashMap<>();
params.put("useSSL", "false");
params.put("autoReconnect", "true");
var propsSection = getConfig().getConfigurationSection("storage.mysql.properties");
if (propsSection != null) {
for (String key : propsSection.getKeys(false)) {
params.put(key, String.valueOf(propsSection.get(key)));
}
}
StringBuilder query = new StringBuilder();
for (var entry : params.entrySet()) {
query.append(query.isEmpty() ? '?' : '&');
query.append(entry.getKey()).append('=').append(entry.getValue());
}
String url = "jdbc:mysql://" + host + ":" + port + "/" + db + query;
return new SqlGateStorage(SqlGateStorage.Driver.MYSQL, url, user, pass, prefix, getLogger());
}
File dataFile = new File(getDataFolder(), "gates.db");
@@ -17,6 +17,15 @@ storage:
username: stargate
password: ""
table-prefix: "stargate_"
# Extra JDBC connection parameters, appended to the URL as ?key=value&key=value.
# Defaults to useSSL: false and autoReconnect: true if you don't set them here -
# any key you list overrides that default (e.g. set useSSL: true and add sslMode
# to actually require TLS). Values are written into the URL as-is.
properties:
# useSSL: true
# sslMode: REQUIRED
# serverTimezone: UTC
# allowPublicKeyRetrieval: true
# Enables sending players to another backend server when they dial a gate whose
# server-id differs from this one. Requires the stargate-velocity or stargate-bungee