mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
124 lines
5.4 KiB
Diff
124 lines
5.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 8 May 2020 20:30:58 -0400
|
|
Subject: [PATCH] Fix CraftServer.unloadWorld Leak
|
|
|
|
The dimension manager was still registered which leaked the entire World
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DimensionManager.java b/src/main/java/net/minecraft/server/DimensionManager.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/DimensionManager.java
|
|
+++ b/src/main/java/net/minecraft/server/DimensionManager.java
|
|
@@ -0,0 +0,0 @@ public class DimensionManager implements MinecraftSerializable {
|
|
private final boolean hasSkyLight;
|
|
private final GenLayerZoomer genLayerZoomer;
|
|
|
|
+ // Paper start
|
|
+ public static void unregister(String s, DimensionManager dimensionmanager) {
|
|
+ if (dimensionmanager == OVERWORLD || dimensionmanager == NETHER || dimensionmanager == THE_END) { return; } // do not unregister the default worlds
|
|
+ MCUtil.MAIN_EXECUTOR.execute(() -> {
|
|
+ RegistryMaterials<DimensionManager> registry = (RegistryMaterials<DimensionManager>) IRegistry.DIMENSION_TYPE;
|
|
+ registry.deleteValue(new MinecraftKey(s), dimensionmanager);
|
|
+ });
|
|
+ }
|
|
+ // Paper end
|
|
public static DimensionManager register(String s, DimensionManager dimensionmanager) {
|
|
return (DimensionManager) IRegistry.a(IRegistry.DIMENSION_TYPE, dimensionmanager.id, s, dimensionmanager);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/RegistryID.java
|
|
+++ b/src/main/java/net/minecraft/server/RegistryID.java
|
|
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
|
|
public class RegistryID<K> implements Registry<K> {
|
|
|
|
private static final Object a = null;
|
|
- private K[] b;
|
|
+ private K[] b; // Paper - diff below
|
|
private int[] c;
|
|
- private K[] d;
|
|
+ private K[] d; // Paper - diff below
|
|
private int e;
|
|
private int f;
|
|
private java.util.BitSet usedIds; // Paper
|
|
+ // Paper start
|
|
+ public void removeValue(K value) {
|
|
+ removeValue(value, this.b);
|
|
+ removeValue(value, this.d);
|
|
+ rehash(this.b.length);
|
|
+ }
|
|
+ public void removeValue(K value, K[] arr) {
|
|
+ for (int i = 0; i < arr.length; i++) {
|
|
+ K k = arr[i];
|
|
+ if (k == value) {
|
|
+ arr[i] = null;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
|
|
public RegistryID(int i) {
|
|
i = (int) ((float) i / 0.8F);
|
|
@@ -0,0 +0,0 @@ public class RegistryID<K> implements Registry<K> {
|
|
return this.e;
|
|
}
|
|
|
|
+ private void rehash(int i) { d(i); } // Paper - OBFHELPER
|
|
private void d(int i) {
|
|
K[] ak = this.b;
|
|
int[] aint = this.c;
|
|
diff --git a/src/main/java/net/minecraft/server/RegistryMaterials.java b/src/main/java/net/minecraft/server/RegistryMaterials.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/RegistryMaterials.java
|
|
+++ b/src/main/java/net/minecraft/server/RegistryMaterials.java
|
|
@@ -0,0 +0,0 @@ public class RegistryMaterials<T> extends IRegistryWritable<T> {
|
|
private int V;
|
|
|
|
public RegistryMaterials() {}
|
|
+ public T deleteValue(MinecraftKey minecraftkey, T value) {
|
|
+ this.b.removeValue(value); // Diff 1
|
|
+ this.d = null; // Diff 2
|
|
+ return this.c.remove(minecraftkey); // Diff 3
|
|
+ }
|
|
|
|
@Override
|
|
public <V extends T> V a(int i, MinecraftKey minecraftkey, V v0) {
|
|
- this.b.a(v0, i);
|
|
+ this.b.a(v0, i); // Paper - diff above 1
|
|
Validate.notNull(minecraftkey);
|
|
Validate.notNull(v0);
|
|
- this.d = null;
|
|
+ this.d = null; // Diff 2
|
|
if (this.c.containsKey(minecraftkey)) {
|
|
RegistryMaterials.LOGGER.debug("Adding duplicate key '{}' to registry", minecraftkey);
|
|
}
|
|
|
|
- this.c.put(minecraftkey, v0);
|
|
+ this.c.put(minecraftkey, v0); // Paper - diff3
|
|
if (this.V <= i) {
|
|
this.V = i + 1;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -0,0 +0,0 @@ import net.minecraft.server.EntityPlayer;
|
|
import net.minecraft.server.EnumDifficulty;
|
|
import net.minecraft.server.EnumGamemode;
|
|
import net.minecraft.server.IRecipe;
|
|
+import net.minecraft.server.IRegistry;
|
|
import net.minecraft.server.Item;
|
|
import net.minecraft.server.ItemWorldMap;
|
|
import net.minecraft.server.Items;
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
}
|
|
|
|
worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH));
|
|
- console.worldServer.remove(handle.getWorldProvider().getDimensionManager());
|
|
+ // Paper start
|
|
+ DimensionManager dimensionManager = handle.getWorldProvider().getDimensionManager();
|
|
+ DimensionManager.unregister(world.getName().toLowerCase(java.util.Locale.ENGLISH), dimensionManager);
|
|
+ console.worldServer.remove(dimensionManager);
|
|
+ // Paper end
|
|
return true;
|
|
}
|
|
|