2022-03-06 01:29:47 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
|
|
Date: Sat, 5 Mar 2022 17:12:52 -0800
|
|
|
|
Subject: [PATCH] Fix save problems on shutdown
|
|
|
|
|
|
|
|
- Save level.dat first, in case the shutdown is killed later
|
|
|
|
- Force run minecraftserver tasks and the chunk source tasks
|
|
|
|
while waiting for the chunk system to empty, as there's simply
|
|
|
|
too much trash that could prevent them from executing during
|
|
|
|
the chunk source tick (i.e "time left in tick" logic).
|
2022-03-06 01:36:57 +00:00
|
|
|
- Set forceTicks to true, so that player packets are always
|
|
|
|
processed so that the main process queue can be drained
|
2022-03-06 01:29:47 +00:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-06-09 23:01:48 +00:00
|
|
|
index 1bc400cf245ba3110e8874a4f2837a91d0f70916..60de49a9888b6dfe17dcb0d9dd0dd3d2e7d829aa 100644
|
2022-03-06 01:29:47 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-06-08 13:36:56 +00:00
|
|
|
@@ -953,6 +953,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-03-06 01:29:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - let's be a little more intelligent around crashes
|
|
|
|
+ // make sure level.dat saves
|
|
|
|
+ for (ServerLevel level : this.getAllLevels()) {
|
|
|
|
+ level.saveLevelDat();
|
|
|
|
+ }
|
|
|
|
+ // Paper end - let's be a little more intelligent around crashes
|
|
|
|
+
|
|
|
|
while (this.levels.values().stream().anyMatch((worldserver1) -> {
|
|
|
|
return worldserver1.getChunkSource().chunkMap.hasWork();
|
|
|
|
})) {
|
2022-06-08 13:36:56 +00:00
|
|
|
@@ -965,9 +972,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-03-06 01:29:47 +00:00
|
|
|
worldserver.getChunkSource().tick(() -> {
|
|
|
|
return true;
|
|
|
|
}, false);
|
|
|
|
+ while (worldserver.getChunkSource().pollTask()); // Paper - drain tasks
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.waitUntilNextTick();
|
2022-03-06 01:36:57 +00:00
|
|
|
+ this.forceTicks = true; // Paper
|
2022-03-06 01:29:47 +00:00
|
|
|
+ while (this.pollTask()); // Paper - drain tasks
|
|
|
|
}
|
|
|
|
|
|
|
|
this.saveAllChunks(false, true, false);
|
2022-06-08 13:36:56 +00:00
|
|
|
@@ -1264,6 +1273,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-03-06 01:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean haveTime() {
|
|
|
|
+ // Paper start
|
|
|
|
+ if (this.forceTicks) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit start
|
|
|
|
if (isOversleep) return canOversleep();// Paper - because of our changes, this logic is broken
|
|
|
|
return this.forceTicks || this.runningTask() || Util.getMillis() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTime : this.nextTickTime);
|
2022-03-06 01:29:47 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-06-10 01:20:47 +00:00
|
|
|
index cf3622930aab7ff62e293622ab1cd5ff97ee68f5..de0fe1743dbddc6ff548dc4c658955266600180f 100644
|
2022-03-06 01:29:47 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-06-10 01:20:47 +00:00
|
|
|
@@ -1278,7 +1278,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2022-03-06 01:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ this.saveLevelDat();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public void saveLevelDat() {
|
|
|
|
+ this.saveLevelData();
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit start - moved from MinecraftServer.saveChunks
|
|
|
|
ServerLevel worldserver1 = this;
|
|
|
|
|