From a739de61cb366e91008ea0d756aa61d164e3aac4 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Fri, 29 Mar 2019 11:37:20 +0000
Subject: [PATCH] Fix PersistentStructureLegacy NPE on custom worlds

This is caused due to the DimensionManager in CB worlds not being
registered by NMS, we fix this by copying CBs behavior of using the
world providers DimensionManager, vs using the actual dimension manager
of the world
---
 .../Optimize-Persistent-Data-Loading.patch        | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Spigot-Server-Patches/Optimize-Persistent-Data-Loading.patch b/Spigot-Server-Patches/Optimize-Persistent-Data-Loading.patch
index ef62ff8c7d..83d418912d 100644
--- a/Spigot-Server-Patches/Optimize-Persistent-Data-Loading.patch
+++ b/Spigot-Server-Patches/Optimize-Persistent-Data-Loading.patch
@@ -14,7 +14,7 @@ These files take a long time to convert on large worlds and crashes the server.
 Additionally, cache the result of a file being missing so we don't keep spam checking it.
 
 diff --git a/src/main/java/net/minecraft/server/WorldPersistentData.java b/src/main/java/net/minecraft/server/WorldPersistentData.java
-index 8d51af286..e86d382c8 100644
+index 8d51af2867..e86d382c8d 100644
 --- a/src/main/java/net/minecraft/server/WorldPersistentData.java
 +++ b/src/main/java/net/minecraft/server/WorldPersistentData.java
 @@ -0,0 +0,0 @@ public class WorldPersistentData {
@@ -51,4 +51,17 @@ index 8d51af286..e86d382c8 100644
          File file = idatamanager.getDataFile(dimensionmanager, s);
          FileInputStream fileinputstream = new FileInputStream(file);
          Throwable throwable = null;
+diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
+index 5c2421ac38..ee071ba2f6 100644
+--- a/src/main/java/net/minecraft/server/WorldServer.java
++++ b/src/main/java/net/minecraft/server/WorldServer.java
+@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler {
+         this.P();
+         this.Q();
+         this.getWorldBorder().a(minecraftserver.au());
+-        MCUtil.scheduleAsyncTask(() -> this.getChunkProvider().chunkLoader.getPersistentStructureLegacy(dimensionmanager, worldMaps)); // Paper
++        MCUtil.scheduleAsyncTask(() -> this.getChunkProvider().chunkLoader.getPersistentStructureLegacy(worldProvider.getDimensionManager(), worldMaps)); // Paper
+     }
+ 
+     public WorldServer i_() {
 --
\ No newline at end of file