mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 19:22:50 +01:00
74 lines
3.3 KiB
Diff
74 lines
3.3 KiB
Diff
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).
|
|
- Set forceTicks to true, so that player packets are always
|
|
processed so that the main process queue can be drained
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 1edf1d97c2d0a145d3baac9140765a9c2bb2a7a6..ad9609ccb33bbe9bdda94a50900258ad3e0339f0 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -956,6 +956,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
}
|
|
|
|
+ // 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();
|
|
})) {
|
|
@@ -968,9 +975,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
worldserver.getChunkSource().tick(() -> {
|
|
return true;
|
|
}, false);
|
|
+ while (worldserver.getChunkSource().pollTask()); // Paper - drain tasks
|
|
}
|
|
|
|
- this.waitUntilNextTick();
|
|
+ this.forceTicks = true; // Paper
|
|
+ while (this.pollTask()); // Paper - drain tasks
|
|
}
|
|
|
|
this.saveAllChunks(false, true, false);
|
|
@@ -1265,6 +1274,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
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);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 836841987ff5dd4901f75f47028a60d8d1b6e04a..802b929a16b6a8aeee608caeb524e268f8df53bd 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1279,7 +1279,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
}
|
|
|
|
}
|
|
+ // Paper start
|
|
+ this.saveLevelDat();
|
|
+ }
|
|
|
|
+ public void saveLevelDat() {
|
|
+ this.saveLevelData();
|
|
+ // Paper end
|
|
// CraftBukkit start - moved from MinecraftServer.saveChunks
|
|
ServerLevel worldserver1 = this;
|
|
|