@@ -61,7 +61,7 @@ player_uuid VARCHAR (36) NOT NULL PRIMARY KEY,
6161 messages_disabled BOOLEAN NOT NULL
6262 );""" );
6363 playerSettingsInitStatement .execute ();
64- updateDatabaseColumns ();
64+ updateDatabaseColumns (). join () ;
6565 } catch (SQLException e ) {
6666 logger .warn ("Failed to connect to database: {}" , e .getMessage (), e );
6767 }
@@ -169,20 +169,26 @@ public void updateSettings(UUID playerUUID, boolean socialSpyEnabled, boolean me
169169
170170 }
171171
172- private void updateDatabaseColumns () {
173- if (ConfigHandler .getInstance ().isMysqlEnabled ()) {
174- doesMysqlColumnExist ("blocklist" , "blocked_player_name" ).thenAccept (exists -> {
175- if (!exists ) {
176- addColumn ("blocklist" , "blocked_player_name" , "VARCHAR(256)" , "" );
172+ private CompletableFuture <Boolean > updateDatabaseColumns () {
173+ return CompletableFuture .supplyAsync (() -> {
174+ String tableName = "blocklist" ;
175+ String columnName = "blocked_player_name" ;
176+ boolean columnExists ;
177+ try {
178+ if (ConfigHandler .getInstance ().isMysqlEnabled ()) {
179+ columnExists = doesMysqlColumnExist (tableName , columnName ).get ();
180+ } else {
181+ columnExists = doesSqliteColumnExist (tableName , columnName ).get ();
177182 }
178- });
179- } else {
180- doesSqliteColumnExist ("blocklist" , "blocked_player_name" ).thenAccept (exists -> {
181- if (!exists ) {
182- addColumn ("blocklist" , "blocked_player_name" , "VARCHAR(256)" , "" );
183+ if (!columnExists ) {
184+ addColumn (tableName , columnName , "VARCHAR(256)" , "" );
183185 }
184- });
185- }
186+ } catch (Exception e ) {
187+ logger .warn ("Unable to update database table: {} column: {}, error: {}" , tableName , columnName , e .getMessage (), e );
188+ return false ;
189+ }
190+ return true ;
191+ });
186192 }
187193
188194 private CompletableFuture <Boolean > doesSqliteColumnExist (String tableName , String columnName ) {
@@ -219,7 +225,7 @@ private CompletableFuture<Boolean> doesMysqlColumnExist(String tableName, String
219225 // Possibly extremely cursed way to do this :cackle:
220226
221227 private void addColumn (String tableName , String columnName , String dataType , String constraints ) {
222- String query = "ALTER TABLE " + tableName + " ADD COLUMN " + columnName + dataType + constraints + ";" ;
228+ String query = String . format ( "ALTER TABLE %s ADD COLUMN %s %s %s;" , tableName , columnName , dataType , constraints ) ;
223229 try (Connection connection = getConnection ()) {
224230 PreparedStatement statement = connection .prepareStatement (query );
225231 statement .executeUpdate ();
0 commit comments