From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Tue, 21 May 2019 02:34:04 +0100
Subject: [PATCH] improve CraftWorld#isChunkLoaded

getChunkAt will request the chunk using vanillas chunk loading system,
which while we're not going to load the chunk, does involve the server
waiting for the execution queue to get to our request; We can just query
the chunk status and get a response now, vs having to wait

diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 0d5731429abe7b4ff97d6644ff088063dde19e60..5ea7b0b25ae837645f690443d674ce7eb48c1692 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -405,14 +405,13 @@ public class CraftWorld implements World {
 
     @Override
     public boolean isChunkLoaded(int x, int z) {
-        net.minecraft.server.Chunk chunk = world.getChunkProvider().getChunkAt(x, z, false);
-        return chunk != null;
+        return world.getChunkProvider().getChunkAtIfLoadedImmediately(x, z) != null; // Paper
     }
 
     @Override
     public boolean isChunkGenerated(int x, int z) {
         try {
-            return isChunkLoaded(x, z) || world.getChunkProvider().playerChunkMap.read(new ChunkCoordIntPair(x, z)) != null;
+            return world.getChunkProvider().getChunkAtIfCachedImmediately(x, z) != null || world.getChunkProvider().playerChunkMap.read(new ChunkCoordIntPair(x, z)) != null; // Paper (TODO check if the first part can be removed)
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         }
