Skip to content

Repository files navigation

ThreadUtil

GitHub License Maven Central Version Documentation Javadoc GitHub Actions Workflow Status GitHub Issues GitHub last commit Discord Server

A fluent scheduling utility for Minecraft plugins, providing elegant async/sync runnable chaining with Bukkit/Spigot/Paper/Velocity integration.


🌟 Features

  • Fluent API for async/sync task chaining
  • Built-in delay support with tick/Duration precision
  • Task cancellation support
  • Thread-safe error handling
  • Custom thread pool integration

📦 Installation

The bukkit, velocity & sponge modules transitively include common. Additionally you should shade the library into your plugin jar.

Gradle Kotlin DSL
repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.milkdrinkers:threadutil-common:VERSION")
    implementation("io.github.milkdrinkers:threadutil-bukkit:VERSION")
    implementation("io.github.milkdrinkers:threadutil-sponge:VERSION")
    implementation("io.github.milkdrinkers:threadutil-velocity:VERSION")
}
Maven
<project>
    <dependencies>
        <dependency>
            <groupId>io.github.milkdrinkers</groupId>
            <artifactId>threadutil-common</artifactId>
            <version>VERSION</version>
        </dependency>
        <dependency>
            <groupId>io.github.milkdrinkers</groupId>
            <artifactId>threadutil-bukkit</artifactId>
            <version>VERSION</version>
        </dependency>
        <dependency>
            <groupId>io.github.milkdrinkers</groupId>
            <artifactId>threadutil-sponge</artifactId>
            <version>VERSION</version>
        </dependency>
        <dependency>
            <groupId>io.github.milkdrinkers</groupId>
            <artifactId>threadutil-velocity</artifactId>
            <version>VERSION</version>
        </dependency>
    </dependencies>
</project>

Usage Example 🚀

import io.github.milkdrinkers.threadutil.queue.RunningTaskQueue;
import io.github.milkdrinkers.threadutil.PlatformBukkit;
import io.github.milkdrinkers.threadutil.Scheduler;

// Initialize ThreadUtil when your software is starting!
Scheduler.init(new PlatformBukkit(plugin));

// Start executing the queue and store the running task queue
RunningTaskQueue taskQueue = Scheduler
    .async(() -> {
        return fetchPlayerData(player.getUniqueId());
    })
    .delay(Duration.ofSeconds(10))
    .async(playerData -> {
        saveToFile(playerData);
    })
    .execute();

// Wait 5 seconds then cancel the other task queue
Scheduler
    .delay(Duration.ofSeconds(5))
    .sync(() -> {
        taskQueue.cancel();
    })
    .execute();

// Make sure to shut down your scheduler when your software is stopping!
Scheduler.shutdown();

📚 Documentation


🔨 Building from Source

git clone https://github.com/milkdrinkers/ThreadUtil.git
cd threadutil
./gradlew publishToMavenLocal

🔧 Contributing

Contributions are always welcome! Please make sure to read our Contributor's Guide for standards and our Contributor License Agreement (CLA) before submitting any pull requests.

We also ask that you adhere to our Contributor Code of Conduct to ensure this community remains a place where all feel welcome to participate.


📝 Licensing

You can find the license the source code and all assets are under here. Additionally, contributors agree to the Contributor License Agreement (CLA) found here.


❤️ Acknowledgments

  • Aikar: For their excellent utility TaskChain, which this was inspired by. I highly recommend their library, providing the same features and more for any platform!

🔥 Consuming Projects

Here is a list of known projects using ThreadUtil:

  • Minecraft-Plugin-Template - Provided by default in a Minecraft Plugin Template.
  • Maquillage - Maquillage a Minecraft cosmetics plugin.
  • Stewards - Stewards a Minecraft Towny NPC extension plugin.
  • CharacterCards - CharacterCards is a Minecraft plugin allowing players to create cards describing their character.
  • (Add your project here!)

About

Fluent java library for Minecraft, providing elegant async/sync runnable chaining with Bukkit, Spigot, Paper, Velocity integration.

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Sponsor this project

Used by

Contributors

Languages