Implementing Bukkit

Daniel Ennis edited this page Mar 9, 2018 · 12 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 library into your plugin 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>https://repo.aikar.co/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-bukkit</artifactId>
            <version>TASKCHAIN VERSION</version>
        </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

First you will need to add the repositories (you should already have Spigot) and the dependency to your build.gradle. You will also need to shadow the library into your plugin jar.

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:2.0.2"
    }
}
apply plugin: "com.github.johnrengelman.shadow"

repositories {
    maven {
        url = "http://ci.emc.gs/nexus/content/groups/aikar/"
    }
    maven {
        url = "https://hub.spigotmc.org/nexus/content/groups/public/"
    }
}

dependencies {
    compile "co.aikar:taskchain-bukkit:<TASKCHAIN_VERSION>"
}

build.dependsOn shadowJar

Replace <TASKCHAIN_VERSION> with the latest version found on the TaskChain home page

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!

But if you really do need Ant, you can find artfacts here:

http://ci.emc.gs/nexus/content/groups/aikar/co/aikar/taskchain-core/

http://ci.emc.gs/nexus/content/groups/aikar/co/aikar/taskchain-bukkit/

Download both of the same version, and include core and then bukkit in your build.

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!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.