From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cryptite 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 S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); @@ -407,6 +408,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { + 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 readSavedData(Function readFunction, String id) { + public T readSavedData(Function readFunction, String id) { // Slice private -> public try { File file = this.getDataFile(id); if (file.exists()) {