PaperMC/Spigot-Server-Patches/0310-Provide-option-to-use-a-versioned-world-folder-for-t.patch

229 lines
11 KiB
Diff
Raw Normal View History

From d9812faa701cf379d733e98cf420a0603cdebfc7 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 29 Jul 2018 15:48:50 -0400
Subject: [PATCH] Provide option to use a versioned world folder for testing
This should not ever be used in production!!
This setting is intended for testing so you can try out converting your world
without actually modifying the world files.
This will add some additional overhead to your world, but you're
just testing anyways so that's not a big deal :)
Will store in a folder named after the current version.
PlayerData and Data folders are copied on server start, so there
may be some delay there, but region files are only copied on demand.
This is highly experiemental so backup your world before relying on this to not modify it
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 48b0a742a..f0b87972d 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Pattern;
import com.google.common.collect.Lists;
@@ -308,4 +309,27 @@ public class PaperConfig {
Bukkit.getLogger().log(Level.INFO, "Using Aikar's Alternative Luck Formula to apply Luck attribute to all loot pool calculations. See https://luckformula.emc.gs");
}
}
+
+ public static boolean useVersionedWorld = false;
+ private static void useVersionedWorld() {
+ useVersionedWorld = getBoolean("settings.use-versioned-world", false);
+ if (useVersionedWorld) {
+ Logger logger = Bukkit.getLogger();
+ String ver = MinecraftServer.getServer().getVersion();
+ logger.log(Level.INFO, "******************************************************");
+ logger.log(Level.INFO, "*** Using a versioned world folder. Your world will be saved");
+ logger.log(Level.INFO, "*** to into the " + ver + " folder, but copied from your current world.");
+ logger.log(Level.INFO, "*** ");
+ logger.log(Level.INFO, "*** This setting should not be used in your real world!!!");
+ logger.log(Level.INFO, "*** If you want to retain the new world, you need to move ");
+ logger.log(Level.INFO, "*** the folders out of the " + ver + " folder and overwrite existing");
+ logger.log(Level.INFO, "*** ");
+ logger.log(Level.INFO, "*** Deleting the " + ver + " folder will cause it to recreate again");
+ logger.log(Level.INFO, "*** from your unversioned world files.");
+ logger.log(Level.INFO, "*** ");
+ logger.log(Level.INFO, "*** You should backup your original world files incase something goes");
+ logger.log(Level.INFO, "*** wrong with this system! This is not a backup system.");
+ logger.log(Level.INFO, "******************************************************");
+ }
+ }
}
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index 485bce987..60143ff63 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -58,8 +58,55 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
// private boolean f; // CraftBukkit
public final LongSet blacklist = new LongOpenHashSet();
private static final double SAVE_QUEUE_TARGET_SIZE = 625; // Spigot
+ // Paper start - support saving to an alternate directory
+ private final File templateWorld;
+ private final File actualWorld;
+ private final boolean useAltWorld;
+
+ private void copyIfNeeded(int x, int z) {
+ if (!useAltWorld) {
+ return;
+ }
+ synchronized (RegionFileCache.class) {
+ if (RegionFileCache.hasRegionFile(this.actualWorld, x, z)) {
+ return;
+ }
+ File actual = RegionFileCache.getRegionFileName(this.actualWorld, x, z);
+ File template = RegionFileCache.getRegionFileName(this.templateWorld, x, z);
+ if (!actual.exists() && template.exists()) {
+ try {
+ //a.info("Copying" + template + " to " + actual);
+ java.nio.file.Files.copy(template.toPath(), actual.toPath(), java.nio.file.StandardCopyOption.COPY_ATTRIBUTES);
+ } catch (IOException e1) {
+ LogManager.getLogger().error("Error copying " + template + " to " + actual, e1);
+ MinecraftServer.getServer().safeShutdown();
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(e1);
+ }
+ }
+ }
+ }
+ // Paper end
public ChunkRegionLoader(File file, DataFixer datafixer) {
+ // Paper start
+ this.actualWorld = file;
+ if (com.destroystokyo.paper.PaperConfig.useVersionedWorld) {
+ this.useAltWorld = true;
+ String name = file.getName();
+ File container = file.getParentFile().getParentFile();
+ if (name.equals("DIM-1") || name.equals("DIM1")) {
+ container = container.getParentFile();
+ }
+ this.templateWorld = new File(container, name);
+ File region = new File(file, "region");
+ if (!region.exists()) {
+ region.mkdirs();
+ }
+ } else {
+ this.useAltWorld = false;
+ this.templateWorld = file;
+ }
+ // Paper end
this.c = file;
this.d = datafixer;
}
@@ -97,7 +144,13 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
}
public boolean chunkExists(int x, int z) {
- return RegionFileCache.chunkExists(this.c, x, z);
+ // Paper start
+ if (this.saveMap.containsKey(ChunkCoordIntPair.asLong(x, z))) {
+ return true;
+ }
+ copyIfNeeded(x, z);
+ return RegionFileCache.chunkExists(this.actualWorld, x, z);
+ // Paper end
}
@Nullable
@@ -107,6 +160,8 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
return null;
}
// CraftBukkit end
+ copyIfNeeded(i, j); // Paper
+
NBTTagCompound nbttagcompound = SupplierUtils.getIfExists(this.saveMap.get(ChunkCoordIntPair.asLong(i, j))); // Spigot // Paper
if (nbttagcompound != null) {
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
index d07222239..8c8b7cbab 100644
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -76,6 +76,13 @@ public class RegionFileCache {
itr.remove();
}
}
+ public static synchronized File getRegionFileName(File file, int i, int j) {
+ File file1 = new File(file, "region");
+ return new File(file1, "r." + (i >> 5) + "." + (j >> 5) + ".mca");
+ }
+ public static synchronized boolean hasRegionFile(File file, int i, int j) {
+ return RegionFileCache.cache.containsKey(getRegionFileName(file, i, j));
+ }
// Paper End
public static synchronized void a() {
diff --git a/src/main/java/net/minecraft/server/WorldNBTStorage.java b/src/main/java/net/minecraft/server/WorldNBTStorage.java
index 577ba1b5f..9be0e994e 100644
--- a/src/main/java/net/minecraft/server/WorldNBTStorage.java
+++ b/src/main/java/net/minecraft/server/WorldNBTStorage.java
@@ -32,6 +32,58 @@ public class WorldNBTStorage implements IDataManager, IPlayerFileData {
public WorldNBTStorage(File file, String s, @Nullable MinecraftServer minecraftserver, DataFixer datafixer) {
this.a = datafixer;
+ // Paper start
+ if (com.destroystokyo.paper.PaperConfig.useVersionedWorld) {
+ File origBaseDir = new File(file, s);
+ final String currentVersion = MinecraftServer.getServer().getVersion();
+ file = new File(file, currentVersion);
+ File baseDir = new File(file, s);
+
+ if (!baseDir.exists() && origBaseDir.exists() && !baseDir.mkdirs()) {
+ LogManager.getLogger().error("Could not create world directory for " + file);
+ System.exit(1);
+ }
+
+ try {
+ boolean printedHeader = false;
+ String[] dirs = {"advancements", "data", "datapacks", "playerdata", "stats"};
+ for (String dir : dirs) {
+ File origPlayerData = new File(origBaseDir, dir);
+ File targetPlayerData = new File(baseDir, dir);
+ if (origPlayerData.exists() && !targetPlayerData.exists()) {
+ if (!printedHeader) {
+ LogManager.getLogger().info("**** VERSIONED WORLD - Copying files");
+ printedHeader = true;
+ }
+ LogManager.getLogger().info("- Copying: " + dir);
+ org.apache.commons.io.FileUtils.copyDirectory(origPlayerData, targetPlayerData);
+ }
+ }
+
+ String[] files = {"level.dat", "level.dat_old", "session.lock", "uid.dat"};
+ for (String fileName : files) {
+ File origPlayerData = new File(origBaseDir, fileName);
+ File targetPlayerData = new File(baseDir, fileName);
+ if (origPlayerData.exists() && !targetPlayerData.exists()) {
+ if (!printedHeader) {
+ LogManager.getLogger().info("- Copying files");
+ printedHeader = true;
+ }
+ LogManager.getLogger().info("- Copying: " + fileName);
+ org.apache.commons.io.FileUtils.copyFile(origPlayerData, targetPlayerData);
+
+ }
+ }
+ if (printedHeader) {
+ LogManager.getLogger().info("**** VERSIONED WORLD - Copying DONE");
+ }
+ } catch (IOException e) {
+ LogManager.getLogger().error("Error copying versioned world data for " + origBaseDir + " to " + baseDir, e);
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(e);
+ }
+
+ }
+ // Paper end
this.baseDir = new File(file, s);
this.baseDir.mkdirs();
this.playerDir = new File(this.baseDir, "playerdata");
--
Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Warning: this commit contains more mapping changes from upstream, As always, ensure that you have working backups and test this build before deployment; Developers working on paper will, yet again, need to delete their work/Minecraft/1.13.2 folder Bukkit Changes: 7fca5fd4 SPIGOT-4558: Preserve user order in the face of copied defaults in configurations 15c9b1eb Ignore spurious slot IDs sent by client, e.g. in enchanting tables 5d2a10c5 SPIGOT-3747: Add API for force loaded chunks d6dd2bb3 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent 771db4aa SPIGOT-794: Call EntityPlaceEvent for Minecart placement 55462509 Add InventoryView#getSlotType 2f3ce5b6 Remove EntityTransformEvent and CustomItemTagContainer from draft API f04ad7b6 Make ProjectileLaunchEvent extend EntitySpawnEvent ccb85808 Define EntitySpawnEvent b8cc3ebe Add PlayerItemDamageEvent 184a495d Ease ClassLoader Deadlocks Where Possible 11ac4728 Expand Boolean Prompt Values in Conversation API aae62d51 Added getAllSessionData() to the Conversation API. 9290ff91 Add InventoryView#getInventory API 995e530f Add API to get / set base arrow damage CraftBukkit Changes: c4a67eed SPIGOT-4556: Fix plugins closing inventory during drop events 5be2ddcb Replace version constants with methods to prevent compiler inlining a5b9c7b3 Use API method to create offset command completions 2bc7d1df SPIGOT-3747: Add API for force loaded chunks a408f375 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent b54b9409 SPIGOT-2864: Make Arrow / Item setTicksLived behave like FallingBlock 79ded7a8 SPIGOT-1811: Death message not shown on respawn screen b4a4f15d SPIGOT-943: InventoryCloseEvent called on death regardless of open inventory 0afed592 SPIGOT-794: Call EntityPlaceEvent for Minecart placement 2b2d084a Add InventoryView#getSlotType 01a9959a Do not use deprecated ItemSpawnEvent constructor 9642498d SPIGOT-4547: Call EntitySpawnEvent as general spawn fallback event 963f4a5f Add PlayerItemDamageEvent 63db0445 Add API to get / set base arrow damage 531c25d7 Add CraftMagicNumbers.MAPPINGS_VERSION for use by NMS plugins d05c8b14 Mappings Update bd36e200 SPIGOT-4551: Ignore invalid attribute modifier slots Spigot Changes: 518206a1 Remove redundant trove depend 1959ad21 MC-11211,SPIGOT-4552: Fix placing double slabs at y = 255 29ab5e43 SPIGOT-3661: Allow arguments in restart-script 7cc46316 SPIGOT-852: Growth modifiers for beetroots, potatoes, carrots 82e117e1 Squelch "fatal: Resolve operation not in progress" message 0a1a68e7 Mappings Update & Patch Rebuild
2019-01-01 04:15:55 +01:00
2.20.1