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() {
try {
onPluginLoad();
} catch (Throwable t) {
crash(t);
} catch (Throwable th) {
criticalErrorOnPluginStartup(th);
}
}
@ -107,9 +107,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
// Start Metrics
Metrics.start(this);
} catch (Throwable t) {
crash(t);
emergencyStop();
} catch (Throwable th) {
criticalErrorOnPluginStartup(th);
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.sendMessage(" ");
@ -121,12 +120,6 @@ public abstract class SongodaPlugin extends JavaPlugin {
console.sendMessage(" "); // blank line to separate chatter
}
protected void emergencyStop() {
emergencyStop = true;
Bukkit.getPluginManager().disablePlugin(this);
}
@Override
public final void onDisable() {
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.
@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);
* Logs one or multiple errors that occurred during plugin startup and calls {@link #emergencyStop()} afterwards
*
* @param th The error(s) that occurred
*/
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()
), th);
emergencyStop();
}
}