aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMrIvanPlays <[email protected]>2020-08-09 09:04:18 +0300
committerDaniel Ennis <[email protected]>2020-08-11 09:55:10 -0400
commit2b4ce0b370f2697616c4c73dbb42cd3d749b73c9 (patch)
tree2ccc884fde59fb65b132dcef1d835c9c9546e300
parentede98b68207868ada5ec7ef08fbdb8ef25b9981a (diff)
downloadPaper-2b4ce0b370f2697616c4c73dbb42cd3d749b73c9.tar.gz
Paper-2b4ce0b370f2697616c4c73dbb42cd3d749b73c9.zip
Restore incremental player saving
This patch was dropped in 1.14 . I couldn't find it in removed so I got it from 1.13 Tested with 30-40 players and works fine with default settings. Closes https://github.com/PaperMC/Paper/issues/4070
-rw-r--r--Spigot-Server-Patches/0551-Incremental-player-saving.patch95
1 files changed, 95 insertions, 0 deletions
diff --git a/Spigot-Server-Patches/0551-Incremental-player-saving.patch b/Spigot-Server-Patches/0551-Incremental-player-saving.patch
new file mode 100644
index 0000000000..ce7a11b17b
--- /dev/null
+++ b/Spigot-Server-Patches/0551-Incremental-player-saving.patch
@@ -0,0 +1,95 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Sun, 9 Aug 2020 08:59:25 +0300
+Subject: [PATCH] Incremental player saving
+
+
+diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
+index 56e4359ba32339e1bef58061585ff3e12e4215f3..60f03502a7fd622d2de3b2da9fe8014b289f3d31 100644
+--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
+@@ -435,4 +435,15 @@ public class PaperConfig {
+ allowPistonDuplication = getBoolean("settings.unsupported-settings.allow-piston-duplication", config.getBoolean("settings.unsupported-settings.allow-tnt-duplication", false));
+ set("settings.unsupported-settings.allow-tnt-duplication", null);
+ }
++
++ public static int playerAutoSaveRate = -1;
++ public static int maxPlayerAutoSavePerTick = 10;
++ private static void playerAutoSaveRate() {
++ playerAutoSaveRate = getInt("settings.player-auto-save-rate", -1);
++ maxPlayerAutoSavePerTick = getInt("settings.max-player-auto-save-per-tick", -1);
++ if (maxPlayerAutoSavePerTick == -1) { // -1 Automatic / "Recommended"
++ // 10 should be safe for everyone unless you mass spamming player auto save
++ maxPlayerAutoSavePerTick = (playerAutoSaveRate == -1 || playerAutoSaveRate > 100) ? 10 : 20;
++ }
++ }
+ }
+diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
+index e5a81f831813209d224ffedbc03f6d8243721a25..c72cfd2bdfbe4536f6799fc4dff195c1f66d4c94 100644
+--- a/src/main/java/net/minecraft/server/EntityPlayer.java
++++ b/src/main/java/net/minecraft/server/EntityPlayer.java
+@@ -42,6 +42,7 @@ import org.bukkit.inventory.MainHand;
+ public class EntityPlayer extends EntityHuman implements ICrafting {
+
+ private static final Logger LOGGER = LogManager.getLogger();
++ public long lastSave = MinecraftServer.currentTick; // Paper
+ public PlayerConnection playerConnection;
+ public NetworkManager networkManager; // Paper
+ public final MinecraftServer server;
+diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
+index 3130c68e7318a41e763575b245ee1b5298c92a16..0defaec8a8a25b1a0172f211d599d07264977cfa 100644
+--- a/src/main/java/net/minecraft/server/MinecraftServer.java
++++ b/src/main/java/net/minecraft/server/MinecraftServer.java
+@@ -1228,9 +1228,15 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
+ //if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit // Paper - move down
+ //MinecraftServer.LOGGER.debug("Autosave started"); // Paper
+ serverAutoSave = (autosavePeriod > 0 && this.ticks % autosavePeriod == 0); // Paper
++ // Paper start
++ int playerSaveInterval = com.destroystokyo.paper.PaperConfig.playerAutoSaveRate;
++ if (playerSaveInterval < 0) {
++ playerSaveInterval = autosavePeriod;
++ }
++ // Paper end
+ this.methodProfiler.enter("save");
+- if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // Paper
+- this.playerList.savePlayers();
++ if (playerSaveInterval > 0) { // Paper
++ this.playerList.savePlayers(playerSaveInterval); // Paper
+ }// Paper
+ // Paper start
+ for (WorldServer world : getWorlds()) {
+diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
+index 9382e8f79e8edec8885c629a36e230fbec50e1fb..38d83bb3183c6b8d7708e27b7427a757e3d26b0f 100644
+--- a/src/main/java/net/minecraft/server/PlayerList.java
++++ b/src/main/java/net/minecraft/server/PlayerList.java
+@@ -482,6 +482,7 @@ public abstract class PlayerList {
+ protected void savePlayerFile(EntityPlayer entityplayer) {
+ if (!entityplayer.getBukkitEntity().isPersistent()) return; // CraftBukkit
+ if (!entityplayer.didPlayerJoinEvent) return; // Paper - If we never fired PJE, we disconnected during login. Data has not changed, and additionally, our saved vehicle is not loaded! If we save now, we will lose our vehicle (CraftBukkit bug)
++ entityplayer.lastSave = MinecraftServer.currentTick; // Paper
+ this.playerFileData.save(entityplayer);
+ ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
+
+@@ -1127,10 +1128,21 @@ public abstract class PlayerList {
+ }
+
+ public void savePlayers() {
++ // Paper start - incremental player saving
++ savePlayers(null);
++ }
++ public void savePlayers(Integer interval) {
+ MCUtil.ensureMain("Save Players" , () -> { // Paper - Ensure main
+ MinecraftTimings.savePlayers.startTiming(); // Paper
++ int numSaved = 0;
++ long now = MinecraftServer.currentTick;
+ for (int i = 0; i < this.players.size(); ++i) {
+- this.savePlayerFile((EntityPlayer) this.players.get(i));
++ EntityPlayer entityplayer = this.players.get(i);
++ if (interval == null || now - entityplayer.lastSave >= interval) {
++ this.savePlayerFile(entityplayer);
++ if (interval != null && ++numSaved <= com.destroystokyo.paper.PaperConfig.maxPlayerAutoSavePerTick) { break; }
++ }
++ // Paper end
+ }
+ MinecraftTimings.savePlayers.stopTiming(); // Paper
+ return null; }); // Paper - ensure main