Skip to content

Using the API

LRMtheBoss edited this page Apr 14, 2024 · 7 revisions

Customize the behavior of DriveBackupV2 using its powerful API. This guide assumes you have prior knowledge of how to create Bukkit plugins.

Since v1.3.2

Getting Started

Adding the Dependency

In your Maven project's pom.xml, add the following text under <repositories>:

<repository>
    <id>DriveBackupV2-mvn-repo</id>
    <url>https://raw.githubusercontent.com/MaxMaeder/DriveBackupV2/mvn-repo/</url>
    <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
    </snapshots>
</repository>

Under <dependencies>, add the following text:

<dependency>
    <groupId>ratismal</groupId>
    <artifactId>DriveBackupV2</artifactId>
    <version>PLUGIN_VERSION</version>
</dependency>

Replace PLUGIN_VERSION with the version of DriveBackupV2 you have installed.

Updating the plugin.yml

If your plugin can function without DriveBackupV2, add DriveBackupV2 to the softdepend list in your plugin's plugin.yml, like so:

softdepend: [DriveBackupV2]

Otherwise, add it to the depend list, like so:

depend: [DriveBackupV2]

Importing the Class

In addition to completing the above steps, you will need to import the DriveBackupV2 class in order to use the API. Add the following text to the top of any files you plan on using the API in:

import ratismal.drivebackup.DriveBackupApi;

Methods

void beforeBackupStart(Callable<Boolean> callable)

Runs the specified Callable after a backup has been initiated (either manually using /drivebackup backup or the API, or automatically with scheduled or interval-based backups), but before the backup process has been started.

Multiple Callables can be specified by calling this method multiple times.

If any Callable returns false, the backup will be canceled.

If the Callable doesn't return in 10 seconds, the Callable will be ignored.

  • Parameters:
    • callable the Callable

void onBackupDone(Runnable runnable)

Runs the specified Runnable in a new thread after a backup is successfully completed.

  • Parameters:
    • runnable the Runnable

void onBackupError(Runnable runnable)

Runs the specified Runnable in a new thread after the backup system completes with an error.

  • Parameters:
    • runnable the Runnable

void startBackup()

Starts a backup.

Behaves identically to running /drivebackup backup.

void reloadConfig()

Reloads the plugin's config.yml.

Behaves identically to running /drivebackup reloadconfig.

String getNextAutoBackup()

Returns the message sent to chat when /drivebackup nextbackup is run.

For more information about the /drivebackup nextbackup command, see this.

  • Returns:
    • the message

Examples

View the code of and download several example plugins using the API here.