From a4fe910f5722f9429ef926ce239bbb28926ca365 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 1 Jun 2020 23:51:37 -0400
Subject: [PATCH] Fix sounds when using worldedit regen command

Locks dimension manager to the first world its used with.

WE is creating a temp world and the world ref on that manager
is getting changed to the temp world.

This would of also caused a memory leak of that temp world too.
---
 Spigot-Server-Patches/0004-MC-Utils.patch  | 4 ++--
 Spigot-Server-Patches/0384-Anti-Xray.patch | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Spigot-Server-Patches/0004-MC-Utils.patch b/Spigot-Server-Patches/0004-MC-Utils.patch
index d6470aa738..e8581590a0 100644
--- a/Spigot-Server-Patches/0004-MC-Utils.patch
+++ b/Spigot-Server-Patches/0004-MC-Utils.patch
@@ -4399,7 +4399,7 @@ index 143be566c683ae035997f9a4058381a109f3de23..0e30d8c9933dc6595b9715ef6dc99cc8
          return VoxelShapes.b;
      }
 diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
-index 2e1eabba14a3757d03fd90741651001e78c6322f..d9ff52eda71fcdf88d4c9114450237bcba2ccb08 100644
+index 2e1eabba14a3757d03fd90741651001e78c6322f..45ded8cd3aee69083f6196765208d8c2430f0a02 100644
 --- a/src/main/java/net/minecraft/server/World.java
 +++ b/src/main/java/net/minecraft/server/World.java
 @@ -22,6 +22,7 @@ import org.bukkit.craftbukkit.SpigotTimings; // Spigot
@@ -4414,7 +4414,7 @@ index 2e1eabba14a3757d03fd90741651001e78c6322f..d9ff52eda71fcdf88d4c9114450237bc
          this.spigotConfig = new org.spigotmc.SpigotWorldConfig( worlddata.getName() ); // Spigot
          this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(worlddata.getName(), this.spigotConfig); // Paper
          this.generator = gen;
-+        dimensionmanager.world = (WorldServer) this; // Paper
++        if (dimensionmanager.world == null) dimensionmanager.world = (WorldServer) this; // Paper
          this.world = new CraftWorld((WorldServer) this, gen, env);
          this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
          this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
diff --git a/Spigot-Server-Patches/0384-Anti-Xray.patch b/Spigot-Server-Patches/0384-Anti-Xray.patch
index 8f9b4fffcc..459f84e4a9 100644
--- a/Spigot-Server-Patches/0384-Anti-Xray.patch
+++ b/Spigot-Server-Patches/0384-Anti-Xray.patch
@@ -1392,7 +1392,7 @@ index 01bf28dc34dd69dbcee5f470cc71ec2fbb2fcc12..caa18b046cd4231b1caa9c70e766ab60
      }
  
 diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
-index 74709dff3f87e929f1583be524d4e53ad3be6728..7faaef50a5430c8bdf85ca0e37a4ad24ad56b1ef 100644
+index 69db339c29c8f06026f05b0b5bb8019099af3fdf..4608d5f50d3c572f56bcc20dae2d537a07d05202 100644
 --- a/src/main/java/net/minecraft/server/World.java
 +++ b/src/main/java/net/minecraft/server/World.java
 @@ -2,6 +2,8 @@ package net.minecraft.server;
@@ -1418,7 +1418,7 @@ index 74709dff3f87e929f1583be524d4e53ad3be6728..7faaef50a5430c8bdf85ca0e37a4ad24
          this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(worlddata.getName(), this.spigotConfig); // Paper
 +        this.chunkPacketBlockController = this.paperConfig.antiXray ? new ChunkPacketBlockControllerAntiXray(this.paperConfig) : ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
          this.generator = gen;
-         dimensionmanager.world = (WorldServer) this; // Paper
+         if (dimensionmanager.world == null) dimensionmanager.world = (WorldServer) this; // Paper
          this.world = new CraftWorld((WorldServer) this, gen, env);
 @@ -343,6 +347,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
              // CraftBukkit end