The Maintenance API provides an event system that allows you to react to changes in maintenance status and configuration reloads. Events are handled through the EventManager interface.
The MaintenanceChangedEvent is fired whenever maintenance mode is enabled or disabled:
import eu.kennytv.maintenance.api.Maintenance;import eu.kennytv.maintenance.api.MaintenanceProvider;import eu.kennytv.maintenance.api.event.MaintenanceChangedEvent;import eu.kennytv.maintenance.api.event.manager.EventListener;import org.bukkit.Bukkit;import org.bukkit.plugin.java.JavaPlugin;public class MaintenanceAlerts extends JavaPlugin { @Override public void onEnable() { Maintenance maintenance = MaintenanceProvider.get(); if (maintenance == null) { return; } // Create a custom listener class EventListener<MaintenanceChangedEvent> listener = new EventListener<MaintenanceChangedEvent>() { @Override public void onEvent(MaintenanceChangedEvent event) { handleMaintenanceChange(event); } }; // Register the listener maintenance.getEventManager().registerListener(listener, MaintenanceChangedEvent.class); } private void handleMaintenanceChange(MaintenanceChangedEvent event) { if (event.isMaintenance()) { // Maintenance was enabled getLogger().info("Server entered maintenance mode"); // Broadcast to operators Bukkit.getOnlinePlayers().stream() .filter(player -> player.hasPermission("maintenance.notify")) .forEach(player -> player.sendMessage("§c[Alert] Server is now in maintenance mode")); // Disable certain features disablePublicFeatures(); } else { // Maintenance was disabled getLogger().info("Server exited maintenance mode"); // Broadcast to operators Bukkit.getOnlinePlayers().stream() .filter(player -> player.hasPermission("maintenance.notify")) .forEach(player -> player.sendMessage("§a[Alert] Server is now open to the public")); // Re-enable features enablePublicFeatures(); } } private void disablePublicFeatures() { // Disable public warps, shops, etc. getLogger().info("Disabling public features during maintenance..."); } private void enablePublicFeatures() { // Re-enable public warps, shops, etc. getLogger().info("Re-enabling public features..."); }}
The MaintenanceChangedEvent is a record containing a single boolean field isMaintenance() that indicates whether maintenance is now enabled or disabled.
The MaintenanceReloadedEvent is fired when the Maintenance plugin’s configuration is reloaded:
import eu.kennytv.maintenance.api.Maintenance;import eu.kennytv.maintenance.api.MaintenanceProvider;import eu.kennytv.maintenance.api.event.MaintenanceReloadedEvent;import eu.kennytv.maintenance.api.event.manager.EventListener;import org.bukkit.plugin.java.JavaPlugin;public class ConfigSync extends JavaPlugin { @Override public void onEnable() { Maintenance maintenance = MaintenanceProvider.get(); if (maintenance == null) { return; } // Listen for config reloads maintenance.getEventManager().registerListener( new EventListener<MaintenanceReloadedEvent>() { @Override public void onEvent(MaintenanceReloadedEvent event) { handleConfigReload(); } }, MaintenanceReloadedEvent.class ); } private void handleConfigReload() { Maintenance maintenance = MaintenanceProvider.get(); getLogger().info("Maintenance configuration was reloaded"); // Check the new maintenance status if (maintenance.isMaintenance()) { getLogger().info("Maintenance is now enabled after reload"); } else { getLogger().info("Maintenance is now disabled after reload"); } // Sync your plugin's configuration based on new Maintenance settings syncConfiguration(); } private void syncConfiguration() { // Update your plugin's behavior based on new settings getLogger().info("Synchronizing configuration with Maintenance plugin..."); }}
The MaintenanceReloadedEvent doesn’t contain any data. Use Maintenance.isMaintenance() to check the current status after a reload.