Skip to content

Commit

Permalink
Make plugin more resilient to db startup problems
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Mar 28, 2020
1 parent 67d7d02 commit fc73e37
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion MarriageMaster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>mvdw-software</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public class Database extends BaseDatabase<MarriageMaster, MarriagePlayerData, M
public Database(@NotNull MarriageMaster plugin)
{
super(plugin, plugin.getLogger(), new PlatformSpecific(plugin), plugin.getConfiguration(), plugin.getDescription().getName(), plugin.getDataFolder(), plugin.getConfiguration().isBungeeEnabled(), false);
unCacheStrategie = UnCacheStrategie.getUnCacheStrategie(cache);
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
if(!plugin.getConfiguration().isBungeeEnabled() || plugin.getServer().getOnlinePlayers().size() > 0)
if(available())
{
new Thread(loadRunnable).start(); // Load async
unCacheStrategie = UnCacheStrategie.getUnCacheStrategie(cache);
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
if(!plugin.getConfiguration().isBungeeEnabled() || plugin.getServer().getOnlinePlayers().size() > 0)
{
new Thread(loadRunnable).start(); // Load async
}
}
else unCacheStrategie = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public class Database extends BaseDatabase<MarriageMaster, MarriagePlayerData, M
public Database(MarriageMaster plugin)
{
super(plugin, plugin.getLogger(), new PlatformSpecific(plugin), plugin.getConfig(), plugin.getDescription().getName(), plugin.getDataFolder(), true, true);
unCacheStrategie = UnCacheStrategie.getUnCacheStrategie(cache);
plugin.getProxy().getPluginManager().registerListener(plugin, this);
loadRunnable.run();
if(available())
{
unCacheStrategie = UnCacheStrategie.getUnCacheStrategie(cache);
plugin.getProxy().getPluginManager().registerListener(plugin, this);
loadRunnable.run();
}
else unCacheStrategie = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 GeorgH93
* Copyright (C) 2020 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,8 +65,12 @@ protected BaseDatabase(final @NotNull MARRIAGE_MASTER plugin, final @NotNull Log
this.platform = platform;
this.bungee = bungee;
backend = getDatabaseBackend(platform, dbConfig, bungee, plugin.isSurnamesEnabled(), cache, logger, pluginName, dataFolder, bungeeSupportRequired);
setInstance(this);
loadRunnable = new LoadRunnable();
if(available())
{
setInstance(this);
loadRunnable = new LoadRunnable();
}
else loadRunnable = null;
}

public DatabaseBackend<MARRIAGE_PLAYER_DATA, MARRIAGE_DATA, HOME> getDatabaseBackend(final @NotNull IPlatformSpecific<MARRIAGE_PLAYER_DATA, MARRIAGE_DATA, HOME> platform,
Expand Down Expand Up @@ -96,7 +100,7 @@ public DatabaseBackend<MARRIAGE_PLAYER_DATA, MARRIAGE_DATA, HOME> getDatabaseBac
{
if(bungeeSupportRequired)
{
logger.warning("Database type not supported on BungeeCord!");
logger.severe("Database type not supported on BungeeCord!");
return null;
}
if(bungee)
Expand All @@ -107,7 +111,10 @@ public DatabaseBackend<MARRIAGE_PLAYER_DATA, MARRIAGE_DATA, HOME> getDatabaseBac
db.startup();
return db;
}
catch(Exception ignored){ ignored.printStackTrace(); } //TODO remove stacktrace after beta
catch(Exception ignored)
{
logger.severe("Failed to initialize database backend!");
}
return null;
}

Expand Down

0 comments on commit fc73e37

Please sign in to comment.