From 355eea1cf9aad1dcb06d0e15818d560b9e2b6a31 Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 13 Jul 2023 18:35:49 -0600 Subject: [PATCH] @kugge: Fixed Folia teleportation in unloaded chunks (#368) --- .../net/coreprotect/command/TeleportCommand.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/coreprotect/command/TeleportCommand.java b/src/main/java/net/coreprotect/command/TeleportCommand.java index fc4420a..dfa08c9 100644 --- a/src/main/java/net/coreprotect/command/TeleportCommand.java +++ b/src/main/java/net/coreprotect/command/TeleportCommand.java @@ -6,8 +6,10 @@ import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import net.coreprotect.CoreProtect; import net.coreprotect.config.ConfigHandler; import net.coreprotect.language.Phrase; +import net.coreprotect.thread.Scheduler; import net.coreprotect.utility.Chat; import net.coreprotect.utility.ChatMessage; import net.coreprotect.utility.Color; @@ -99,12 +101,14 @@ public class TeleportCommand { int chunkX = location.getBlockX() >> 4; int chunkZ = location.getBlockZ() >> 4; - if (location.getWorld().isChunkLoaded(chunkX, chunkZ) == false) { - location.getWorld().getChunkAt(location); - } + Scheduler.runTask(CoreProtect.getInstance(), () -> { + if (!location.getWorld().isChunkLoaded(chunkX, chunkZ)) { + location.getWorld().getChunkAt(location); + } - // Teleport the player to a safe location - Teleport.performSafeTeleport(((Player) player), location, true); + // Teleport the player to a safe location + Teleport.performSafeTeleport(((Player) player), location, true); + }, location); ConfigHandler.teleportThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() }); }