From 4c56d6dff2a15f60c9d289a84498d1003708dfbb Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Wed, 13 Dec 2023 03:05:11 -0600 Subject: [PATCH] Make server configs used across saves by default (#376) The server config now defaults to being read from the normal `config` folder, but can be overridden by a file with the same path and name placed in `serverconfigs`. --- gradle.properties | 2 +- .../neoforge/server/ServerLifecycleHooks.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9c6ed955d2..b8c9d1db22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=1.0.17 +fancy_mod_loader_version=2.0.0 mojang_logging_version=1.1.1 log4j_version=2.19.0 guava_version=31.1.2-jre diff --git a/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java b/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java index 0ae45dd23d..89ddf2d8f6 100644 --- a/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java +++ b/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java @@ -6,6 +6,7 @@ package net.neoforged.neoforge.server; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -40,6 +41,7 @@ import net.neoforged.fml.config.ConfigTracker; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.fml.loading.FMLPaths; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.util.LogicalSidedProvider; import net.neoforged.neoforge.common.world.BiomeModifier; @@ -82,6 +84,18 @@ private static Path getServerConfigPath(final MinecraftServer server) { throw new RuntimeException(e); } } + final Path explanation = serverConfig.resolve("readme.txt"); + if (!Files.exists(explanation)) { + try { + Files.writeString(explanation, """ + Any server configs put in this folder will override the corresponding server config from /config/. + If the config being transferred is in a subfolder of the base config folder make sure to include that folder here in the path to the file you are overwriting. + For example if you are overwriting a config with the path /config/ExampleMod/config-server.toml, you would need to put it in serverconfig/ExampleMod/config-server.toml + """, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } + } return serverConfig; } @@ -89,7 +103,7 @@ public static void handleServerAboutToStart(final MinecraftServer server) { currentServer = server; // on the dedi server we need to force the stuff to setup properly LogicalSidedProvider.setServer(() -> server); - ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server)); + ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, FMLPaths.CONFIGDIR.get(), getServerConfigPath(server)); runModifiers(server); NeoForge.EVENT_BUS.post(new ServerAboutToStartEvent(server)); } @@ -130,7 +144,7 @@ public static void handleServerStopped(final MinecraftServer server) { latch.countDown(); exitLatch = null; } - ConfigTracker.INSTANCE.unloadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server)); + ConfigTracker.INSTANCE.unloadConfigs(ModConfig.Type.SERVER); } public static MinecraftServer getCurrentServer() {