From cd67596d574abcc1c9e6d313c2954dce39cdf02c Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 22 Jan 2013 09:11:44 -0500 Subject: [PATCH] The "ServerStarting" event should now properly crash the server if it fails, so the client will properly exit. Also, added in a "pre-server-start" event that fires before the worlds are loaded for a save, just for you immibis. --- .../cpw/mods/fml/common/FMLCommonHandler.java | 9 ++++-- .../cpw/mods/fml/common/FMLModContainer.java | 2 ++ common/cpw/mods/fml/common/Loader.java | 30 +++++++++++++++++-- common/cpw/mods/fml/common/LoaderState.java | 2 ++ common/cpw/mods/fml/common/Mod.java | 8 +++++ .../event/FMLServerAboutToStartEvent.java | 25 ++++++++++++++++ 6 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 common/cpw/mods/fml/common/event/FMLServerAboutToStartEvent.java diff --git a/common/cpw/mods/fml/common/FMLCommonHandler.java b/common/cpw/mods/fml/common/FMLCommonHandler.java index b4627773a8..2fc57b7a58 100644 --- a/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -304,9 +304,14 @@ public class FMLCommonHandler } } - public void handleServerStarting(MinecraftServer server) + public boolean handleServerAboutToStart(MinecraftServer server) { - Loader.instance().serverStarting(server); + return Loader.instance().serverAboutToStart(server); + } + + public boolean handleServerStarting(MinecraftServer server) + { + return Loader.instance().serverStarting(server); } public void handleServerStarted() diff --git a/common/cpw/mods/fml/common/FMLModContainer.java b/common/cpw/mods/fml/common/FMLModContainer.java index 7ab6449bbe..252aea20c5 100644 --- a/common/cpw/mods/fml/common/FMLModContainer.java +++ b/common/cpw/mods/fml/common/FMLModContainer.java @@ -58,6 +58,7 @@ import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.event.FMLFingerprintViolationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; import cpw.mods.fml.common.event.FMLServerStartedEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; @@ -90,6 +91,7 @@ public class FMLModContainer implements ModContainer .put(FMLPreInitializationEvent.class, Mod.PreInit.class) .put(FMLInitializationEvent.class, Mod.Init.class) .put(FMLPostInitializationEvent.class, Mod.PostInit.class) + .put(FMLServerAboutToStartEvent.class, Mod.ServerAboutToStart.class) .put(FMLServerStartingEvent.class, Mod.ServerStarting.class) .put(FMLServerStartedEvent.class, Mod.ServerStarted.class) .put(FMLServerStoppingEvent.class, Mod.ServerStopping.class) diff --git a/common/cpw/mods/fml/common/Loader.java b/common/cpw/mods/fml/common/Loader.java index ef325430e0..e212775a07 100644 --- a/common/cpw/mods/fml/common/Loader.java +++ b/common/cpw/mods/fml/common/Loader.java @@ -695,10 +695,19 @@ public class Loader return "Minecraft " + mccversion; } - public void serverStarting(Object server) + public boolean serverStarting(Object server) { - modController.distributeStateMessage(LoaderState.SERVER_STARTING, server); - modController.transition(LoaderState.SERVER_STARTING); + try + { + modController.distributeStateMessage(LoaderState.SERVER_STARTING, server); + modController.transition(LoaderState.SERVER_STARTING); + } + catch (Throwable t) + { + FMLLog.log(Level.SEVERE, t, "A fatal exception occurred during the server starting event"); + return false; + } + return true; } public void serverStarted() @@ -752,4 +761,19 @@ public class Loader modController.transition(LoaderState.SERVER_STOPPED); modController.transition(LoaderState.AVAILABLE); } + + public boolean serverAboutToStart(MinecraftServer server) + { + try + { + modController.distributeStateMessage(LoaderState.SERVER_ABOUT_TO_START, server); + modController.transition(LoaderState.SERVER_ABOUT_TO_START); + } + catch (Throwable t) + { + FMLLog.log(Level.SEVERE, t, "A fatal exception occurred during the server about to start event"); + return false; + } + return true; + } } diff --git a/common/cpw/mods/fml/common/LoaderState.java b/common/cpw/mods/fml/common/LoaderState.java index 0bd780301b..4bdb1223f4 100644 --- a/common/cpw/mods/fml/common/LoaderState.java +++ b/common/cpw/mods/fml/common/LoaderState.java @@ -8,6 +8,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; import cpw.mods.fml.common.event.FMLServerStartedEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; @@ -28,6 +29,7 @@ public enum LoaderState INITIALIZATION("Initializing mods", FMLInitializationEvent.class), POSTINITIALIZATION("Post-initializing mods", FMLPostInitializationEvent.class), AVAILABLE("Mod loading complete", FMLLoadCompleteEvent.class), + SERVER_ABOUT_TO_START("Server about to start", FMLServerAboutToStartEvent.class), SERVER_STARTING("Server starting", FMLServerStartingEvent.class), SERVER_STARTED("Server started", FMLServerStartedEvent.class), SERVER_STOPPING("Server stopping", FMLServerStoppingEvent.class), diff --git a/common/cpw/mods/fml/common/Mod.java b/common/cpw/mods/fml/common/Mod.java index 5aa5cd4f22..51d753723c 100644 --- a/common/cpw/mods/fml/common/Mod.java +++ b/common/cpw/mods/fml/common/Mod.java @@ -144,6 +144,14 @@ public @interface Mod @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface PostInit {} + /** + * Mark the designated method as being called at the "server-about-to-start" phase + * @author cpw + * + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface ServerAboutToStart {} /** * Mark the designated method as being called at the "server-starting" phase * @author cpw diff --git a/common/cpw/mods/fml/common/event/FMLServerAboutToStartEvent.java b/common/cpw/mods/fml/common/event/FMLServerAboutToStartEvent.java new file mode 100644 index 0000000000..14574c10fd --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLServerAboutToStartEvent.java @@ -0,0 +1,25 @@ +package cpw.mods.fml.common.event; + +import net.minecraft.server.MinecraftServer; +import cpw.mods.fml.common.LoaderState.ModState; + +public class FMLServerAboutToStartEvent extends FMLStateEvent { + + private MinecraftServer server; + + public FMLServerAboutToStartEvent(Object... data) + { + super(data); + this.server = (MinecraftServer) data[0]; + } + @Override + public ModState getModState() + { + return ModState.AVAILABLE; + } + + public MinecraftServer getServer() + { + return server; + } +}