Minor cleanup of #27

* Code style
* Method name and access modifier
* JavaDoc
This commit is contained in:
Christian Koop 2021-11-01 20:29:16 +01:00
parent af9def96b3
commit 7c6817c470
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -70,8 +70,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
public final void onLoad() { public final void onLoad() {
try { try {
onPluginLoad(); onPluginLoad();
} catch (Throwable t) { } catch (Throwable th) {
crash(t); criticalErrorOnPluginStartup(th);
} }
} }
@ -107,9 +107,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
// Start Metrics // Start Metrics
Metrics.start(this); Metrics.start(this);
} catch (Throwable t) { } catch (Throwable th) {
crash(t); criticalErrorOnPluginStartup(th);
emergencyStop();
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.sendMessage(" "); console.sendMessage(" ");
@ -121,12 +120,6 @@ public abstract class SongodaPlugin extends JavaPlugin {
console.sendMessage(" "); // blank line to separate chatter console.sendMessage(" "); // blank line to separate chatter
} }
protected void emergencyStop() {
emergencyStop = true;
Bukkit.getPluginManager().disablePlugin(this);
}
@Override @Override
public final void onDisable() { public final void onDisable() {
if (emergencyStop) { if (emergencyStop) {
@ -213,15 +206,27 @@ public abstract class SongodaPlugin extends JavaPlugin {
} }
} }
} }
protected void emergencyStop() {
emergencyStop = true;
Bukkit.getPluginManager().disablePlugin(this);
}
/** /**
Invoke this method if a severe error occurs and the plugin needs to shut down. * Logs one or multiple errors that occurred during plugin startup and calls {@link #emergencyStop()} afterwards
*
@param t Any exceptions that are thrown when crashed should be put here, and will print once the error message logs. * @param th The error(s) that occurred
*/ */
public void crash(Throwable... t) { protected void criticalErrorOnPluginStartup(Throwable... th) {
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); Bukkit.getLogger().log(Level.SEVERE,
String.format(
"Unexpected error while loading %s v%s c%s: Disabling plugin!",
getDescription().getName(),
getDescription().getVersion(),
SongodaCore.getCoreLibraryVersion()
), th);
emergencyStop(); emergencyStop();
} }
} }