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

initial working version

Currenttly only features systemd ready-notification on startup.
parent cf81fa9e
plugins {
id 'com.github.johnrengelman.shadow' version '2.0.4'
id 'java'
}
repositories {
mavenCentral()
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compile 'info.faljse:SDNotify:1.1'
}
rootProject.name = 'SpigotSystemd'
package jetzt.nicht.minecraft.spigotSystemd;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import jetzt.nicht.minecraft.spigotSystemd.SpigotSystemdPlugin;
public class PluginListener implements Listener {
SpigotSystemdPlugin mainPlugin;
public PluginListener(SpigotSystemdPlugin mainPlugin) {
this.mainPlugin = mainPlugin;
}
@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 org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import info.faljse.SDNotify.SDNotify;
import jetzt.nicht.minecraft.spigotSystemd.PluginListener;
import jetzt.nicht.minecraft.spigotSystemd.StartupListener;
public class SpigotSystemdPlugin extends JavaPlugin {
PluginListener pluginListener;
StartupListener startupListener;
@Override
public void onEnable() {
// we have been loaded, so the server has just been started
// XXX: Check some other state, to become reload-safe!
// Check systemd if our service is started!
// 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...");
getServer().getPluginManager()
.registerEvents(this.startupListener, this);
}
@Override
public void onDisable() {
}
public void onServerMostlyReady() {
System.out.println("The server is now \"mostly ready\"!");
// Unregister the StartupListener, as the server is now
// deemed "mostly ready"
System.out.println("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...");
getServer().getPluginManager()
.registerEvents(this.pluginListener, this);
// Trigger one execution of onPluginEnabled, as all plugins might have
// been enabled already. This is a bit ugly but technically correct,
// because at least we ourselves have been enabled.
this.onPluginEnabled();
}
public void onPluginEnabled() {
if (this.checkPluginsEnabled()) {
System.out.println("All plugins have been enabled!");
System.out.println("Unregistering PluginListener...");
HandlerList.unregisterAll(this.pluginListener);
System.out.println("Signalling readyness to systemd...");
SDNotify.sendNotify();
} else {
System.out.println("There are still plugins to be enabled, continuing...");
}
}
public boolean checkPluginsEnabled() {
System.out.println("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())
);
if (plugin.isEnabled() == false) {
allPluginsEnabled = false;
break;
}
}
return allPluginsEnabled;
}
}
package jetzt.nicht.minecraft.spigotSystemd;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent;
import jetzt.nicht.minecraft.spigotSystemd.SpigotSystemdPlugin;
public class StartupListener implements Listener {
SpigotSystemdPlugin mainPlugin;
public StartupListener(SpigotSystemdPlugin mainPlugin) {
this.mainPlugin = mainPlugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldInitialized(WorldInitEvent event) {
System.out.println("Some World has been initialized!");
this.mainPlugin.onServerMostlyReady();
}
}
---
name: systemd
description: Integrates Spigot with systemd when running as a systemd service.
author: Gigadoc2
version: 0.1.0
main: jetzt.nicht.minecraft.spigotSystemd.SpigotSystemdPlugin
load: STARTUP
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