Skip to main content
The MaintenanceProvider class is the entry point for obtaining the Maintenance API instance. This is the first step in using the Maintenance API.

Overview

MaintenanceProvider is a singleton provider that gives you access to the main Maintenance API interface. You should always check if the API is available before using it.

Method

get

Returns the Maintenance API instance.
return
Maintenance
The Maintenance API instance, or null if the plugin is not loaded yet
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;

Maintenance api = MaintenanceProvider.get();
if (api != null) {
    // API is available, safe to use
    api.setMaintenance(true);
} else {
    // API not loaded yet
    System.err.println("Maintenance API is not available");
}

Usage Examples

Basic Usage

The most common pattern is to obtain the API instance when you need it:
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;

public class MyPlugin {
    
    public void enableMaintenance() {
        Maintenance api = MaintenanceProvider.get();
        if (api == null) {
            System.err.println("Maintenance plugin not available");
            return;
        }
        
        api.setMaintenance(true);
        System.out.println("Maintenance mode enabled");
    }
}

Caching the API Instance

If you need to use the API frequently, you can cache the instance:
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {
    
    private Maintenance maintenanceApi;
    
    @Override
    public void onEnable() {
        // Get the API during plugin initialization
        this.maintenanceApi = MaintenanceProvider.get();
        
        if (maintenanceApi == null) {
            getLogger().severe("Maintenance plugin not found!");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        
        getLogger().info("Maintenance API version: " + maintenanceApi.getVersion());
    }
    
    public void toggleMaintenance() {
        if (maintenanceApi != null) {
            maintenanceApi.setMaintenance(!maintenanceApi.isMaintenance());
        }
    }
}

Checking API Availability with Soft Dependency

If Maintenance is an optional dependency, check for availability:
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {
    
    private Maintenance maintenanceApi;
    private boolean maintenanceAvailable;
    
    @Override
    public void onEnable() {
        // Check if Maintenance plugin is available
        this.maintenanceApi = MaintenanceProvider.get();
        this.maintenanceAvailable = maintenanceApi != null;
        
        if (maintenanceAvailable) {
            getLogger().info("Maintenance integration enabled");
            setupMaintenanceIntegration();
        } else {
            getLogger().info("Maintenance plugin not found, running without integration");
        }
    }
    
    private void setupMaintenanceIntegration() {
        // Register event listeners
        maintenanceApi.getEventManager().registerListener(
            eu.kennytv.maintenance.api.event.MaintenanceChangedEvent.class,
            event -> {
                getLogger().info("Maintenance mode changed: " + event.isMaintenance());
            }
        );
    }
    
    public boolean isMaintenanceMode() {
        return maintenanceAvailable && maintenanceApi.isMaintenance();
    }
}

Using in Commands

Example of using the API in a command:
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.CommandExecutor;
import org.bukkit.command.CommandSender;

public class MaintenanceCommand implements CommandExecutor {
    
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Maintenance api = MaintenanceProvider.get();
        
        if (api == null) {
            sender.sendMessage("Maintenance plugin is not available");
            return true;
        }
        
        if (args.length == 0) {
            // Display status
            Settings settings = api.getSettings();
            sender.sendMessage("Maintenance Status: " + (api.isMaintenance() ? "ON" : "OFF"));
            sender.sendMessage("Whitelisted Players: " + settings.getWhitelistedPlayers().size());
            return true;
        }
        
        if (args[0].equalsIgnoreCase("on")) {
            api.setMaintenance(true);
            sender.sendMessage("Maintenance mode enabled");
            return true;
        }
        
        if (args[0].equalsIgnoreCase("off")) {
            api.setMaintenance(false);
            sender.sendMessage("Maintenance mode disabled");
            return true;
        }
        
        return false;
    }
}

Plugin Dependencies

To use the Maintenance API, add it as a dependency in your plugin.yml:

Hard Dependency

If your plugin requires Maintenance to function:
name: MyPlugin
version: 1.0.0
main: com.example.MyPlugin
depend: [Maintenance]

Soft Dependency

If Maintenance is optional:
name: MyPlugin
version: 1.0.0
main: com.example.MyPlugin
softdepend: [Maintenance]

Maven Dependency

Add the Maintenance API to your pom.xml:
<repositories>
    <repository>
        <id>kennytv-repo</id>
        <url>https://repo.kennytv.eu/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>eu.kennytv.maintenance</groupId>
        <artifactId>maintenance-api</artifactId>
        <version>4.2.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Gradle Dependency

Add the Maintenance API to your build.gradle:
repositories {
    maven {
        url 'https://repo.kennytv.eu/'
    }
}

dependencies {
    compileOnly 'eu.kennytv.maintenance:maintenance-api:4.2.1'
}

Next Steps

Once you have obtained the API instance, you can:
  • Use the Maintenance API to control maintenance mode
  • Access the Settings API to manage configuration and whitelists
  • Register event listeners using the EventManager

Build docs developers (and LLMs) love