Skip to content

Commit

Permalink
Make server configs used across saves by default (#376)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
pupnewfster authored Dec 13, 2023
1 parent 4e79de7 commit 4c56d6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -82,14 +84,26 @@ 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 <instance path>/config/<config path>.
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 <instance 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;
}

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));
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 4c56d6d

Please sign in to comment.