Add in a "server stopped" event

This commit is contained in:
Christian 2012-12-30 23:52:38 -05:00
parent 2454ed0fbf
commit 80193d4969
7 changed files with 54 additions and 10 deletions

View file

@ -453,4 +453,9 @@ public class FMLCommonHandler
{
sidedDelegate.disconnectIDMismatch(serverDifference, toKill, network);
}
public void handleServerStopped()
{
Loader.instance().serverStopped();
}
}

View file

@ -60,6 +60,7 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.event.FMLStateEvent;
import cpw.mods.fml.common.network.FMLNetworkHandler;
@ -92,6 +93,7 @@ public class FMLModContainer implements ModContainer
.put(FMLServerStartingEvent.class, Mod.ServerStarting.class)
.put(FMLServerStartedEvent.class, Mod.ServerStarted.class)
.put(FMLServerStoppingEvent.class, Mod.ServerStopping.class)
.put(FMLServerStoppedEvent.class, Mod.ServerStopped.class)
.put(IMCEvent.class,Mod.IMCCallback.class)
.put(FMLFingerprintViolationEvent.class, Mod.FingerprintWarning.class)
.build();

View file

@ -27,6 +27,7 @@ import java.util.concurrent.Callable;
import java.util.logging.Level;
import net.minecraft.crash.CallableMinecraftVersion;
import net.minecraft.server.MinecraftServer;
import com.google.common.base.CharMatcher;
import com.google.common.base.Function;
@ -710,8 +711,6 @@ public class Loader
{
modController.distributeStateMessage(LoaderState.SERVER_STOPPING);
modController.transition(LoaderState.SERVER_STOPPING);
modController.transition(LoaderState.AVAILABLE);
}
public BiMap<ModContainer, Object> getModObjectList()
@ -746,4 +745,11 @@ public class Loader
public String getMCPVersionString() {
return String.format("MCP v%s", mcpversion);
}
public void serverStopped()
{
modController.distributeStateMessage(LoaderState.SERVER_STOPPED);
modController.transition(LoaderState.SERVER_STOPPED);
modController.transition(LoaderState.AVAILABLE);
}
}

View file

@ -10,6 +10,7 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.event.FMLStateEvent;
@ -30,6 +31,7 @@ public enum LoaderState
SERVER_STARTING("Server starting", FMLServerStartingEvent.class),
SERVER_STARTED("Server started", FMLServerStartedEvent.class),
SERVER_STOPPING("Server stopping", FMLServerStoppingEvent.class),
SERVER_STOPPED("Server stopped", FMLServerStoppedEvent.class),
ERRORED("Mod Loading errored",null);
@ -49,7 +51,7 @@ public enum LoaderState
return ERRORED;
}
// stopping -> available
if (this == SERVER_STOPPING)
if (this == SERVER_STOPPED)
{
return AVAILABLE;
}

View file

@ -168,6 +168,14 @@ public @interface Mod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ServerStopping {}
/**
* Mark the designated method as being called at the "server-stopped" phase
* @author cpw
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ServerStopped {}
/**
* Mark the designated method as the receiver for {@link FMLInterModComms} messages
* Called between {@link Init} and {@link PostInit}

View file

@ -0,0 +1,18 @@
package cpw.mods.fml.common.event;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.LoaderState.ModState;
public class FMLServerStoppedEvent extends FMLStateEvent {
public FMLServerStoppedEvent(Object... data)
{
super(data);
}
@Override
public ModState getModState()
{
return ModState.AVAILABLE;
}
}

View file

@ -40,8 +40,11 @@
var48.printStackTrace();
field_71306_a.log(Level.SEVERE, "Encountered an unexpected exception " + var48.getClass().getSimpleName(), var48);
CrashReport var2 = null;
@@ -455,6 +467,10 @@
@@ -453,8 +465,13 @@
}
finally
{
+ FMLCommonHandler.instance().handleServerStopped();
try
{
+ if (FMLCommonHandler.instance().shouldServerBeKilledQuietly())
@ -51,7 +54,7 @@
this.func_71260_j();
this.field_71316_v = true;
}
@@ -480,8 +496,10 @@
@@ -480,8 +497,10 @@
public void func_71217_p()
{
@ -62,7 +65,7 @@
++this.field_71315_w;
if (this.field_71295_T)
@@ -527,6 +545,7 @@
@@ -527,6 +546,7 @@
this.field_71304_b.func_76319_b();
this.field_71304_b.func_76319_b();
@ -70,7 +73,7 @@
}
public void func_71190_q()
@@ -554,6 +573,7 @@
@@ -554,6 +574,7 @@
}
this.field_71304_b.func_76320_a("tick");
@ -78,7 +81,7 @@
CrashReport var6;
try
@@ -578,6 +598,7 @@
@@ -578,6 +599,7 @@
throw new ReportedException(var6);
}
@ -86,7 +89,7 @@
this.field_71304_b.func_76319_b();
this.field_71304_b.func_76320_a("tracker");
var4.func_73039_n().func_72788_a();
@@ -705,7 +726,7 @@
@@ -705,7 +727,7 @@
public String getServerModName()
{
@ -95,7 +98,7 @@
}
public CrashReport func_71230_b(CrashReport p_71230_1_)
@@ -1146,6 +1167,13 @@
@@ -1146,6 +1168,13 @@
@SideOnly(Side.SERVER)
public static void main(String[] p_main_0_)
{