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 a6f58b3457b7477015c5c6d969e7d83017dd3fa1..7f2070bd2d7eb7f0256a96df00103d20c45e65a0 100644
|
|
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
@@ -331,6 +331,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 c95c9792cf150b91d72710342859c9e9487bc8b4..bbe3af37c559e64e7660a909b08c89d6c96e2458 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;
|
|
}
|
|
@@ -1131,6 +1141,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();
|
|
@@ -1535,6 +1554,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 f033f530eef10177c349f2673bb3ee8ebdb1d30b..ebd5fe9f64672b01e3981c19aa9464e8f20dbc03 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
|