Verified Commit b47ae5a8 authored by Gigadoc 2's avatar Gigadoc 2

proper logging

parent 2a4c6fff
......@@ -16,7 +16,6 @@ public class PluginListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnabled(PluginEnableEvent event) {
System.out.println("Some plugin has been enabled!");
this.mainPlugin.onPluginEnabled();
}
}
package jetzt.nicht.minecraft.spigotSystemd;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
......@@ -11,11 +12,15 @@ import jetzt.nicht.minecraft.spigotSystemd.PluginListener;
import jetzt.nicht.minecraft.spigotSystemd.StartupListener;
public class SpigotSystemdPlugin extends JavaPlugin {
PluginListener pluginListener;
StartupListener startupListener;
private PluginListener pluginListener;
private StartupListener startupListener;
private Logger log;
@Override
public void onEnable() {
// First of all, get a logger.
this.log = getLogger();
// When the plugin is being enabled, the server might just be starting,
// or the plugin is being reloaded, or the plugin is loaded late. We
// only want to start the whole readiness-listener-thing if the server
......@@ -26,7 +31,7 @@ public class SpigotSystemdPlugin extends JavaPlugin {
// started if they are. At the very least this prevents us from
// registering a StartupListener if ALL the worlds have been loaded.
if (someWorldIsLoaded()) {
System.out.println("The server has already loaded a world! This " +
log.warning("The server has already loaded a world! This " +
"either means that the server/plugin has been reloaded, " +
"or the plugin has somehow been loaded late " +
"(please don't do that).");
......@@ -35,7 +40,7 @@ public class SpigotSystemdPlugin extends JavaPlugin {
// Register our listener that waits for the server to be "ready".
// We pass in a reference to ourselves so the listener can call back.
this.startupListener = new StartupListener(this);
System.out.println("Registering StartupListener...");
log.finer("Registering StartupListener...");
getServer().getPluginManager()
.registerEvents(this.startupListener, this);
SDNotify.sendStatus("Starting...");
......@@ -53,17 +58,22 @@ public class SpigotSystemdPlugin extends JavaPlugin {
// being activated again, if we implement watchdog functionality.
}
void onWorldInitialized() {
log.finer("Some World has been initialized!");
this.onServerMostlyReady();
}
void onServerMostlyReady() {
System.out.println("The server is now \"mostly ready\"!");
log.fine("The server is now \"mostly ready\"!");
// Unregister the StartupListener, as the server is now
// deemed "mostly ready"
System.out.println("Unregistering StartupListener...");
log.finer("Unregistering StartupListener...");
HandlerList.unregisterAll(this.startupListener);
// Register our listener that waits for plugins to be enabled. See above.
this.pluginListener = new PluginListener(this);
System.out.println("Registering PluginListener...");
log.finer("Registering PluginListener...");
getServer().getPluginManager()
.registerEvents(this.pluginListener, this);
......@@ -75,26 +85,25 @@ public class SpigotSystemdPlugin extends JavaPlugin {
void onPluginEnabled() {
if (allPluginsEnabled()) {
System.out.println("All plugins have been enabled!");
System.out.println("Unregistering PluginListener...");
log.fine("All plugins have been enabled!");
log.finer("Unregistering PluginListener...");
HandlerList.unregisterAll(this.pluginListener);
System.out.println("Signalling readiness to systemd...");
log.info("Signalling readiness to systemd...");
SDNotify.sendNotify();
SDNotify.sendStatus("Ready to accept connections!");
} else {
System.out.println("There are still plugins to be enabled, continuing...");
log.fine("There are still plugins to be enabled, continuing...");
}
}
private boolean allPluginsEnabled() {
System.out.println("Checking whether all plugins have been enabled...");
log.finer("Some plugin has been enabled!");
log.fine("Checking whether all plugins have been enabled...");
Plugin[] loadedPlugins = getServer().getPluginManager().getPlugins();
boolean allPluginsEnabled = true;
for (Plugin plugin : loadedPlugins) {
System.out.println(
String.format("%s: %b", plugin, plugin.isEnabled())
);
log.finest(String.format("%s: %b", plugin, plugin.isEnabled()));
if (plugin.isEnabled() == false) {
allPluginsEnabled = false;
break;
......
......@@ -16,7 +16,6 @@ public class StartupListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldInitialized(WorldInitEvent event) {
System.out.println("Some World has been initialized!");
this.mainPlugin.onServerMostlyReady();
this.mainPlugin.onWorldInitialized();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment