@@ -40,17 +40,8 @@ public class MySQLStorageProvider extends StorageProvider {
4040
4141 private boolean isLoaded = false ;
4242
43- // TODO implement MySQL provider
4443 public MySQLStorageProvider (Autorank instance ) {
4544 super (instance );
46-
47- // Initialise provider to make it ready for use.
48- if (!this .initialiseProvider ()) {
49- plugin .debugMessage ("There was an error loading storage provider '" + getName () + "'." );
50- isLoaded = false ;
51- }
52-
53- isLoaded = true ;
5445 }
5546
5647 @ Override
@@ -124,23 +115,33 @@ public String getName() {
124115 }
125116
126117 @ Override
127- public boolean initialiseProvider () {
118+ public CompletableFuture < Boolean > initialiseProvider () {
128119
129- // Load table names
130- loadTableNames ();
120+ return CompletableFuture .supplyAsync (() -> {
121+ // Load table names
122+ loadTableNames ();
131123
132- // Load settings from settings file.
133- loadMySQLVariables ();
124+ // Load settings from settings file and initialize MySQL connection .
125+ try {
126+ if (!loadMySQLVariables ().get ()) {
127+ return false ;
128+ }
129+ } catch (InterruptedException | ExecutionException e ) {
130+ e .printStackTrace ();
131+ return false ;
132+ }
134133
135- // Check whether loading was successful.
136- if (mysqlLibrary == null ) {
137- return false ;
138- }
134+ // Check whether loading was successful.
135+ if (mysqlLibrary == null ) {
136+ return false ;
137+ }
139138
140- // Load and create tables
141- createTables ();
139+ // Load and create tables
140+ createTables ();
142141
143- return true ;
142+ isLoaded = true ;
143+ return true ;
144+ });
144145 }
145146
146147 @ Override
@@ -313,34 +314,34 @@ private void loadTableNames() {
313314 /**
314315 * Grab the credentials defined in the Setting config and initialise connection to MySQL database.
315316 */
316- private void loadMySQLVariables () {
317+ private CompletableFuture < Boolean > loadMySQLVariables () {
317318
318- final SettingsConfig configHandler = plugin .getSettingsConfig ();
319+ return CompletableFuture .supplyAsync (() -> {
320+ final SettingsConfig configHandler = plugin .getSettingsConfig ();
319321
322+ if (!configHandler .useMySQL ()) {
323+ plugin .getLogger ().warning ("Autorank is trying to register a MySQL storage provider, but MySQL is " +
324+ "disabled in the settings file!" );
325+ return false ;
326+ }
320327
321- if (!configHandler .useMySQL ()) {
322- plugin .getLogger ().warning ("Autorank is trying to register a MySQL storage provider, but MySQL is " +
323- "disabled in the settings file!" );
324- return ;
325- }
326-
327- hostname = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .HOSTNAME );
328- username = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .USERNAME );
329- password = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .PASSWORD );
330- database = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .DATABASE );
328+ hostname = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .HOSTNAME );
329+ username = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .USERNAME );
330+ password = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .PASSWORD );
331+ database = configHandler .getMySQLCredentials (SettingsConfig .MySQLCredentials .DATABASE );
331332
332- mysqlLibrary = new SQLDataStorage (hostname , username , password , database );
333+ mysqlLibrary = new SQLDataStorage (hostname , username , password , database );
333334
334- plugin .getServer ().getScheduler ().runTaskAsynchronously (plugin , () -> {
335335 if (!mysqlLibrary .connect ()) {
336336 mysqlLibrary = null ;
337337 plugin .getLogger ().severe ("Could not connect to " + hostname );
338338 plugin .debugMessage (ChatColor .RED + "Could not connect to MYSQL!" );
339+ return false ;
339340 } else {
340341 plugin .debugMessage (ChatColor .RED + "Successfully established connection to " + hostname );
342+ return true ;
341343 }
342344 });
343-
344345 }
345346
346347 /**
0 commit comments