Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ TaskChain then executes your task pipe line, switching thread context where need
- [[GUIDE: Using in your Bukkit Plugins](https://github.com/aikar/TaskChain/wiki/implementing-bukkit)]
- Sponge Minecraft Servers
- [[GUIDE: Using in your Sponge Plugins](https://github.com/aikar/TaskChain/wiki/implementing-sponge)]
- Folia Servers
- Same methods employed by BukkitTaskChainFactory but instead use FoliaTaskChainFactory

### Planned
- Forge Minecraft Servers [[#2](https://github.com/aikar/TaskChain/issues/2)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@SuppressWarnings({"WeakerAccess", "unused"})
Expand Down
60 changes: 60 additions & 0 deletions folia/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

<!--
~ Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
~
~ Permission is hereby granted, free of charge, to any person obtaining
~ a copy of this software and associated documentation files (the
~ "Software"), to deal in the Software without restriction, including
~ without limitation the rights to use, copy, modify, merge, publish,
~ distribute, sublicense, and/or sell copies of the Software, and to
~ permit persons to whom the Software is furnished to do so, subject to
~ the following conditions:
~
~ The above copyright notice and this permission notice shall be
~ included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
~ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
~ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
~ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
~ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->

<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>
<parent>
<groupId>co.aikar</groupId>
<artifactId>taskchain-parent</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>taskchain-folia</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
<packaging>jar</packaging>
<name>TaskChain (Folia)</name>

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>taskchain-core</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
</dependency>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
115 changes: 115 additions & 0 deletions folia/src/main/java/co/aikar/taskchain/FoliaTaskChainFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2016-2024 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.taskchain;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

@SuppressWarnings({"WeakerAccess", "unused"})
public class FoliaTaskChainFactory extends TaskChainFactory {

private FoliaTaskChainFactory(Plugin plugin, AsyncQueue asyncQueue) {
super(new FoliaGameInterface(plugin, asyncQueue));
}

@Contract("_ -> new")
public static @NotNull TaskChainFactory create(Plugin plugin) {
return new FoliaTaskChainFactory(plugin, new TaskChainAsyncQueue());
}

@SuppressWarnings("PublicInnerClass")
private static class FoliaGameInterface implements GameInterface {
private final Plugin plugin;
private final AsyncQueue asyncQueue;

FoliaGameInterface(Plugin plugin, AsyncQueue asyncQueue) {
this.plugin = plugin;
this.asyncQueue = asyncQueue;
}

@Override
public AsyncQueue getAsyncQueue() {
return this.asyncQueue;
}

@Override
public boolean isMainThread() {
return Bukkit.isPrimaryThread();
}

@Override
public void postToMain(Runnable run) {
if (plugin.isEnabled()) {
Bukkit.getGlobalRegionScheduler().execute(plugin, run);
} else {
run.run();
}
}

@Override
public void scheduleTask(int ticks, Runnable run) {
if (plugin.isEnabled()) {
Bukkit.getGlobalRegionScheduler().runDelayed(plugin, task ->
Bukkit.getGlobalRegionScheduler().execute(plugin, run), ticks);
} else {
run.run();
}
}

@Override
public void registerShutdownHandler(TaskChainFactory factory) {
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().equals(plugin)) {
factory.shutdown(60, TimeUnit.SECONDS);
}
}
}, plugin);
}
}

public static final TaskChainAbortAction<Player, String, ?> MESSAGE = new TaskChainAbortAction<Player, String, Object>() {
@Override
public void onAbort(TaskChain<?> chain, @NotNull Player player, String message) {
player.sendMessage(message);
}
};

public static final TaskChainAbortAction<Player, String, ?> COLOR_MESSAGE = new TaskChainAbortAction<Player, String, Object>() {
@Override
public void onAbort(TaskChain<?> chain, @NotNull Player player, String message) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}
};
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
<module>core</module>
<module>bukkit</module>
<module>sponge</module>
<module>folia</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<repository>
<id>sponge-maven-repo</id>
<name>Sponge maven repo</name>
<url>http://repo.spongepowered.org/maven</url>
<url>https://repo.spongepowered.org/maven</url>
<releases>
<enabled>true</enabled>
</releases>
Expand Down