130 lines
6.6 KiB
Diff
130 lines
6.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Mon, 12 Jun 2023 14:09:36 -0500
|
|
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 d91ad3622592ece58877f975cdcbf984e61219d7..67a16d32e73099b5b6e1e406341fc6b982cceaa6 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;
|
|
@@ -308,6 +309,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// Paper start - lag compensation
|
|
public static final long SERVER_INIT = System.nanoTime();
|
|
// Paper end - lag compensation
|
|
+ public @Nullable DimensionDataStorage sharedDataStorage; // Slice
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
|
AtomicReference<S> atomicreference = new AtomicReference();
|
|
@@ -407,6 +409,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.paperConfigurations = services.paperConfigurations(); // Paper
|
|
}
|
|
|
|
+ // Slice start
|
|
+ public DimensionDataStorage getMapDataStorage() {
|
|
+ return sharedDataStorage != null ? sharedDataStorage : overworld().getDataStorage();
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
private void readScoreboard(DimensionDataStorage persistentStateManager) {
|
|
persistentStateManager.computeIfAbsent(this.getScoreboard().dataFactory(), "scoreboard");
|
|
}
|
|
@@ -873,6 +881,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;
|
|
}
|
|
@@ -1087,6 +1096,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.nextTickTime = Util.getMillis();
|
|
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
|
|
this.status = this.buildServerStatus();
|
|
@@ -1399,6 +1417,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 aad0d7662d530eaa9256de635401bbcde3263286..f676c0f91cb971317b5d8f3c183544f693475414 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -2102,14 +2102,14 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
@Override
|
|
public MapItemSavedData getMapData(String id) {
|
|
// Paper start - Call missing map initialize event & set id
|
|
- final DimensionDataStorage storage = this.getServer().overworld().getDataStorage();
|
|
+ final DimensionDataStorage storage = this.getServer().getMapDataStorage();
|
|
|
|
final net.minecraft.world.level.saveddata.SavedData existing = storage.cache.get(id);
|
|
if (existing == null && !storage.cache.containsKey(id)) {
|
|
final net.minecraft.world.level.saveddata.SavedData.Factory<MapItemSavedData> factory = MapItemSavedData.factory();
|
|
final MapItemSavedData map = storage.readSavedData(factory.deserializer(), factory.type(), id);
|
|
- storage.cache.put(id, map);
|
|
if (map != null) {
|
|
+ storage.cache.put(id, map);
|
|
map.id = id;
|
|
new MapInitializeEvent(map.mapView).callEvent();
|
|
return map;
|
|
@@ -2123,12 +2123,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.factory(), "idcounts")).getFreeAuxValueForMap();
|
|
+ // Slice start
|
|
+ DimensionDataStorage storage = this.getServer().getMapDataStorage();
|
|
+ MapIndex mapIndex = storage.get(MapIndex.factory(), "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
|