Skip to content

Implementing Bukkit

Daniel Ennis edited this page Oct 28, 2016 · 18 revisions

Implementing TaskChain into Bukkit/Spigot/Paper Plugins

Maven

First you will need to add the repositories (you should already have Spigot) and the dependency to your pom.xml You will also need to shade the plugin into your jar.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>


    <repositories>
        <repository>
            <id>aikar</id>
            <url>http://ci.emc.gs/nexus/content/groups/aikar/</url>
        </repository>
        <repository>
            <id>spigot</id>
            <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>co.aikar</groupId>
            <artifactId>taskchain-core</artifactId>
            <version>TASKCHAIN VERSION</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Replace TASKCHAIN VERSION with the latest version found on the TaskChain home page

Gradle

TODO

Ant

Did you see my comment about getting off dinosaurs on the README? Yeah... that applies here too. Please use a modern build tool like Maven or Gradle!

Adding to your plugin

Once the Dependency is added, you need to create a factory and store a reference to it.

It is recommended to set up static helper methods to create chains, here is an example of integrating it into your plugin:

import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChainFactory;
import co.aikar.taskchain.TaskChain;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {
    private static TaskChainFactory taskChainFactory;
    public static <T> TaskChain<T> newChain() {
        return taskChainFactory.newChain();
    }
    public static <T> TaskChain<T> newSharedChain(String name) {
        return taskChainFactory.newSharedChain(name);
    }

    @Override
    public void onEnable() {
        taskChainFactory = BukkitTaskChainFactory.create(this);
    }
}

That is it!

You may now use

MyPlugin.newChain()./* tasks */.execute();

Anywhere in your plugin!

Clone this wiki locally