aboutsummaryrefslogtreecommitdiffhomepage
path: root/CraftBukkit-Patches/0081-Replace-AutoSave-Mechanism.patch
blob: 581c91ec4e4983a8b4585756731203bafa57859d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
From f47619fa36a666e37d58e2178f1acb04550a4afd Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 12 Jan 2014 21:07:18 +1100
Subject: [PATCH] Replace AutoSave Mechanism

The problem here is that MinecraftServer.save(..), will attempt to sleep whilst all pending chunks are written to disk, however due to various and complicated bugs, it will wait for an incorrect amount of chunks, which may cause it to sleep for an overly long amount of time. Instead we will mimic the save-all command in its behaviour, which is both safe and performant.

diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index edd781e..622e522 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -583,7 +583,16 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
             SpigotTimings.worldSaveTimer.startTiming(); // Spigot
             this.methodProfiler.a("save");
             this.u.savePlayers();
-            this.saveChunks(true);
+            // Spigot Start
+            // We replace this with saving each individual world as this.saveChunks(...) is broken,
+            // and causes the main thread to sleep for random amounts of time depending on chunk activity
+            server.playerCommandState = true;
+            for (World world : worlds) {
+                world.getWorld().save();
+            }
+            server.playerCommandState = false;
+            // this.saveChunks(true);
+            // Spigot End
             this.methodProfiler.b();
             SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
         }
-- 
1.9.1