Getting the API Instance
The Maintenance API is accessed through theMaintenanceProvider class:
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
public class MyPlugin extends JavaPlugin {
private Maintenance maintenance;
@Override
public void onEnable() {
// Get the API instance
maintenance = MaintenanceProvider.get();
if (maintenance == null) {
getLogger().warning("Maintenance plugin not loaded yet!");
return;
}
getLogger().info("Successfully hooked into Maintenance v" + maintenance.getVersion());
}
}
The
MaintenanceProvider.get() method may return null if the Maintenance plugin hasn’t loaded yet. Always check for null before using the API.Checking Maintenance Status
You can check if maintenance mode is currently enabled:import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class StatusCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Maintenance maintenance = MaintenanceProvider.get();
if (maintenance == null) {
sender.sendMessage("Maintenance plugin not available!");
return true;
}
if (maintenance.isMaintenance()) {
sender.sendMessage("§cServer is currently in maintenance mode");
} else {
sender.sendMessage("§aServer is operational");
}
// Check if a timer is running
if (maintenance.isTaskRunning()) {
sender.sendMessage("§eA maintenance timer is currently running");
}
return true;
}
}
Enabling and Disabling Maintenance
Control maintenance mode programmatically:import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ToggleMaintenanceCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Maintenance maintenance = MaintenanceProvider.get();
if (maintenance == null) {
sender.sendMessage("§cMaintenance plugin not available!");
return true;
}
// Toggle maintenance mode
boolean newState = !maintenance.isMaintenance();
maintenance.setMaintenance(newState);
if (newState) {
sender.sendMessage("§cMaintenance mode enabled - non-whitelisted players will be kicked");
} else {
sender.sendMessage("§aMaintenance mode disabled - server is now open");
}
return true;
}
}
When maintenance is enabled, all non-whitelisted players are automatically kicked from the server. On BungeeCord with Redis enabled, the status is also written to the database.
Managing the Whitelist
Add and remove players from the maintenance whitelist:import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import eu.kennytv.maintenance.api.Settings;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
public class WhitelistCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Maintenance maintenance = MaintenanceProvider.get();
if (maintenance == null) {
sender.sendMessage("§cMaintenance plugin not available!");
return true;
}
Settings settings = maintenance.getSettings();
if (args.length == 0) {
// List all whitelisted players
Map<UUID, String> whitelisted = settings.getWhitelistedPlayers();
sender.sendMessage("§7Whitelisted players (" + whitelisted.size() + "):");
whitelisted.forEach((uuid, name) ->
sender.sendMessage("§7- " + name + " (" + uuid + ")"));
return true;
}
if (args.length < 2) {
sender.sendMessage("§cUsage: /whitelist <add|remove|check> <player>");
return true;
}
String action = args[0].toLowerCase();
String playerName = args[1];
switch (action) {
case "add" -> {
// Get player UUID (player must be online or use UUID lookup service)
Player target = Bukkit.getPlayer(playerName);
if (target == null) {
sender.sendMessage("§cPlayer must be online to add them!");
return true;
}
boolean added = settings.addWhitelistedPlayer(target.getUniqueId(), target.getName());
if (added) {
sender.sendMessage("§aAdded " + playerName + " to maintenance whitelist");
} else {
sender.sendMessage("§e" + playerName + " is already whitelisted");
}
}
case "remove" -> {
Player target = Bukkit.getPlayer(playerName);
if (target == null) {
sender.sendMessage("§cPlayer must be online to remove them!");
return true;
}
boolean removed = settings.removeWhitelistedPlayer(target.getUniqueId());
if (removed) {
sender.sendMessage("§aRemoved " + playerName + " from maintenance whitelist");
} else {
sender.sendMessage("§e" + playerName + " is not on the whitelist");
}
}
case "check" -> {
Player target = Bukkit.getPlayer(playerName);
if (target == null) {
sender.sendMessage("§cPlayer must be online to check them!");
return true;
}
if (settings.isWhitelisted(target.getUniqueId())) {
sender.sendMessage("§a" + playerName + " is whitelisted");
} else {
sender.sendMessage("§c" + playerName + " is not whitelisted");
}
}
default -> sender.sendMessage("§cUsage: /whitelist <add|remove|check> <player>");
}
return true;
}
}
Complete Plugin Example
Here’s a complete example plugin that integrates with the Maintenance API:import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import eu.kennytv.maintenance.api.Settings;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class MaintenanceIntegration extends JavaPlugin {
private Maintenance maintenance;
@Override
public void onEnable() {
// Get API instance
maintenance = MaintenanceProvider.get();
if (maintenance == null) {
getLogger().severe("Maintenance plugin not found! Disabling...");
getServer().getPluginManager().disablePlugin(this);
return;
}
getLogger().info("Successfully hooked into Maintenance v" + maintenance.getVersion());
// Log current status
if (maintenance.isMaintenance()) {
getLogger().info("Server is currently in maintenance mode");
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (maintenance == null) {
sender.sendMessage("§cMaintenance API not available!");
return true;
}
if (command.getName().equalsIgnoreCase("maintenanceinfo")) {
Settings settings = maintenance.getSettings();
sender.sendMessage("§7----- Maintenance Info -----");
sender.sendMessage("§7Status: " + (maintenance.isMaintenance() ? "§cEnabled" : "§aDisabled"));
sender.sendMessage("§7Version: " + maintenance.getVersion());
sender.sendMessage("§7Timer Running: " + (maintenance.isTaskRunning() ? "§aYes" : "§cNo"));
sender.sendMessage("§7Whitelisted Players: " + settings.getWhitelistedPlayers().size());
sender.sendMessage("§7Debug Mode: " + (maintenance.isDebug() ? "§aEnabled" : "§cDisabled"));
// Show if sender is whitelisted
if (sender instanceof Player player) {
boolean whitelisted = settings.isWhitelisted(player.getUniqueId());
sender.sendMessage("§7You are: " + (whitelisted ? "§aWhitelisted" : "§cNot whitelisted"));
}
return true;
}
return false;
}
}
Accessing Settings
TheSettings interface provides access to configuration options:
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import eu.kennytv.maintenance.api.Settings;
public void checkSettings() {
Maintenance maintenance = MaintenanceProvider.get();
Settings settings = maintenance.getSettings();
// Check various settings
boolean maintenanceEnabled = settings.isMaintenance();
boolean pingMessages = settings.isEnablePingMessages();
boolean joinNotifications = settings.isJoinNotifications();
boolean customIcon = settings.hasCustomIcon();
boolean debug = settings.debugEnabled();
// Reload all configurations
settings.reloadConfigs();
}
Next Steps
Event Listeners
Listen to maintenance events in your plugin
Proxy Integration
Manage per-server maintenance on proxy networks