-
Notifications
You must be signed in to change notification settings - Fork 21
API
Nassim Jahnke edited this page May 18, 2024
·
23 revisions
Maintenance is published to maven central, so no extra repository is required.
You can add it to your maven project by including this in your pom:
<dependencies>
<dependency>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-api</artifactId>
<version>4.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
OR, if you need the proxy extensions;
<dependencies>
<dependency>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-api-proxy</artifactId>
<version>4.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
You can either get the api instance through the server's pluginmanager or through a quicker util. Depending on what platform you are on, you can get it by using one of the following utility class:
MaintenanceProxy api = (MaintenanceProxy) MaintenanceProvider.get();
Maintenance api = MaintenanceProvider.get();
An example of how to use some of its methods could be the following:
package eu.kennytv.fantasticplugin;
import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.api.MaintenanceProvider;
import eu.kennytv.maintenance.api.proxy.MaintenanceProxy;
import eu.kennytv.maintenance.api.proxy.Server;
import java.util.Map;
import java.util.UUID;
public class SuperFantasticClass {
public void doAwesomeStuff() {
Maintenance api = MaintenanceProvider.get();
if (!api.isMaintenance() && !api.isTaskRunning()) {
api.setMaintenance(true);
System.out.println("No task was running, enabled maintenance mode!");
}
}
public void doEvenAwesomerStuff() {
Maintenance api = MaintenanceProvider.get();
boolean added = api.getSettings().addWhitelistedPlayer(UUID.fromString("a8179ff3-c201-4a75-bdaa-9d14aca6f83f"), "KennyTV");
if (!added) {
System.out.println("The player already is in the maintenance whitelist!");
return;
}
for (Map.Entry<UUID, String> entry : api.getSettings().getWhitelistedPlayers().entrySet()) {
System.out.println("uuid: " + entry.getKey().toString());
System.out.println("name: " + entry.getValue());
}
}
public void doAwesomestestStuff() {
MaintenanceProxy api = (MaintenanceProxy) MaintenanceProvider.get();
Server lobby = api.getServer("Lobby1");
if (!api.isMaintenance(lobby)) {
// The 'changed' boolean obviously always be true, see the check one line above.
boolean changed = api.setMaintenanceToServer(lobby, true);
if (changed) {
System.out.println("Maintenance on Lobby1 has been enabled!");
}
}
}
}
To listen to Maintenance events, use the EventManager you can get through Maintenance API, like so:
public void registerListeners() {
MaintenanceProvider.get().getEventManager().registerListener(new MaintenanceChangedListener(), MaintenanceChangedEvent.class);
}
public static final class MaintenanceChangedListener extends EventListener<MaintenanceChangedEvent> {
@Override
public void onEvent(MaintenanceChangedEvent event) {
// do something
}
}
You can also always get support on my Discord server: https://discord.gg/vGCUzHq