Reorganize modloading on the dediserver. This removes the DedicatedServer parameter from the FMLDedicatedServerSetupEvent.

Code for customizing the server instance should be moved to the ServerAboutToStartEvent or similar, where the server instance
is available.

This reorganization means that mods will load fully before the server is even constructed, or the server properties loaded. We also move the EULA right to the front so we don't have to wait for bootstrap.

This should fix the problems with mods which customize world data and other things.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2020-06-29 22:08:50 -04:00
parent d5aa0c4a91
commit 99e7fad655
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
6 changed files with 62 additions and 74 deletions

View file

@ -8,16 +8,40 @@
try {
OptionSet optionset = optionparser.parse(p_main_0_);
@@ -86,7 +87,7 @@
@@ -79,32 +80,36 @@
optionparser.printHelpOn(System.err);
return;
}
+ Path path1 = Paths.get("eula.txt");
+ ServerEula servereula = new ServerEula(path1);
+ if (!optionset.has(optionspec1) && !servereula.func_154346_a()) {
+ field_240759_a_.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
+ return;
+ }
CrashReport.func_230188_h_();
Bootstrap.func_151354_b();
Bootstrap.func_218821_c();
Util.func_240994_l_();
+ if (!optionset.has(optionspec1)) net.minecraftforge.fml.server.ServerModLoader.load(); // Load mods before we load almost anything else anymore. Single spot now. Only loads if they haven't passed the initserver param
Path path = Paths.get("server.properties");
ServerPropertiesProvider serverpropertiesprovider = new ServerPropertiesProvider(path);
- serverpropertiesprovider.func_219035_b();
+ if (optionset.has(optionspec1) || !java.nio.file.Files.exists(path)) serverpropertiesprovider.func_219035_b();
Path path1 = Paths.get("eula.txt");
ServerEula servereula = new ServerEula(path1);
serverpropertiesprovider.func_219035_b();
- Path path1 = Paths.get("eula.txt");
- ServerEula servereula = new ServerEula(path1);
if (optionset.has(optionspec1)) {
@@ -105,6 +106,11 @@
field_240759_a_.info("Initialized '{}' and '{}'", path.toAbsolutePath(), path1.toAbsolutePath());
return;
}
- if (!servereula.func_154346_a()) {
- field_240759_a_.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
- return;
- }
-
File file1 = new File(optionset.valueOf(optionspec9));
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
PlayerProfileCache playerprofilecache = new PlayerProfileCache(gameprofilerepository, new File(file1, MinecraftServer.field_152367_a.getName()));
String s = Optional.ofNullable(optionset.valueOf(optionspec10)).orElse(serverpropertiesprovider.func_219034_a().field_219021_o);
@ -25,11 +49,10 @@
+ field_240759_a_.error("Invalid world directory specified, must not be null, empty or the same directory as your universe! " + s);
+ return;
+ }
+ net.minecraftforge.fml.server.ServerModLoader.gatherAndInit(); // Gather and construct mods before resource loading and before world conversions.
SaveFormat saveformat = SaveFormat.func_237269_a_(file1.toPath());
SaveFormat.LevelSave saveformat$levelsave = saveformat.func_237274_c_(s);
MinecraftServer.func_240777_a_(saveformat$levelsave);
@@ -170,6 +176,7 @@
@@ -170,6 +175,7 @@
Thread thread = new Thread("Server Shutdown Thread") {
public void run() {
dedicatedserver.func_71263_m(true);

View file

@ -8,24 +8,7 @@
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
String s1;
@@ -98,7 +99,9 @@
field_155771_h.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
}
+ net.minecraftforge.fml.server.ServerModLoader.begin(this);
field_155771_h.info("Loading properties");
+ this.field_71340_o.func_219033_a(properties -> ServerProperties.func_218985_a(java.nio.file.Paths.get("server.properties")));
ServerProperties serverproperties = this.field_71340_o.func_219034_a();
if (this.func_71264_H()) {
this.func_71189_e("127.0.0.1");
@@ -153,17 +156,20 @@
if (!PreYggdrasilConverter.func_219587_e(this)) {
return false;
} else {
+ net.minecraftforge.fml.server.ServerModLoader.end();
this.func_184105_a(new DedicatedPlayerList(this, this.field_240767_f_, this.field_240766_e_));
long i = Util.func_211178_c();
this.func_71191_d(serverproperties.field_219026_t);
@@ -159,11 +160,13 @@
SkullTileEntity.func_184293_a(this.func_152358_ax());
SkullTileEntity.func_184294_a(this.func_147130_as());
PlayerProfileCache.func_187320_a(this.func_71266_T());
@ -39,7 +22,7 @@
if (serverproperties.field_219027_u != null) {
this.func_200252_aR().func_223585_a(GameRules.field_223620_w).func_223570_a(serverproperties.field_219027_u, this);
}
@@ -189,11 +195,12 @@
@@ -189,11 +192,12 @@
}
Items.field_190931_a.func_150895_a(ItemGroup.field_78027_g, NonNullList.func_191196_a());
@ -53,7 +36,7 @@
}
}
@@ -506,6 +513,11 @@
@@ -506,6 +510,11 @@
return false;
}

View file

@ -40,7 +40,7 @@ public enum SidedProvider
()-> { throw new UnsupportedOperationException(); }),
SIDED_SETUP_EVENT(
(Function<Supplier<Minecraft>, Function<ModContainer, Event>>)c-> mc->new FMLClientSetupEvent(c, mc),
s-> mc->new FMLDedicatedServerSetupEvent(s, mc),
s-> mc->new FMLDedicatedServerSetupEvent(mc),
()-> { throw new UnsupportedOperationException(); }),
STRIPCHARS(
(Function<Supplier<Minecraft>, Function<String, String>>)c-> ClientHooks::stripSpecialChars,

View file

@ -36,20 +36,16 @@ import java.util.function.Supplier;
*
* Do dedicated server specific activities with this event.
*
* <em>This event is fired before construction of the dedicated server. Use {@link net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent}
* or {@link net.minecraftforge.fml.event.server.FMLServerStartingEvent} to do stuff with the server, in both dedicated
* and integrated server contexts</em>
*
* This is a parallel dispatch event.
*/
public class FMLDedicatedServerSetupEvent extends ModLifecycleEvent
{
private final Supplier<DedicatedServer> serverSupplier;
public FMLDedicatedServerSetupEvent(Supplier<DedicatedServer> server, ModContainer container)
public FMLDedicatedServerSetupEvent(ModContainer container)
{
super(container);
this.serverSupplier = server;
}
public Supplier<DedicatedServer> getServerSupplier()
{
return serverSupplier;
}
}

View file

@ -31,7 +31,19 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import net.minecraft.resources.IPackNameDecorator;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.storage.FolderName;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSidedProvider;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.SidedProvider;
import net.minecraftforge.fml.network.ConnectionType;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import net.minecraftforge.fml.network.FMLStatusPing;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.fml.network.NetworkRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
@ -46,11 +58,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSidedProvider;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.config.ConfigTracker;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
@ -60,10 +67,6 @@ import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import net.minecraftforge.fml.loading.FileUtils;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.network.ConnectionType;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.packs.ModFileResourcePack;
import net.minecraftforge.fml.packs.ResourcePackLoader;
import net.minecraftforge.forgespi.language.IModInfo;
@ -87,6 +90,9 @@ public class ServerLifecycleHooks
public static boolean handleServerAboutToStart(final MinecraftServer server)
{
currentServer = server;
currentServer.getServerStatusResponse().setForgeData(new FMLStatusPing()); //gathers NetworkRegistry data
// on the dedi server we need to force the stuff to setup properly
DistExecutor.unsafeRunWhenOn(Dist.DEDICATED_SERVER, ()->()->SidedProvider.setServer(()->(DedicatedServer)server));
LogicalSidedProvider.setServer(()->server);
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
return !MinecraftForge.EVENT_BUS.post(new FMLServerAboutToStartEvent(server));

View file

@ -19,10 +19,12 @@
package net.minecraftforge.fml.server;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.*;
import net.minecraftforge.fml.network.FMLStatusPing;
import net.minecraftforge.fml.LoadingFailedException;
import net.minecraftforge.fml.LogicalSidedProvider;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.SidedProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -33,40 +35,19 @@ import static net.minecraftforge.fml.loading.LogMarkers.LOADING;
public class ServerModLoader
{
private static final Logger LOGGER = LogManager.getLogger();
private static DedicatedServer server;
private static boolean hasErrors = false;
public static void gatherAndInit() {
LanguageHook.loadForgeAndMCLangs();
public static void load() {
SidedProvider.setServer(()-> {
throw new IllegalStateException("Unable to access server yet");
});
LogicalSidedProvider.setServer(()-> {
throw new IllegalStateException("Unable to access server yet");
});
LanguageHook.loadForgeAndMCLangs();
try {
ModLoader.get().gatherAndInitializeMods(() -> {});
} catch (LoadingFailedException e) {
ServerModLoader.hasErrors = true;
throw e;
}
}
public static void begin(DedicatedServer dedicatedServer) {
ServerModLoader.server = dedicatedServer;
SidedProvider.setServer(()->ServerModLoader.server);
LogicalSidedProvider.setServer(()->ServerModLoader.server);
try {
ModLoader.get().loadMods(Runnable::run, (a)->{}, (a)->{});
} catch (LoadingFailedException e) {
ServerModLoader.hasErrors = true;
throw e;
}
}
public static void end() {
try {
ModLoader.get().finishMods(Runnable::run);
} catch (LoadingFailedException e) {
ServerModLoader.hasErrors = true;
@ -78,7 +59,6 @@ public class ServerModLoader
warnings.forEach(warning -> LOGGER.warn(LOADING, warning.formatToString()));
}
MinecraftForge.EVENT_BUS.start();
server.getServerStatusResponse().setForgeData(new FMLStatusPing()); //gathers NetworkRegistry data
}
public static boolean hasErrors() {