Files
OldSliceMC/patches/server/0028-Shared-Data-Folder-for-maps.patch
2022-11-16 09:50:52 -06:00

131 lines
6.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Mon, 14 Nov 2022 07:37:41 -0600
Subject: [PATCH] Shared Data Folder for maps
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index fafbebbb5e8c1a381b673f97f1fa210687b52823..8c846971b56930ff10740986d71ad47afc2b79d1 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -693,4 +693,11 @@ public class PaperConfig {
private static void useProxyProtocol() {
useProxyProtocol = getBoolean("settings.proxy-protocol", false);
}
+
+ // Slice start
+ public static String sharedDataFolder;
+ private static void sharedDataFolder() {
+ sharedDataFolder = getString("settings.shared-data-folder", null);
+ }
+ // Slice end
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index ce51ebeb5df07abc4a8bb31bc737ab3e4214ce83..8129c62692b9d1c4be85387dc52096b94956920e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -308,6 +308,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public volatile Thread shutdownThread; // Paper
public volatile boolean abnormalExit = false; // Paper
+ public @Nullable DimensionDataStorage sharedDataStorage; // Slice
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
@@ -407,6 +408,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit end
+ // Slice start
+ public DimensionDataStorage getMapDataStorage() {
+ return sharedDataStorage != null ? sharedDataStorage : overworld().getDataStorage();
+ }
+ // Slice end
+
private void readScoreboard(DimensionDataStorage persistentStateManager) {
ServerScoreboard scoreboardserver = this.getScoreboard();
@@ -919,6 +926,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.isSaving = true;
this.getPlayerList().saveAll(); // Diff on change
flag3 = this.saveAllChunks(suppressLogs, flush, force);
+ if (sharedDataStorage != null) sharedDataStorage.save(); // Slice
} finally {
this.isSaving = false;
}
@@ -1161,6 +1169,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
try {
long serverStartTime = Util.getNanos(); // Paper
if (this.initServer()) {
+ // Slice start
+ String sharedDataFolder = com.destroystokyo.paper.PaperConfig.sharedDataFolder;
+ if (sharedDataFolder != null) {
+ File sharedDir = new File(sharedDataFolder);
+ sharedDir.mkdirs();
+ this.sharedDataStorage = new DimensionDataStorage(sharedDir, fixerUpper);
+ }
+ // Slice end
+
this.nextTickTime = Util.getMillis();
this.status.setDescription(new TextComponent(this.motd));
this.status.setVersion(new ServerStatus.Version(SharedConstants.getCurrentVersion().getName(), SharedConstants.getCurrentVersion().getProtocolVersion()));
@@ -1492,6 +1509,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
level.saveIncrementally(fullSave);
}
}
+ if (sharedDataStorage != null) sharedDataStorage.save(); // Slice
} finally {
this.isSaving = false;
}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 9b3af8f2a433368d722cd442c07b2a2cfb16dc54..f460d21bcc7ba36763410851cf92a7053d85fc96 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1845,7 +1845,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@Override
public MapItemSavedData getMapData(String id) {
// CraftBukkit start
- return (MapItemSavedData) this.getServer().overworld().getDataStorage().get((nbttagcompound) -> {
+ return (MapItemSavedData) this.getServer().getMapDataStorage().get((nbttagcompound) -> { // Slice
// We only get here when the data file exists, but is not a valid map
MapItemSavedData newMap = MapItemSavedData.load(nbttagcompound);
newMap.id = id;
@@ -1859,12 +1859,22 @@ public class ServerLevel extends Level implements WorldGenLevel {
@Override
public void setMapData(String id, MapItemSavedData state) {
state.id = id; // CraftBukkit
- this.getServer().overworld().getDataStorage().set(id, state);
+ this.getServer().getMapDataStorage().set(id, state); // Slice
}
@Override
public int getFreeMapId() {
- return ((MapIndex) this.getServer().overworld().getDataStorage().computeIfAbsent(MapIndex::load, MapIndex::new, "idcounts")).getFreeAuxValueForMap();
+ // Slice start
+ DimensionDataStorage storage = this.getServer().getMapDataStorage();
+ MapIndex mapIndex = storage.readSavedData(MapIndex::load, "idcounts");
+ if (mapIndex == null) {
+ mapIndex = new MapIndex();
+ }
+ int newId = mapIndex.getFreeAuxValueForMap();
+ storage.set("idcounts", mapIndex);
+ storage.save();
+ return newId;
+ // Slice end
}
// Paper start - helper function for configurable spawn radius
diff --git a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
index 0465b397b628b11a6fc52e3375945c94d68cfdd5..14296686772b74a45543227dc1e74a9c71c58cef 100644
--- a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
+++ b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
@@ -58,7 +58,7 @@ public class DimensionDataStorage {
}
@Nullable
- private <T extends SavedData> T readSavedData(Function<CompoundTag, T> readFunction, String id) {
+ public <T extends SavedData> T readSavedData(Function<CompoundTag, T> readFunction, String id) { // Slice private -> public
try {
File file = this.getDataFile(id);
if (file.exists()) {