123 lines
6.5 KiB
Diff
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 b53b6cc4463675096b061b3b65f14a4695c742e2..6100d75e5d9184fd4ec79ffbd00cea0d637e5073 100644
|
|
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
@@ -333,6 +333,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 268bebac970646a9d697ec31ea5c89b9f583618f..59db2872229b4229f959bf227d1a2cf54c208ce8 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();
|
|
@@ -1536,6 +1555,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 21f54a4a3de169ede1687324009aea3f9d986db4..4e5bdf47beab8477fd5278fc4c9ff162ad835d12 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -2116,7 +2116,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)) {
|
|
@@ -2143,12 +2143,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
|