Folia Support (#46)

* Folia Support

* Unused import.

* Changelog and min. version bump.

---------

Co-authored-by: LlmDl <[email protected]>
This commit is contained in:
WarriorandLlmDl authored and GitHub committed 2023-05-09 15:03:06 -05:00
1 parent 60168fae2c
commit 945b66f803
6 files changed
+37 -19

No files matched your search

+3 -3
View File
@@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId>
<packaging>jar</packaging>
<version>0.104</version>
<version>0.105</version>
<licenses>
<license>
@@ -26,7 +26,7 @@
<java.version>17</java.version>
<project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<towny.version>0.99.0.0</towny.version>
<towny.version>0.99.0.6</towny.version>
</properties>
<!-- For use with GitHub Package Registry -->
@@ -75,7 +75,7 @@
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.99.0.0</version>
<version>${towny.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
+4 -1
View File
@@ -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
- 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.
+1
View File
@@ -8,6 +8,7 @@ description: >
TownyChat plugin which hooks into Towny.
depend: [Towny]
softdepend: [CraftIRC, PlaceholderAPI, dynmap, EssentialsDiscord]
folia-supported: true
############################################################
# +------------------------------------------------------+ #
+24 -11
View File
@@ -13,6 +13,9 @@ import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
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<UUID, Channel> 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 class Chat extends JavaPlugin {
* 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 class Chat extends JavaPlugin {
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;
}
}
}
@@ -5,6 +5,7 @@ import com.palmergames.bukkit.TownyChat.channels.Channel;
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 class ChannelJoinAliasCommand extends BukkitCommand {
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);
}
@@ -15,7 +15,6 @@ import com.palmergames.bukkit.util.Colors;
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 class TownyChatPlayerListener implements Listener {
@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);
}