diff --git a/pom.xml b/pom.xml
index cf21afb..d3e94f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.palmergames.bukkit
TownyChat
jar
- 0.104
+ 0.105
@@ -26,7 +26,7 @@
17
1.16
UTF-8
- 0.99.0.0
+ 0.99.0.6
@@ -75,7 +75,7 @@
com.github.TownyAdvanced
Towny
- 0.99.0.0
+ ${towny.version}
provided
diff --git a/resources/changelog.txt b/resources/changelog.txt
index 1a05f5c..bf9657e 100644
--- a/resources/changelog.txt
+++ b/resources/changelog.txt
@@ -447,4 +447,7 @@ v0.104:
- Update min. Towny version to 0.99.0.0.
- Update EssentialsX maven details.
- Translate spy message colour codes.
- - Closes https://github.com/TownyAdvanced/Towny/issues/6634
\ No newline at end of file
+ - Closes https://github.com/TownyAdvanced/Towny/issues/6634
+v0.105:
+ - Add Folia support, courtesy of Warrior with PR #46.
+ - Update min. Towny version to 0.99.0.6.
\ No newline at end of file
diff --git a/resources/plugin.yml b/resources/plugin.yml
index a7d8ca6..9d52ac7 100644
--- a/resources/plugin.yml
+++ b/resources/plugin.yml
@@ -8,6 +8,7 @@ description: >
TownyChat plugin which hooks into Towny.
depend: [Towny]
softdepend: [CraftIRC, PlaceholderAPI, dynmap, EssentialsDiscord]
+folia-supported: true
############################################################
# +------------------------------------------------------+ #
diff --git a/src/com/palmergames/bukkit/TownyChat/Chat.java b/src/com/palmergames/bukkit/TownyChat/Chat.java
index d4f5518..1ab296a 100644
--- a/src/com/palmergames/bukkit/TownyChat/Chat.java
+++ b/src/com/palmergames/bukkit/TownyChat/Chat.java
@@ -13,6 +13,9 @@
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
import com.palmergames.bukkit.TownyChat.util.EssentialsIntegration;
import com.palmergames.bukkit.towny.Towny;
+import com.palmergames.bukkit.towny.scheduling.TaskScheduler;
+import com.palmergames.bukkit.towny.scheduling.impl.BukkitTaskScheduler;
+import com.palmergames.bukkit.towny.scheduling.impl.FoliaTaskScheduler;
import com.palmergames.bukkit.util.Version;
import com.palmergames.util.FileMgmt;
@@ -51,21 +54,25 @@ public class Chat extends JavaPlugin {
protected PluginManager pm;
private static Chat chat = null;
+ private final TaskScheduler scheduler;
private Towny towny = null;
private DynmapAPI dynMap = null;
private Essentials essentials = null;
- private static Version requiredTownyVersion = Version.fromString("0.99.0.0");
+ private static Version requiredTownyVersion = Version.fromString("0.99.0.6");
public static boolean usingPlaceholderAPI = false;
public static boolean usingEssentialsDiscord = false;
boolean chatConfigError = false;
boolean channelsConfigError = false;
private static ConcurrentMap playerChannelMap;
+ public Chat() {
+ chat = this;
+ this.scheduler = isFoliaClassPresent() ? new FoliaTaskScheduler(this) : new BukkitTaskScheduler(this);
+ }
+
@Override
public void onEnable() {
-
- chat = this;
pm = getServer().getPluginManager();
channelsConfig = new ChannelConfigurationHandler(this);
channels = new ChannelsHolder(this);
@@ -89,14 +96,7 @@ public void onEnable() {
* This executes the task with a 1 tick delay avoiding the bukkit depends bug.
* TODO: What bug is this referencing? This goes back to the first version of TownyChat.
*/
- if (getServer().getScheduler().scheduleSyncDelayedTask(this, new onLoadedTask(this), 1) == -1) {
- /*
- * We either failed to find Towny or the Scheduler failed to
- * register the task.
- */
- disableWithMessage("Could not schedule onLoadedTask.");
- return;
- }
+ scheduler.run(new onLoadedTask(this));
getCommand("townychat").setExecutor(new TownyChatCommand(this));
getCommand("channel").setExecutor(new ChannelCommand(this));
@@ -300,4 +300,17 @@ public Channel getPlayerChannel(Player player) {
public void setPlayerChannel(Player player, Channel channel) {
playerChannelMap.put(player.getUniqueId(), channel);
}
+
+ public TaskScheduler getScheduler() {
+ return this.scheduler;
+ }
+
+ private static boolean isFoliaClassPresent() {
+ try {
+ Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/palmergames/bukkit/TownyChat/Command/commandobjects/ChannelJoinAliasCommand.java b/src/com/palmergames/bukkit/TownyChat/Command/commandobjects/ChannelJoinAliasCommand.java
index 0846f70..e8aba9f 100644
--- a/src/com/palmergames/bukkit/TownyChat/Command/commandobjects/ChannelJoinAliasCommand.java
+++ b/src/com/palmergames/bukkit/TownyChat/Command/commandobjects/ChannelJoinAliasCommand.java
@@ -5,6 +5,7 @@
import com.palmergames.bukkit.TownyChat.events.PlayerJoinChatChannelEvent;
import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.object.Translatable;
+import com.palmergames.bukkit.towny.scheduling.TaskScheduler;
import com.palmergames.bukkit.util.Colors;
import com.palmergames.util.StringMgmt;
@@ -75,8 +76,9 @@ public boolean execute(CommandSender commandSender, String label, String[] args)
final String msg = message;
// https://www.spigotmc.org/threads/plugins-triggering-commands-async.31815/
- if (!Bukkit.isPrimaryThread()) {
- Bukkit.getScheduler().runTask(plugin, () -> player.chat(msg));
+ TaskScheduler scheduler = plugin.getScheduler();
+ if (!scheduler.isEntityThread(player)) {
+ scheduler.run(player, () -> player.chat(msg));
} else {
player.chat(msg);
}
diff --git a/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java b/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
index 0e15183..b0a9728 100644
--- a/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
+++ b/src/com/palmergames/bukkit/TownyChat/listener/TownyChatPlayerListener.java
@@ -15,7 +15,6 @@
import me.clip.placeholderapi.PlaceholderAPI;
-import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -39,7 +38,7 @@ public TownyChatPlayerListener(Chat instance) {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event) {
- Bukkit.getScheduler().runTaskLater(plugin, () -> loginPlayer(event.getPlayer()), 2l);
+ plugin.getScheduler().runLater(event.getPlayer(), () -> loginPlayer(event.getPlayer()), 2L);
}