9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0154-PaperPR-Fix-unnecessary-map-data-saves.patch

46 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dqu1J <mcpeytwot5@gmail.com>
Date: Tue, 29 Apr 2025 01:35:45 -0400
Subject: [PATCH] PaperPR: Fix unnecessary map data saves
Original license: GPLv3
Original project: https://github.com/PaperMC/Paper
Paper pull request: https://github.com/PaperMC/Paper/pull/12296
Fixes Paper#12295
Currently, MapCanvas API unnecessarily causes map data file to save.
The API calls this.mapView.worldMap.setColorsDirty() to mark colors dirty for players, however this has the side-effect of saving the map .dat files as well:
```
public void setColorsDirty(int x, int z) {
this.setDirty(); // This saves the data file!
for (MapItemSavedData.HoldingPlayer holdingPlayer : this.carriedBy) {
holdingPlayer.markColorsDirty(x, z); // This is what the API wants to do!
}
}
```
This causes unnecessary lag during world saves, which scales with the amount of maps handled with API since last save. On servers that heavily rely on imageonmap-like plugins, it can cause lag spikes of dozens of seconds.
This PR changes this method to add a boolean argument to the method that determines whether the file is saved or not, which is used by the API. An overload is added for compatibility, and for vanilla.
diff --git a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
index 59829bb134555d96edcf4cbb844ccacb88c44961..76916ac06208348f718dffc9be232feb66b84d5c 100644
--- a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
+++ b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
@@ -456,7 +456,12 @@ public class MapItemSavedData extends SavedData {
}
public void setColorsDirty(int x, int z) {
- this.setDirty();
+ // Paper start - Fix unnecessary map data saves
+ this.setColorsDirty(x, z, true);
+ }
+ public void setColorsDirty(int x, int z, boolean markFileDirty) {
+ if (markFileDirty) this.setDirty();
+ // Paper end - Fix unnecessary map data saves
for (MapItemSavedData.HoldingPlayer holdingPlayer : this.carriedBy) {
holdingPlayer.markColorsDirty(x, z);