diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 384fc9fe..d7c54570 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -71,13 +71,7 @@ public abstract class SongodaPlugin extends JavaPlugin { try { onPluginLoad(); } catch (Throwable t) { - Bukkit.getLogger().log(Level.SEVERE, - "Unexpected error while loading " + getDescription().getName() - + " v" + getDescription().getVersion() - + " c" + SongodaCore.getCoreLibraryVersion() - + ": Disabling plugin!", t); - - emergencyStop = true; + crash(t); } } @@ -113,13 +107,8 @@ public abstract class SongodaPlugin extends JavaPlugin { // Start Metrics Metrics.start(this); - } catch (Throwable th) { - Bukkit.getLogger().log(Level.SEVERE, - "Unexpected error while loading " + getDescription().getName() - + " v" + getDescription().getVersion() - + " c" + SongodaCore.getCoreLibraryVersion() - + ": Disabling plugin!", th); - + } catch (Throwable t) { + crash(t); emergencyStop(); console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); @@ -224,4 +213,15 @@ public abstract class SongodaPlugin extends JavaPlugin { } } } + + /** + Invoke this method if a severe error occurs and the plugin needs to shut down. + + @param t Any exceptions that are thrown when crashed should be put here, and will print once the error message logs. + */ + public void crash(Throwable... t) { + Bukkit.getLogger().log(Level.SEVERE, String.format("Unexpected error while loading %s v%s c%s: Disabling plugin!", getDescription().getName(), getDescription().getVersion(), SongodaCore.getCoreLibraryVersion()), t); + emergencyStop(); + } + }