diff --git a/common/pom.xml b/common/pom.xml index 0007a6a9..f4ee3647 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -71,6 +71,10 @@ false false + + com.tcoded.folialib + com.loohp.interactivechat.libs.com.tcoded.folialib + net.kyori com.loohp.interactivechat.libs.net.kyori @@ -318,6 +322,12 @@ + + com.github.technicallycoded + FoliaLib + 0.4.3 + compile + com.github.Carleslc.Simple-YAML Simple-Yaml diff --git a/common/src/main/java/com/loohp/interactivechat/Commands.java b/common/src/main/java/com/loohp/interactivechat/Commands.java index d86c3bbd..34c6a406 100644 --- a/common/src/main/java/com/loohp/interactivechat/Commands.java +++ b/common/src/main/java/com/loohp/interactivechat/Commands.java @@ -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()); @@ -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()) { @@ -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) { @@ -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) { @@ -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 { @@ -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 { @@ -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 = Optional.of(ICPlayerFactory.getICPlayer(player)); - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { String text = str; try { long unix = System.currentTimeMillis(); @@ -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 { @@ -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); @@ -425,7 +425,7 @@ 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)); } @@ -433,7 +433,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String 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); @@ -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)); } @@ -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)); } @@ -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)); } diff --git a/common/src/main/java/com/loohp/interactivechat/InteractiveChat.java b/common/src/main/java/com/loohp/interactivechat/InteractiveChat.java index dfd14331..47f0fc67 100644 --- a/common/src/main/java/com/loohp/interactivechat/InteractiveChat.java +++ b/common/src/main/java/com/loohp/interactivechat/InteractiveChat.java @@ -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; @@ -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); + } } - } + }); } } @@ -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; @@ -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); @@ -470,14 +477,14 @@ public void onEnable() { } }, 0, 100); - Bukkit.getScheduler().runTaskTimer(plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimer(() -> { Map 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) { @@ -488,7 +495,7 @@ public void onEnable() { } BiConsumer inventoryRemovalListener = (hash, inv) -> { - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> closeInventoryViews(inv)); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> closeInventoryViews(inv)); }; itemDisplay.registerRemovalListener(inventoryRemovalListener); inventoryDisplay.registerRemovalListener(inventoryRemovalListener); @@ -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) { @@ -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())) { @@ -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(); @@ -709,4 +717,7 @@ private void gc() { }, 0, 1200); } + public PlatformScheduler getScheduler() { + return platformScheduler; + } } diff --git a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageListener.java b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageListener.java index af581d9b..75a7abd0 100644 --- a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageListener.java +++ b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageListener.java @@ -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")); @@ -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); @@ -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(); @@ -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: diff --git a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageSender.java b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageSender.java index 38c4a722..4212dabb 100644 --- a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageSender.java +++ b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/BungeeMessageSender.java @@ -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()); diff --git a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/ServerPingListener.java b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/ServerPingListener.java index 065dcb92..359a0add 100644 --- a/common/src/main/java/com/loohp/interactivechat/bungeemessaging/ServerPingListener.java +++ b/common/src/main/java/com/loohp/interactivechat/bungeemessaging/ServerPingListener.java @@ -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); } diff --git a/common/src/main/java/com/loohp/interactivechat/config/ConfigManager.java b/common/src/main/java/com/loohp/interactivechat/config/ConfigManager.java index 03c4c0ef..6fe12e5f 100644 --- a/common/src/main/java/com/loohp/interactivechat/config/ConfigManager.java +++ b/common/src/main/java/com/loohp/interactivechat/config/ConfigManager.java @@ -422,7 +422,7 @@ public static void loadConfig() { InteractiveChat.language = getConfig().getString("Settings.Language"); - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { LanguageUtils.loadTranslations(InteractiveChat.language); if (WebData.getInstance() == null) { WebData.newInstance(); diff --git a/common/src/main/java/com/loohp/interactivechat/data/PlayerDataManager.java b/common/src/main/java/com/loohp/interactivechat/data/PlayerDataManager.java index f7202ea0..b8812f8c 100644 --- a/common/src/main/java/com/loohp/interactivechat/data/PlayerDataManager.java +++ b/common/src/main/java/com/loohp/interactivechat/data/PlayerDataManager.java @@ -69,7 +69,7 @@ public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); UUID playerUUID = player.getUniqueId(); - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { if (!database.playerExists(playerUUID)) { database.createPlayer(playerUUID, player.getName()); } @@ -82,7 +82,7 @@ public void onJoin(PlayerJoinEvent event) { public void onLeave(PlayerQuitEvent event) { PlayerData pd = data.remove(event.getPlayer().getUniqueId()); if (pd != null) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> pd.save()); + InteractiveChat.plugin.getScheduler().runAsync((task) -> pd.save()); } } diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/dynmap/DynmapListener.java b/common/src/main/java/com/loohp/interactivechat/hooks/dynmap/DynmapListener.java index b3f3abd9..3f99e8e9 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/dynmap/DynmapListener.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/dynmap/DynmapListener.java @@ -66,7 +66,7 @@ public static void _init_() { public void onPluginEnable(PluginEnableEvent event) { if (init) { if (event.getPlugin().getName().equalsIgnoreCase("dynmap")) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { _init_(); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + "[InteractiveChat] InteractiveChat has injected into Dynmap!"); }, 100); diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/eco/EcoHook.java b/common/src/main/java/com/loohp/interactivechat/hooks/eco/EcoHook.java index 53af192b..53993354 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/eco/EcoHook.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/eco/EcoHook.java @@ -67,10 +67,16 @@ public static Future setEcoLore(ItemStack itemStack) { } public static Future setEcoLore(ItemStack itemStack, Player player) { - if (!InteractiveChat.ecoSetLoreOnMainThread || Bukkit.isPrimaryThread()) { + InteractiveChat plugin = InteractiveChat.getPlugin(InteractiveChat.class); + if (!InteractiveChat.ecoSetLoreOnMainThread || plugin.getScheduler().isGlobalTickThread()) { return CompletableFuture.completedFuture(setEcoLore0(itemStack.clone(), player)); } else { - return Bukkit.getScheduler().callSyncMethod(InteractiveChat.plugin, () -> setEcoLore0(itemStack.clone(), player)); + CompletableFuture future = new CompletableFuture<>(); + plugin.getScheduler().runAtEntity(player, (task) -> { + setEcoLore0(itemStack.clone(), player); + future.complete(itemStack); + }); + return future; } } diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/essentials/EssentialsNicknames.java b/common/src/main/java/com/loohp/interactivechat/hooks/essentials/EssentialsNicknames.java index 5ed275c0..4d55bc31 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/essentials/EssentialsNicknames.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/essentials/EssentialsNicknames.java @@ -60,7 +60,7 @@ public static void init() { } }); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { for (Player player : Bukkit.getOnlinePlayers()) { loadNicks(player); } @@ -80,7 +80,7 @@ public static void loadNicks(Player player) { public void onEssentialsReload(PlayerCommandPreprocessEvent event) { if (event.getMessage().equalsIgnoreCase("/essentials reload")) { if (event.getPlayer().hasPermission("essentials.essentials")) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { prefix = essen.getConfig().getString("nickname-prefix"); }, 40); } @@ -100,7 +100,7 @@ public void onEssentialsNickChange(NickChangeEvent event) { @EventHandler public void onEssentialsJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { loadNicks(player); }, 100); } diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/floodgate/FloodgateHook.java b/common/src/main/java/com/loohp/interactivechat/hooks/floodgate/FloodgateHook.java index bc865c3c..693d5b30 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/floodgate/FloodgateHook.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/floodgate/FloodgateHook.java @@ -162,7 +162,7 @@ private static void handleRunCommand(UUID uuid, String command) { } else { Player player = Bukkit.getPlayer(uuid); if (player != null) { - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> PlayerUtils.dispatchCommandAsPlayer(player, command)); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> PlayerUtils.dispatchCommandAsPlayer(player, command)); } } } diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/luckperms/LuckPermsEvents.java b/common/src/main/java/com/loohp/interactivechat/hooks/luckperms/LuckPermsEvents.java index 4db65af0..28a5dbc6 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/luckperms/LuckPermsEvents.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/luckperms/LuckPermsEvents.java @@ -41,7 +41,7 @@ public LuckPermsEvents(InteractiveChat plugin) { UUID uuid = event.getUser().getUniqueId(); if (!scheduledReset.contains(uuid)) { scheduledReset.add(uuid); - Bukkit.getScheduler().runTaskLater(plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater(() -> { PlayerUtils.resetPermissionCache(uuid); scheduledReset.remove(uuid); }, 1); diff --git a/common/src/main/java/com/loohp/interactivechat/hooks/venturechat/VentureChatInjection.java b/common/src/main/java/com/loohp/interactivechat/hooks/venturechat/VentureChatInjection.java index 1e453114..18d4862f 100644 --- a/common/src/main/java/com/loohp/interactivechat/hooks/venturechat/VentureChatInjection.java +++ b/common/src/main/java/com/loohp/interactivechat/hooks/venturechat/VentureChatInjection.java @@ -62,7 +62,7 @@ public static void firePacketListener(PacketEvent event) { public void onPluginEnable(PluginEnableEvent event) { if (init) { if (event.getPlugin().getName().equalsIgnoreCase("VentureChat")) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { _init_(); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + "[InteractiveChat] InteractiveChat has injected into VentureChat!"); }, 100); diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/ChatEvents.java b/common/src/main/java/com/loohp/interactivechat/listeners/ChatEvents.java index 401b4c86..e906a547 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/ChatEvents.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/ChatEvents.java @@ -358,7 +358,7 @@ public static void checkChatMessage(AsyncPlayerChatEvent event) { String mapKey = ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', event.getMessage())); InteractiveChat.messages.put(mapKey, player.getUniqueId()); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(mapKey), 60); + InteractiveChat.plugin.getScheduler().runLater((task) -> InteractiveChat.messages.remove(mapKey), 60); if (InteractiveChat.bungeecordMode) { try { diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/ClientSettingPacket.java b/common/src/main/java/com/loohp/interactivechat/listeners/ClientSettingPacket.java index 88856caa..c280d5d2 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/ClientSettingPacket.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/ClientSettingPacket.java @@ -73,9 +73,9 @@ public static void handlePacketReceiving(PacketEvent event) { boolean colorSettings = NMS.getInstance().getColorSettingsFromClientInformationPacket(packet); boolean originalColorSettings = PlayerUtils.canChatColor(player); if (originalColorSettings && !colorSettings) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsDisabled"))), 5); + InteractiveChat.plugin.getScheduler().runLater((task) -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsDisabled"))), 5); } else if (!originalColorSettings && colorSettings) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsReEnabled"))), 5); + InteractiveChat.plugin.getScheduler().runLater((task) -> player.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', ConfigManager.getConfig().getString("Messages.ColorsReEnabled"))), 5); } } diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/InventoryEvents.java b/common/src/main/java/com/loohp/interactivechat/listeners/InventoryEvents.java index 31c51c7c..0b6da5c1 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/InventoryEvents.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/InventoryEvents.java @@ -67,9 +67,9 @@ public void onInventoryClick(InventoryClickEvent event) { if (hash != null) { Inventory fakeInv = InteractiveChat.inventoryDisplay1Lower.get(hash); if (fakeInv == null) { - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.closeInventory()); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> player.closeInventory()); } else { - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> InventoryUtils.sendFakePlayerInventory(player, fakeInv, true, false)); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> InventoryUtils.sendFakePlayerInventory(player, fakeInv, true, false)); } } if (event.getView().getTopInventory() == null) { @@ -157,7 +157,7 @@ private void inventoryAction(ItemStack item, Player player, Inventory topInvento displayInventory.setItem(i + 9, containerItem == null ? null : containerItem.clone()); } - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAtEntityLater(player, (task) -> { ValuePairs opened; String hash = InteractiveChat.viewingInv1.remove(player.getUniqueId()); if (hash != null) { @@ -179,7 +179,7 @@ private void inventoryAction(ItemStack item, Player player, Inventory topInvento public void onInventoryClickHighest(InventoryClickEvent event) { if (CANCELLED_INVENTORY.remove(event)) { event.setCancelled(true); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> ((Player) event.getWhoClicked()).updateInventory(), 5); + InteractiveChat.plugin.getScheduler().runAtEntityLater(event.getWhoClicked(), (task) -> ((Player) event.getWhoClicked()).updateInventory(), 5); } } @@ -193,7 +193,7 @@ public void onInventoryClose(InventoryCloseEvent event) { if (topInventory != null) { ValuePairs opened = InteractiveChat.containerDisplay.remove(topInventory); if (opened != null) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAtEntityLater(player, (task) -> { player.openInventory(opened.getFirst()); String hash = opened.getSecond(); if (hash != null) { diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/MapViewer.java b/common/src/main/java/com/loohp/interactivechat/listeners/MapViewer.java index d84318c7..fa49d275 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/MapViewer.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/MapViewer.java @@ -23,7 +23,6 @@ import com.loohp.interactivechat.InteractiveChat; import com.loohp.interactivechat.nms.NMS; import com.loohp.interactivechat.utils.FilledMapUtils; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -42,7 +41,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.map.MapCursor; import org.bukkit.map.MapView; -import org.bukkit.scheduler.BukkitRunnable; import java.util.Iterator; import java.util.List; @@ -66,30 +64,27 @@ public static void showMap(Player player, ItemStack item) { NMS.getInstance().sendFakeMainHandSlot(player, item); MAP_VIEWERS.put(player, item); - - new BukkitRunnable() { - @Override - public void run() { - ItemStack itemStack = MAP_VIEWERS.get(player); - if (itemStack != null && itemStack.equals(item)) { - if (!player.getInventory().containsAtLeast(itemStack, 1)) { - byte[] colors = FilledMapUtils.getColors(mapView, player); - List mapCursors = FilledMapUtils.getCursors(mapView, player); - Iterator itr = mapCursors.iterator(); - while (itr.hasNext()) { - MapCursor mapCursor = itr.next(); - int type = mapCursor.getRawType(); - if (type == 0 || type == 6 || type == 7) { - itr.remove(); - } + + InteractiveChat.plugin.getScheduler().runTimer((outer) -> { + ItemStack itemStack = MAP_VIEWERS.get(player); + if (itemStack != null && itemStack.equals(item)) { + if (!player.getInventory().containsAtLeast(itemStack, 1)) { + byte[] colors = FilledMapUtils.getColors(mapView, player); + List mapCursors = FilledMapUtils.getCursors(mapView, player); + Iterator itr = mapCursors.iterator(); + while (itr.hasNext()) { + MapCursor mapCursor = itr.next(); + int type = mapCursor.getRawType(); + if (type == 0 || type == 6 || type == 7) { + itr.remove(); } - NMS.getInstance().sendFakeMapUpdate(player, mapId, mapCursors, colors); } - } else { - this.cancel(); + NMS.getInstance().sendFakeMapUpdate(player, mapId, mapCursors, colors); } + } else { + outer.cancel(); } - }.runTaskTimer(InteractiveChat.plugin, 0, 1); + }, 0, 1); } catch (Exception e) { e.printStackTrace(); } @@ -111,7 +106,7 @@ public void onInventory(InventoryOpenEvent event) { public void onInventory(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); if (player.getGameMode().equals(GameMode.CREATIVE)) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { boolean removed = MAP_VIEWERS.remove(player) != null; if (removed) { @@ -141,7 +136,7 @@ public void onInventory(InventoryCreativeEvent event) { if (removed) { if (player.getInventory().equals(event.getClickedInventory()) && slot >= 9) { ItemStack item = player.getInventory().getItem(slot); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.getInventory().setItem(slot, item), 1); + InteractiveChat.plugin.getScheduler().runLater((task) -> player.getInventory().setItem(slot, item), 1); } else { event.setCursor(null); } @@ -167,7 +162,7 @@ public void onSlotChange(PlayerItemHeldEvent event) { if (removed) { player.getInventory().setHeldItemSlot(lastSlot); NMS.getInstance().sendFakeMainHandSlot(player, player.getInventory().getItemInHand()); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> player.getInventory().setHeldItemSlot(slot), 1); + InteractiveChat.plugin.getScheduler().runLater((task) -> player.getInventory().setHeldItemSlot(slot), 1); } } @@ -180,7 +175,7 @@ public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (player.getGameMode().equals(GameMode.CREATIVE)) { - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { boolean removed = MAP_VIEWERS.remove(player) != null; if (removed) { diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/OutMessagePacket.java b/common/src/main/java/com/loohp/interactivechat/listeners/OutMessagePacket.java index ea31d603..e99b7523 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/OutMessagePacket.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/OutMessagePacket.java @@ -575,7 +575,7 @@ private static void processPacket(Player receiver, ICPlayer determinedSender, Pa if (sender.isPresent() && !sender.get().isLocal()) { if (isFiltered) { - Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLaterAsync((task) -> { SERVICE.execute(() -> { processPacket(receiver, determinedSender, packet, messageUUID, false, packetHandler); }, receiver, messageUUID); @@ -673,7 +673,7 @@ private static void processPacket(Player receiver, ICPlayer determinedSender, Pa PreChatPacketSendEvent sendEvent = new PreChatPacketSendEvent(true, receiver, packet, component, postEventSenderUUID, originalPacket, InteractiveChat.sendOriginalIfTooLong, longerThanMaxLength); Bukkit.getPluginManager().callEvent(sendEvent); - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { InteractiveChat.keyTime.remove(rawMessageKey); InteractiveChat.keyPlayer.remove(rawMessageKey); }, 10); diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/OutTabCompletePacket.java b/common/src/main/java/com/loohp/interactivechat/listeners/OutTabCompletePacket.java index 23948a78..eba19c09 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/OutTabCompletePacket.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/OutTabCompletePacket.java @@ -59,7 +59,7 @@ public class OutTabCompletePacket { private static AtomicReference> playernames = new AtomicReference<>(new HashMap<>()); public static void tabCompleteListener() { - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((outer) -> { if (InteractiveChat.useTooltipOnTab) { Map playernames = new HashMap<>(); for (ICPlayer player : ICPlayerFactory.getOnlineICPlayers()) { @@ -72,7 +72,7 @@ public static void tabCompleteListener() { playernames.put(ChatColorUtils.stripColor(name), player.getUniqueId()); } } - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> OutTabCompletePacket.playernames.set(playernames)); + InteractiveChat.plugin.getScheduler().runNextTick((inner) -> OutTabCompletePacket.playernames.set(playernames)); } }, 0, 100); diff --git a/common/src/main/java/com/loohp/interactivechat/listeners/RedispatchSignedPacket.java b/common/src/main/java/com/loohp/interactivechat/listeners/RedispatchSignedPacket.java index 6d134640..701df90b 100644 --- a/common/src/main/java/com/loohp/interactivechat/listeners/RedispatchSignedPacket.java +++ b/common/src/main/java/com/loohp/interactivechat/listeners/RedispatchSignedPacket.java @@ -69,19 +69,19 @@ public void onPacketReceiving(PacketEvent event) { event.setReadOnly(false); event.setCancelled(true); event.setReadOnly(true); - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.chat(message)); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> player.chat(message)); } else { if (!ModernChatSigningUtils.isChatMessageIllegal(message)) { event.setReadOnly(false); event.setCancelled(true); event.setReadOnly(true); if (player.isConversing()) { - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.acceptConversationInput(message)); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> player.acceptConversationInput(message)); if (!InteractiveChat.skipDetectSpamRateWhenDispatchingUnsignedPackets) { - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> ModernChatSigningUtils.detectRateSpam(player, message)); + InteractiveChat.plugin.getScheduler().runAsync((task) -> ModernChatSigningUtils.detectRateSpam(player, message)); } } else { - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { try { Object decorated = ModernChatSigningUtils.getChatDecorator(player, LegacyComponentSerializer.legacySection().deserialize(message)).get(); PlayerUtils.chatAsPlayer(player, message, decorated); @@ -104,7 +104,7 @@ public void onPacketReceiving(PacketEvent event) { event.setReadOnly(false); event.setCancelled(true); event.setReadOnly(true); - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runNextTick((task) -> { PlayerUtils.dispatchCommandAsPlayer(player, command); if (!InteractiveChat.skipDetectSpamRateWhenDispatchingUnsignedPackets) { ModernChatSigningUtils.detectRateSpam(player, command); diff --git a/common/src/main/java/com/loohp/interactivechat/metrics/Metrics.java b/common/src/main/java/com/loohp/interactivechat/metrics/Metrics.java index 13bc7816..bf7b7cd5 100644 --- a/common/src/main/java/com/loohp/interactivechat/metrics/Metrics.java +++ b/common/src/main/java/com/loohp/interactivechat/metrics/Metrics.java @@ -24,6 +24,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import com.loohp.interactivechat.InteractiveChat; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -272,7 +273,7 @@ public void run() { } // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> submitData()); } }, 1000 * 60 * 5, 1000 * 60 * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start diff --git a/common/src/main/java/com/loohp/interactivechat/modules/InventoryDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/InventoryDisplay.java index b130d891..c1a1a654 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/InventoryDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/InventoryDisplay.java @@ -193,7 +193,7 @@ public static void layout0(ICPlayer player, String sha1, String title, Player re inv = event.getInventory(); Inventory finalRef = inv; - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { ItemStack skull = SkinUtils.getSkull(player.getUniqueId()); ItemMeta meta = skull.getItemMeta(); String name = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(player, InteractiveChat.invSkullName)); @@ -303,7 +303,7 @@ public static void layout1(ICPlayer player, String sha1, String title, Player re inv2 = event2.getInventory(); Inventory finalRef = inv; - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { ItemStack skull = SkinUtils.getSkull(player.getUniqueId()); ItemMeta meta = skull.getItemMeta(); String name = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(player, InteractiveChat.invSkullName)); diff --git a/common/src/main/java/com/loohp/interactivechat/modules/PlayernameDisplay.java b/common/src/main/java/com/loohp/interactivechat/modules/PlayernameDisplay.java index 93fa130f..b95aee77 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/PlayernameDisplay.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/PlayernameDisplay.java @@ -64,10 +64,10 @@ public class PlayernameDisplay implements Listener { public static void setup() { Bukkit.getPluginManager().registerEvents(new PlayernameDisplay(), InteractiveChat.plugin); - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((outer) -> { int valid = flag.get(); Collection names = getNames(); - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runNextTick((inner) -> { if (flag.get() == valid) { PlayernameDisplay.names = names; } diff --git a/common/src/main/java/com/loohp/interactivechat/modules/ProcessExternalMessage.java b/common/src/main/java/com/loohp/interactivechat/modules/ProcessExternalMessage.java index 63f137a6..e828a721 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/ProcessExternalMessage.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/ProcessExternalMessage.java @@ -340,7 +340,7 @@ public String processAndRespond0(Player receiver, String json, boolean preview) } } - Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLater((task) -> { InteractiveChat.keyTime.remove(rawMessageKey); InteractiveChat.keyPlayer.remove(rawMessageKey); }, 5); diff --git a/common/src/main/java/com/loohp/interactivechat/modules/SenderFinder.java b/common/src/main/java/com/loohp/interactivechat/modules/SenderFinder.java index bced22b4..31e20c50 100644 --- a/common/src/main/java/com/loohp/interactivechat/modules/SenderFinder.java +++ b/common/src/main/java/com/loohp/interactivechat/modules/SenderFinder.java @@ -51,7 +51,7 @@ public static Optional getSender(Component component, String messageKe String msg = entry.getKey(); if (chat.contains(msg)) { UUID uuid = entry.getValue(); - Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(msg), 5); + InteractiveChat.plugin.getScheduler().runLaterAsync(() -> InteractiveChat.messages.remove(msg), 5); ICPlayer wplayer = ICPlayerFactory.getICPlayer(uuid); if (wplayer != null) { return Optional.of(wplayer); @@ -73,7 +73,7 @@ public static Optional getSender(Component component, String messageKe if (mostsimular != null) { UUID uuid = InteractiveChat.messages.get(mostsimular); String finalmostsimular = mostsimular; - Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(finalmostsimular), 5); + InteractiveChat.plugin.getScheduler().runLaterAsync((task) -> InteractiveChat.messages.remove(finalmostsimular), 5); ICPlayer wplayer = ICPlayerFactory.getICPlayer(uuid); if (wplayer != null) { return Optional.of(wplayer); diff --git a/common/src/main/java/com/loohp/interactivechat/objectholders/AsyncChatSendingExecutor.java b/common/src/main/java/com/loohp/interactivechat/objectholders/AsyncChatSendingExecutor.java index 80769773..5f7362e3 100644 --- a/common/src/main/java/com/loohp/interactivechat/objectholders/AsyncChatSendingExecutor.java +++ b/common/src/main/java/com/loohp/interactivechat/objectholders/AsyncChatSendingExecutor.java @@ -23,6 +23,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.loohp.interactivechat.InteractiveChat; +import com.tcoded.folialib.wrapper.task.WrappedTask; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -58,7 +59,7 @@ public class AsyncChatSendingExecutor implements AutoCloseable { private final Map> waitingPackets; private final Map lastSuccessfulCheck; - private final List taskIds; + private final List taskIds; private final AtomicBoolean isValid; public AsyncChatSendingExecutor(LongSupplier executionWaitTime, long killThreadAfter) { @@ -124,10 +125,8 @@ public void discard(UUID player, UUID id) { @Override public synchronized void close() throws Exception { isValid.set(false); - for (int id : taskIds) { - if (id >= 0) { - Bukkit.getScheduler().cancelTask(id); - } + for (WrappedTask task : taskIds) { + InteractiveChat.plugin.getScheduler().cancelTask(task); } executor.shutdown(); } @@ -196,8 +195,8 @@ private void packetOrderSender() { }, "InteractiveChat Async ChatPacket Ordered Sending Thread").start(); } - private int packetSender() { - return Bukkit.getScheduler().runTaskTimer(InteractiveChat.plugin, () -> { + private WrappedTask packetSender() { + return InteractiveChat.plugin.getScheduler().runTimer(() -> { while (!sendingQueue.isEmpty()) { OutboundPacket out = sendingQueue.poll(); try { @@ -208,7 +207,7 @@ private int packetSender() { e.printStackTrace(); } } - }, 0, 1).getTaskId(); + }, 0, 1); } private void monitor() { diff --git a/common/src/main/java/com/loohp/interactivechat/objectholders/ICPlayerFactory.java b/common/src/main/java/com/loohp/interactivechat/objectholders/ICPlayerFactory.java index ab2377c9..751da1d2 100644 --- a/common/src/main/java/com/loohp/interactivechat/objectholders/ICPlayerFactory.java +++ b/common/src/main/java/com/loohp/interactivechat/objectholders/ICPlayerFactory.java @@ -108,7 +108,7 @@ public void onLeave(PlayerQuitEvent event) { } }, InteractiveChat.plugin); - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> REFERENCED_OFFLINE_PLAYERS.values().removeIf(each -> each.get() == null), 12000, 12000); + InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> REFERENCED_OFFLINE_PLAYERS.values().removeIf(each -> each.get() == null), 12000, 12000); } public static RemotePlayerCreateResult createOrUpdateRemoteICPlayer(String server, String name, UUID uuid, boolean rightHanded, int selectedSlot, int experienceLevel, Inventory inventory, Inventory enderchest, boolean vanished) { diff --git a/common/src/main/java/com/loohp/interactivechat/objectholders/MentionPair.java b/common/src/main/java/com/loohp/interactivechat/objectholders/MentionPair.java index ca632ddc..509b9f88 100644 --- a/common/src/main/java/com/loohp/interactivechat/objectholders/MentionPair.java +++ b/common/src/main/java/com/loohp/interactivechat/objectholders/MentionPair.java @@ -21,7 +21,7 @@ package com.loohp.interactivechat.objectholders; import com.loohp.interactivechat.InteractiveChat; -import org.bukkit.Bukkit; +import com.tcoded.folialib.wrapper.task.WrappedTask; import java.util.UUID; @@ -30,13 +30,13 @@ public class MentionPair { private final UUID sender; private final UUID receiver; private final long timestamp; - private final int taskid; + private final WrappedTask task; public MentionPair(UUID sender, UUID reciever) { this.sender = sender; this.receiver = reciever; this.timestamp = System.currentTimeMillis(); - this.taskid = run(); + this.task = run(); } public UUID getSender() { @@ -48,17 +48,17 @@ public UUID getReciever() { } public void remove() { - Bukkit.getScheduler().cancelTask(taskid); + task.cancel(); InteractiveChat.mentionPair.remove(this); } - private int run() { - return Bukkit.getScheduler().runTaskTimer(InteractiveChat.plugin, () -> { + private WrappedTask run() { + return InteractiveChat.plugin.getScheduler().runTimer(() -> { if ((System.currentTimeMillis() - timestamp) > 3000) { - Bukkit.getScheduler().cancelTask(taskid); + task.cancel(); InteractiveChat.mentionPair.remove(this); } - }, 0, 5).getTaskId(); + }, 0, 5); } @Override @@ -67,7 +67,6 @@ public int hashCode() { int result = 1; result = prime * result + ((receiver == null) ? 0 : receiver.hashCode()); result = prime * result + ((sender == null) ? 0 : sender.hashCode()); - result = prime * result + taskid; result = prime * result + (int) (timestamp ^ (timestamp >>> 32)); return result; } @@ -95,7 +94,7 @@ public boolean equals(Object obj) { } else if (!sender.equals(other.sender)) { return false; } - if (taskid != other.taskid) { + if (task != other.task) { return false; } return timestamp == other.timestamp; diff --git a/common/src/main/java/com/loohp/interactivechat/objectholders/ModernChatCompletionTask.java b/common/src/main/java/com/loohp/interactivechat/objectholders/ModernChatCompletionTask.java index 0e2c467f..bface025 100644 --- a/common/src/main/java/com/loohp/interactivechat/objectholders/ModernChatCompletionTask.java +++ b/common/src/main/java/com/loohp/interactivechat/objectholders/ModernChatCompletionTask.java @@ -60,7 +60,7 @@ public void onQuit(PlayerQuitEvent event) { } private void run() { - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> { if (InteractiveChat.chatTabCompletionsEnabled) { for (Player tabCompleter : Bukkit.getOnlinePlayers()) { Set tab = ConcurrentHashMap.newKeySet(); diff --git a/common/src/main/java/com/loohp/interactivechat/objectholders/WebData.java b/common/src/main/java/com/loohp/interactivechat/objectholders/WebData.java index b06cd98f..ab61fc18 100644 --- a/common/src/main/java/com/loohp/interactivechat/objectholders/WebData.java +++ b/common/src/main/java/com/loohp/interactivechat/objectholders/WebData.java @@ -79,7 +79,7 @@ private WebData() { } private void run() { - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> { reload(); }, 18000, 18000); } diff --git a/common/src/main/java/com/loohp/interactivechat/updater/Updater.java b/common/src/main/java/com/loohp/interactivechat/updater/Updater.java index bd74d442..4b6d1e1e 100644 --- a/common/src/main/java/com/loohp/interactivechat/updater/Updater.java +++ b/common/src/main/java/com/loohp/interactivechat/updater/Updater.java @@ -98,7 +98,7 @@ public static UpdaterResponse checkUpdate() { @EventHandler public void onJoin(PlayerJoinEvent event) { - Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runLaterAsync((task) -> { if (InteractiveChat.updaterEnabled) { Player player = event.getPlayer(); if (player.hasPermission("interactivechat.update")) { diff --git a/common/src/main/java/com/loohp/interactivechat/utils/LanguageUtils.java b/common/src/main/java/com/loohp/interactivechat/utils/LanguageUtils.java index 4cd14236..5a07223d 100644 --- a/common/src/main/java/com/loohp/interactivechat/utils/LanguageUtils.java +++ b/common/src/main/java/com/loohp/interactivechat/utils/LanguageUtils.java @@ -72,7 +72,7 @@ public class LanguageUtils { @SuppressWarnings("unchecked") public static void loadTranslations(String language) { Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] Loading languages..."); - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { while (lock.get()) { try { TimeUnit.MILLISECONDS.sleep(1); diff --git a/common/src/main/java/com/loohp/interactivechat/utils/PlaceholderParser.java b/common/src/main/java/com/loohp/interactivechat/utils/PlaceholderParser.java index 52996fdf..f4c5933d 100644 --- a/common/src/main/java/com/loohp/interactivechat/utils/PlaceholderParser.java +++ b/common/src/main/java/com/loohp/interactivechat/utils/PlaceholderParser.java @@ -47,7 +47,7 @@ public class PlaceholderParser { private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]"); static { - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> { if (InteractiveChat.bungeecordMode) { if (InteractiveChat.useTooltipOnTab) { for (Player player : Bukkit.getOnlinePlayers()) { @@ -62,7 +62,7 @@ public static String parse(OfflineICPlayer offlineICPlayer, String str) { if (InteractiveChat.parsePAPIOnMainThread && !Bukkit.isPrimaryThread()) { try { CompletableFuture future = new CompletableFuture<>(); - Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> future.complete(parse0(offlineICPlayer, str))); + InteractiveChat.plugin.getScheduler().runNextTick((task) -> future.complete(parse0(offlineICPlayer, str))); return future.get(1500, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); diff --git a/common/src/main/java/com/loohp/interactivechat/utils/PlayerUtils.java b/common/src/main/java/com/loohp/interactivechat/utils/PlayerUtils.java index 4945926e..1e352138 100644 --- a/common/src/main/java/com/loohp/interactivechat/utils/PlayerUtils.java +++ b/common/src/main/java/com/loohp/interactivechat/utils/PlayerUtils.java @@ -49,7 +49,7 @@ public class PlayerUtils implements Listener { private static final Map> PERMISSION_CACHE = new ConcurrentHashMap<>(); static { - Bukkit.getScheduler().runTaskTimerAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runTimerAsync((task) -> { long now = System.currentTimeMillis(); Iterator>> itr0 = PERMISSION_CACHE.entrySet().iterator(); while (itr0.hasNext()) { @@ -102,7 +102,7 @@ public static boolean hasPermission(UUID uuid, String permission, boolean def, i return result; } else { CompletableFuture future = new CompletableFuture<>(); - Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> { + InteractiveChat.plugin.getScheduler().runAsync((task) -> { Map map = PERMISSION_CACHE.get(uuid); if (map == null) { PERMISSION_CACHE.putIfAbsent(uuid, new ConcurrentHashMap<>()); diff --git a/common/src/main/java/com/loohp/interactivechat/utils/bossbar/BossBarUpdater.java b/common/src/main/java/com/loohp/interactivechat/utils/bossbar/BossBarUpdater.java index a70e7f83..1942ad2d 100644 --- a/common/src/main/java/com/loohp/interactivechat/utils/bossbar/BossBarUpdater.java +++ b/common/src/main/java/com/loohp/interactivechat/utils/bossbar/BossBarUpdater.java @@ -27,30 +27,25 @@ import net.kyori.adventure.bossbar.BossBar.Flag; import net.kyori.adventure.bossbar.BossBar.Overlay; import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; public abstract class BossBarUpdater implements BossBar.Listener, AutoCloseable { public static void countdownBossBar(BossBarUpdater updater, int ticks, int removeDelay) { - new BukkitRunnable() { - int tick = 0; - - @Override - public void run() { - tick++; - BossBar bossbar = updater.getBossBar(); - float current = 1 - (float) tick / (float) ticks; - bossbar.progress(Math.max(current, 0)); - if (current < 0) { - this.cancel(); - Bukkit.getScheduler().runTaskLaterAsynchronously(InteractiveChat.plugin, () -> updater.close(), removeDelay); - } + AtomicInteger tick = new AtomicInteger(0); + InteractiveChat.plugin.getScheduler().runTimerAsync((outer) -> { + tick.getAndIncrement(); + BossBar bossbar = updater.getBossBar(); + float current = 1 - (float) tick.get() / (float) ticks; + bossbar.progress(Math.max(current, 0)); + if (current < 0) { + outer.cancel(); + InteractiveChat.plugin.getScheduler().runLaterAsync((task) -> updater.close(), removeDelay); } - }.runTaskTimerAsynchronously(InteractiveChat.plugin, 0, 1); + }, 0, 1); } public static BossBarUpdater update(BossBar bossbar, Player... players) { diff --git a/common/src/main/resources/plugin.yml b/common/src/main/resources/plugin.yml index 81e4201e..836a43af 100644 --- a/common/src/main/resources/plugin.yml +++ b/common/src/main/resources/plugin.yml @@ -4,6 +4,7 @@ version: ${project.version} main: com.loohp.interactivechat.InteractiveChat api-version: 1.13 description: Make the chat interactive +folia-supported: true softdepend: - Essentials - EssentialsDiscord