Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Folia Support #243

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>com.tcoded.folialib</pattern>
<shadedPattern>com.loohp.interactivechat.libs.com.tcoded.folialib</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>com.loohp.interactivechat.libs.net.kyori</shadedPattern>
Expand Down Expand Up @@ -318,6 +322,12 @@
</repositories>

<dependencies>
<dependency>
<groupId>com.github.technicallycoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.Carleslc.Simple-YAML</groupId>
<artifactId>Simple-Yaml</artifactId>
Expand Down
32 changes: 16 additions & 16 deletions common/src/main/java/com/loohp/interactivechat/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
ConfigManager.reloadConfig();
InteractiveChat.placeholderCooldownManager.reloadPlaceholders();
PlayerUtils.resetAllPermissionCache();
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> InteractiveChat.playerDataManager.reload());
InteractiveChat.plugin.getScheduler().runAsync((task) -> InteractiveChat.playerDataManager.reload());
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.reloadBungeeConfig(System.currentTimeMillis());
Expand All @@ -107,7 +107,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (sender.hasPermission("interactivechat.update")) {
sender.sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "[InteractiveChat] You are running InteractiveChat version: " + InteractiveChat.plugin.getDescription().getVersion());
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runAsync((task) -> {
UpdaterResponse version = Updater.checkUpdate();
if (version.getResult().equals("latest")) {
if (version.isDevBuildLatest()) {
Expand All @@ -133,11 +133,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
if (pd.isMentionDisabled()) {
pd.setMentionDisabled(false);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.mentionEnable);
} else {
pd.setMentionDisabled(true);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.mentionDisable);
}
if (InteractiveChat.bungeecordMode) {
Expand All @@ -157,11 +157,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
if (pd.isMentionDisabled()) {
pd.setMentionDisabled(false);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.mentionEnable);
} else {
pd.setMentionDisabled(true);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.mentionDisable);
}
if (InteractiveChat.bungeecordMode) {
Expand Down Expand Up @@ -198,7 +198,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player player = (Player) sender;
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
pd.setInventoryDisplayLayout(layout);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.setInvDisplayLayout.replace("{Layout}", layout + ""));
if (InteractiveChat.bungeecordMode) {
try {
Expand All @@ -220,7 +220,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
pd.setInventoryDisplayLayout(layout);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save());
sender.sendMessage(InteractiveChat.setInvDisplayLayout.replace("{Layout}", layout + ""));
if (InteractiveChat.bungeecordMode) {
try {
Expand Down Expand Up @@ -302,7 +302,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
String str = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
Player player = (Player) sender;
Optional<ICPlayer> icplayer = Optional.of(ICPlayerFactory.getICPlayer(player));
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runAsync((task) -> {
String text = str;
try {
long unix = System.currentTimeMillis();
Expand Down Expand Up @@ -359,7 +359,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args.length > 1) {
if (sender instanceof Player) {
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runNextTick((task) -> {
((Player) sender).chat(message);
});
} else {
Expand All @@ -375,7 +375,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (InteractiveChat.floodgateHook && args[0].equalsIgnoreCase("events")) {
if (sender.hasPermission("interactivechat.bedrock.events")) {
if (sender instanceof Player) {
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runAsync((task) -> {
UUID uuid = ((Player) sender).getUniqueId();
if (FloodgateHook.isFloodgatePlayer(uuid)) {
FloodgateHook.sendRecentChatMessagesForm(uuid);
Expand Down Expand Up @@ -425,15 +425,15 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (data == null || data.getInventoryDisplayLayout() == 0) {
Inventory inv = InteractiveChat.inventoryDisplay.get(hash);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
InteractiveChat.plugin.getScheduler().runAtEntity(player, (task) -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
} else {
Inventory inv = InteractiveChat.inventoryDisplay1Upper.get(hash);
Inventory inv2 = InteractiveChat.inventoryDisplay1Lower.get(hash);
if (inv != null && inv2 != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runAtEntity(player, (task) -> {
player.openInventory(inv);
InventoryUtils.sendFakePlayerInventory(player, inv2, true, false);
InteractiveChat.viewingInv1.put(player.getUniqueId(), hash);
Expand All @@ -447,7 +447,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
case "viewender": {
Inventory inv = InteractiveChat.enderDisplay.get(args[1]);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
InteractiveChat.plugin.getScheduler().runAtEntity(player, (task) -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
Expand All @@ -456,7 +456,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
case "viewitem": {
Inventory inv = InteractiveChat.itemDisplay.get(args[1]);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
InteractiveChat.plugin.getScheduler().runAtEntity(player, (task) -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
Expand All @@ -465,7 +465,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
case "viewmap":
ItemStack map = InteractiveChat.mapDisplay.get(args[1]);
if (map != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> MapViewer.showMap(player, map));
InteractiveChat.plugin.getScheduler().runAtEntity(player, (task) -> MapViewer.showMap(player, map));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
Expand Down
39 changes: 25 additions & 14 deletions common/src/main/java/com/loohp/interactivechat/InteractiveChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package com.loohp.interactivechat;

import com.tcoded.folialib.FoliaLib;
import com.tcoded.folialib.impl.PlatformScheduler;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.utility.MinecraftVersion;
Expand Down Expand Up @@ -372,13 +374,15 @@ public static void closeSharedInventoryViews() {

public static void closeInventoryViews(Inventory inventory) {
for (Player player : Bukkit.getOnlinePlayers()) {
Inventory topInventory = player.getOpenInventory().getTopInventory();
if (topInventory.equals(inventory)) {
player.closeInventory();
if (InteractiveChat.viewingInv1.remove(player.getUniqueId()) != null) {
InventoryUtils.restorePlayerInventory(player);
plugin.getScheduler().runAtEntity(player, (task) -> {
Inventory topInventory = player.getOpenInventory().getTopInventory();
if (topInventory.equals(inventory)) {
player.closeInventory();
if (InteractiveChat.viewingInv1.remove(player.getUniqueId()) != null) {
InventoryUtils.restorePlayerInventory(player);
}
}
}
});
}
}

Expand Down Expand Up @@ -413,6 +417,9 @@ public static boolean hasChatSigning() {

public ProcessExternalMessage externalProcessor;

public FoliaLib foliaLib = new FoliaLib(this);
public PlatformScheduler platformScheduler = foliaLib.getScheduler();

@Override
public void onEnable() {
plugin = this;
Expand Down Expand Up @@ -454,9 +461,9 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ServerPingListener(), this);
ServerPingListener.listen();

Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
InteractiveChat.plugin.getScheduler().runTimerAsync((outer) -> {
if (parsePAPIOnMainThread) {
Bukkit.getScheduler().runTask(plugin, () -> {
InteractiveChat.plugin.getScheduler().runNextTick((task) -> {
for (Player player : Bukkit.getOnlinePlayers()) {
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameHoverText);
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameClickValue);
Expand All @@ -470,14 +477,14 @@ public void onEnable() {
}
}, 0, 100);

Bukkit.getScheduler().runTaskTimer(plugin, () -> {
InteractiveChat.plugin.getScheduler().runTimer(() -> {
Map<UUID, Boolean> vanishStates = new HashMap<>();
for (ICPlayer player : ICPlayerFactory.getOnlineICPlayers()) {
if (player.isLocal()) {
vanishStates.put(player.getUniqueId(), player.isVanished());
}
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
InteractiveChat.plugin.getScheduler().runAsync((inner) -> {
try {
BungeeMessageSender.updatePlayersVanished(System.currentTimeMillis(), vanishStates);
} catch (Exception e) {
Expand All @@ -488,7 +495,7 @@ public void onEnable() {
}

BiConsumer<String, Inventory> inventoryRemovalListener = (hash, inv) -> {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> closeInventoryViews(inv));
InteractiveChat.plugin.getScheduler().runNextTick((task) -> closeInventoryViews(inv));
};
itemDisplay.registerRemovalListener(inventoryRemovalListener);
inventoryDisplay.registerRemovalListener(inventoryRemovalListener);
Expand All @@ -497,7 +504,7 @@ public void onEnable() {
enderDisplay.registerRemovalListener(inventoryRemovalListener);

mapDisplay.registerRemovalListener((hash, item) -> {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runNextTick((task) -> {
for (Player player : Bukkit.getOnlinePlayers()) {
boolean removed = MapViewer.MAP_VIEWERS.remove(player, item);
if (removed) {
Expand Down Expand Up @@ -661,7 +668,7 @@ public void onEnable() {

getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] InteractiveChat has been Enabled!");

Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
InteractiveChat.plugin.getScheduler().runTimerAsync(() -> {
if (queueRemoteUpdate && Bukkit.getOnlinePlayers().size() > 0) {
try {
if (BungeeMessageSender.resetAndForwardPlaceholderList(System.currentTimeMillis(), InteractiveChat.placeholderList.values())) {
Expand Down Expand Up @@ -695,11 +702,12 @@ public void onDisable() {
OutMessagePacket.getAsyncChatSendingExecutor().close();
} catch (Exception ignored) {
}
platformScheduler.cancelAllTasks();
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[InteractiveChat] InteractiveChat has been Disabled!");
}

private void gc() {
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
InteractiveChat.plugin.getScheduler().runTimerAsync(() -> {
itemDisplay.cleanUp();
inventoryDisplay.cleanUp();
inventoryDisplay1Upper.cleanUp();
Expand All @@ -709,4 +717,7 @@ private void gc() {
}, 0, 1200);
}

public PlatformScheduler getScheduler() {
return platformScheduler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public BungeeMessageListener(InteractiveChat instance) {

public void addToComplete(UUID uuid, CompletableFuture<?> future) {
toComplete.put(uuid, future);
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
InteractiveChat.plugin.getScheduler().runLaterAsync(() -> {
CompletableFuture<?> f = toComplete.remove(uuid);
if (f != null && !f.isDone() && !f.isCompletedExceptionally() && !f.isCancelled()) {
f.completeExceptionally(new TimeoutException("The proxy did not respond in time"));
Expand All @@ -103,7 +103,7 @@ public void onPluginMessageReceived(String channel, Player pluginMessagingPlayer
return;
}

Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runAsync((task) -> {
try {
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);

Expand Down Expand Up @@ -252,7 +252,7 @@ public void onPluginMessageReceived(String channel, Player pluginMessagingPlayer
break;
}
InteractiveChat.messages.put(message, uuid3);
Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(message), 60);
InteractiveChat.plugin.getScheduler().runLater((inner) -> InteractiveChat.messages.remove(message), 60);
break;
case 0x07:
int cooldownType = input.readByte();
Expand Down Expand Up @@ -430,7 +430,7 @@ public void onPluginMessageReceived(String channel, Player pluginMessagingPlayer
String command = DataTypeIO.readString(input, StandardCharsets.UTF_8);
Player player4 = Bukkit.getPlayer(playerUUID5);
if (player4 != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> PlayerUtils.dispatchCommandAsPlayer(player4, command));
InteractiveChat.plugin.getScheduler().runNextTick((inner) -> PlayerUtils.dispatchCommandAsPlayer(player4, command));
}
break;
case 0xFF:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class BungeeMessageSender {
protected static short inventoryScheme = 0;

static {
Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> {
int size = sent.size();
for (int i = size; i > 500; i--) {
sent.remove(sent.firstKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onPacketSending(PacketEvent event) {
}
});

Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> {
InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> {
REQUESTS.entrySet().removeIf(entry -> System.currentTimeMillis() > entry.getValue());
}, 0, 20);
}
Expand Down
Loading