Files
OldSliceMC/patches/server/0039-Shared-Data-Storage.patch
2024-04-08 08:34:56 -05:00

123 lines
6.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com>
Date: Wed, 3 Jan 2024 11:03:33 -0600
Subject: [PATCH] Shared Data Storage
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
index 0cc2307636279915c1f8529e62174cc696e185ee..220e5ede5752a4b9ab7e35c3ee4f0b4a26b2986c 100644
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
@@ -336,6 +336,7 @@ public class GlobalConfiguration extends ConfigurationPart {
public boolean useDimensionTypeForCustomSpawners = false;
public boolean strictAdvancementDimensionCheck = false;
public IntOr.Default compressionLevel = IntOr.Default.USE_DEFAULT;
+ public String sharedDataFolder = ""; // Slice
}
public BlockUpdates blockUpdates;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9ce9af857a5f2414658027ff5bb765cc4233899b..b8a43a2833b9f014067681277edad3b96a6d63cd 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2,6 +2,7 @@ package net.minecraft.server;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import co.aikar.timings.Timings;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
@@ -313,6 +314,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public volatile boolean abnormalExit = false; // Paper
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
+ @Nullable DimensionDataStorage sharedDataStorage; // Slice
+
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new io.papermc.paper.util.TickThread(() -> { // Paper - rewrite chunk system
@@ -414,6 +417,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.paperConfigurations = services.paperConfigurations(); // Paper - add paper configuration files
}
+ // Slice start
+ public DimensionDataStorage getMapDataStorage() {
+ return sharedDataStorage != null ? sharedDataStorage : overworld().getDataStorage();
+ }
+ // Slice end
+
private void readScoreboard(DimensionDataStorage persistentStateManager) {
persistentStateManager.computeIfAbsent(this.getScoreboard().dataFactory(), "scoreboard");
}
@@ -917,6 +926,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.isSaving = true;
this.getPlayerList().saveAll(); // Paper - Incremental chunk and player saving; diff on change
flag3 = this.saveAllChunks(suppressLogs, flush, force);
+ if (sharedDataStorage != null) sharedDataStorage.save(true); // Slice
} finally {
this.isSaving = false;
}
@@ -1132,6 +1142,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
throw new IllegalStateException("Failed to initialize server");
}
+ // Slice start
+ String sharedDataFolder = io.papermc.paper.configuration.GlobalConfiguration.get().misc.sharedDataFolder;
+ if (!Strings.isNullOrEmpty(sharedDataFolder)) {
+ File sharedDir = new File(sharedDataFolder);
+ sharedDir.mkdirs();
+ this.sharedDataStorage = new DimensionDataStorage(sharedDir, fixerUpper);
+ }
+ // Slice end
+
this.nextTickTimeNanos = Util.getNanos();
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();
@@ -1546,6 +1565,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
level.saveIncrementally(fullSave);
}
}
+ if (sharedDataStorage != null) sharedDataStorage.save(true); // 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 4653878c059a15491eb54d7211311db7e2fe570a..d60d1fe0261c79d77df982b76bfe96b91f6970de 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2127,7 +2127,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@Override
public MapItemSavedData getMapData(String id) {
// Paper start - Call missing map initialize event and set id
- final DimensionDataStorage storage = this.getServer().overworld().getDataStorage();
+ final DimensionDataStorage storage = this.getServer().getMapDataStorage(); // Slice
final net.minecraft.world.level.saveddata.SavedData existing = storage.cache.get(id);
if (existing == null && !storage.cache.containsKey(id)) {
@@ -2154,12 +2154,22 @@ public class ServerLevel extends Level implements WorldGenLevel {
MapInitializeEvent event = new MapInitializeEvent(state.mapView);
Bukkit.getServer().getPluginManager().callEvent(event);
// CraftBukkit end
- 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.factory(), "idcounts")).getFreeAuxValueForMap();
+ // Slice start
+ DimensionDataStorage storage = this.getServer().getMapDataStorage();
+ MapIndex mapIndex = storage.readSavedData(MapIndex::load, MapItemSavedData.factory().type(), "idcounts");
+ if (mapIndex == null) {
+ mapIndex = new MapIndex();
+ }
+ int newId = mapIndex.getFreeAuxValueForMap();
+ storage.set("idcounts", mapIndex);
+ storage.save(true);
+ return newId;
+ // Slice end
}
// Paper start - Configurable Keep Spawn Loaded range per world