Wrap entire LD loading in a catch and make it check for updates if exception is thrown

This commit is contained in:
libraryaddict 2021-05-15 12:32:08 +12:00
parent c8bd25ba57
commit d4abde2542

@ -59,6 +59,7 @@ public class LibsDisguises extends JavaPlugin {
@Override @Override
public void onLoad() { public void onLoad() {
try {
if (instance != null || !Bukkit.getServer().getWorlds().isEmpty() || !Bukkit.getOnlinePlayers().isEmpty()) { if (instance != null || !Bukkit.getServer().getWorlds().isEmpty() || !Bukkit.getOnlinePlayers().isEmpty()) {
reloaded = true; reloaded = true;
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!"); getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!");
@ -85,8 +86,8 @@ public class LibsDisguises extends JavaPlugin {
} }
} catch (Exception e) { } catch (Exception e) {
getLogger() getLogger()
.severe("Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you can " + .severe("Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you" +
"join. Check the pins in #libs-support for a ProtocolLib.jar you can download!"); " can " + "join. Check the pins in #libs-support for a ProtocolLib.jar you can download!");
e.printStackTrace(); e.printStackTrace();
} }
@ -106,10 +107,16 @@ public class LibsDisguises extends JavaPlugin {
} }
WatcherSanitizer.init(); WatcherSanitizer.init();
} catch (Throwable throwable) {
getUpdateChecker().doUpdate();
throw throwable;
}
} }
@Override @Override
public void onEnable() { public void onEnable() {
try {
if (reloaded) { if (reloaded) {
getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!"); getLogger().severe("Server was reloaded! Please do not report any bugs! This plugin can't handle " + "reloads gracefully!");
} }
@ -151,7 +158,8 @@ public class LibsDisguises extends JavaPlugin {
LibsPremium.check(getDescription().getVersion(), getFile()); LibsPremium.check(getDescription().getVersion(), getFile());
if (!LibsPremium.isPremium()) { if (!LibsPremium.isPremium()) {
getLogger().info("You are running the free version, commands limited to non-players and operators. (Console," + " Command " + "Blocks, Admins)"); getLogger()
.info("You are running the free version, commands limited to non-players and operators. (Console," + " Command " + "Blocks, Admins)");
} }
if (ReflectionManager.getVersion() == null) { if (ReflectionManager.getVersion() == null) {
@ -166,7 +174,8 @@ public class LibsDisguises extends JavaPlugin {
if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) {
getLogger().severe("!! May I have your attention please !!"); getLogger().severe("!! May I have your attention please !!");
getLogger().severe("Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " + requiredProtocolLib + getLogger()
.severe("Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " + requiredProtocolLib +
"!"); "!");
getLogger().severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib" + ".jar"); getLogger().severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib" + ".jar");
getLogger().severe("Or! Use /ld updateprotocollib - To update to the latest development build"); getLogger().severe("Or! Use /ld updateprotocollib - To update to the latest development build");
@ -245,6 +254,11 @@ public class LibsDisguises extends JavaPlugin {
unregisterCommands(false); unregisterCommands(false);
new MetricsInitalizer(); new MetricsInitalizer();
} catch (Throwable throwable) {
getUpdateChecker().doUpdate();
throw throwable;
}
} }
public void unregisterCommands(boolean force) { public void unregisterCommands(boolean force) {