Skip to content

Commit

Permalink
fix: fix wrong timezone configuration when connecting to database by …
Browse files Browse the repository at this point in the history
…making it configurable
  • Loading branch information
Misat11 committed Nov 21, 2023
1 parent 1f47d86 commit 5fc4ffb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion plugin/src/main/java/org/screamingsandals/bedwars/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ public void onEnable() {
databaseManager = new DatabaseManager(configurator.config.getString("database.host"),
configurator.config.getInt("database.port"), configurator.config.getString("database.user"),
configurator.config.getString("database.password"), configurator.config.getString("database.db"),
configurator.config.getString("database.table-prefix", "bw_"), configurator.config.getBoolean("database.useSSL"));
configurator.config.getString("database.table-prefix", "bw_"), configurator.config.getBoolean("database.useSSL"),
configurator.config.getBoolean("database.add-timezone-to-connection-string"),
configurator.config.getString("database.timezone-id"));

if (isPlayerStatisticsEnabled()) {
playerStatisticsManager = new PlayerStatisticManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ public void createFiles() {
checkOrSetConfig(modify, "database.user", "root");
checkOrSetConfig(modify, "database.password", "secret");
checkOrSetConfig(modify, "database.table-prefix", "bw_");
checkOrSetConfig(modify, "database.add-timezone-to-connection-string", true);
checkOrSetConfig(modify, "database.timezone-id", TimeZone.getDefault().getID());
checkOrSetConfig(modify, "database.useSSL", false);

checkOrSetConfig(modify, "bossbar.use-xp-bar", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ public class DatabaseManager {
private int port;
private String user;
private boolean useSSL;
private boolean addTimezone;
private String timezoneID;

public DatabaseManager(String host, int port, String user, String password, String database, String tablePrefix, boolean useSSL) {
public DatabaseManager(String host, int port, String user, String password, String database, String tablePrefix, boolean useSSL, boolean addTimezone, String timezoneID) {
this.host = host;
this.port = port;
this.user = user;
this.password = password;
this.database = database;
this.tablePrefix = tablePrefix;
this.useSSL = useSSL;
this.addTimezone = addTimezone;
this.timezoneID = timezoneID;
}

public void initialize() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database
+ "?autoReconnect=true&serverTimezone=" + TimeZone.getDefault().getID() + "&useSSL=" + useSSL);
+ "?autoReconnect=true" + (addTimezone && timezoneID != null ? "&serverTimezone=" + timezoneID : "") + "&useSSL=" + useSSL);
config.setUsername(this.user);
config.setPassword(this.password);
config.addDataSourceProperty("cachePrepStmts", "true");
Expand Down

0 comments on commit 5fc4ffb

Please sign in to comment.