mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Change some event names, hook up the event code for server events for FML
This commit is contained in:
1 parent
9a5dac605c
commit
7edc7d74d4
7 files changed
+86
-73
No files matched your search
@@ -23,6 +23,12 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.ImmutableBiMap.Builder;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
@@ -37,6 +43,10 @@ import cpw.mods.fml.common.event.FMLConstructionEvent;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
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.FMLServerStoppingEvent;
|
||||
import cpw.mods.fml.common.event.FMLStateEvent;
|
||||
import cpw.mods.fml.common.registry.FMLRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||
@@ -60,6 +70,17 @@ public class FMLModContainer implements ModContainer
|
||||
private Multimap<Class<? extends Annotation>, Object> annotations;
|
||||
private DefaultArtifactVersion processedVersion;
|
||||
|
||||
private static final BiMap<Class<? extends FMLStateEvent>, Class<? extends Annotation>> modAnnotationTypes = ImmutableBiMap.<Class<? extends FMLStateEvent>, Class<? extends Annotation>>builder()
|
||||
.put(FMLPreInitializationEvent.class, Mod.PreInit.class)
|
||||
.put(FMLInitializationEvent.class, Mod.Init.class)
|
||||
.put(FMLPostInitializationEvent.class, Mod.PostInit.class)
|
||||
.put(FMLServerStartingEvent.class, Mod.ServerStarting.class)
|
||||
.put(FMLServerStartedEvent.class, Mod.ServerStarted.class)
|
||||
.put(FMLServerStoppingEvent.class, Mod.ServerStopping.class)
|
||||
.build();
|
||||
private static final BiMap<Class<? extends Annotation>, Class<? extends FMLStateEvent>> modTypeAnnotations = modAnnotationTypes.inverse();
|
||||
|
||||
|
||||
public FMLModContainer(String className, File modSource, Map<String,Object> modDescriptor)
|
||||
{
|
||||
this.className = className;
|
||||
@@ -202,23 +223,8 @@ public class FMLModContainer implements ModContainer
|
||||
{
|
||||
for (Annotation a : m.getAnnotations())
|
||||
{
|
||||
Class<?>[] paramTypes;
|
||||
if (a.annotationType() == Mod.PreInit.class)
|
||||
{
|
||||
paramTypes = Mod.PreInit.paramTypes;
|
||||
}
|
||||
else if (a.annotationType() == Mod.Init.class)
|
||||
{
|
||||
paramTypes = Mod.Init.paramTypes;
|
||||
}
|
||||
else if (a.annotationType() == Mod.PostInit.class)
|
||||
{
|
||||
paramTypes = Mod.PostInit.paramTypes;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Class<?>[] paramTypes = new Class[] { modTypeAnnotations.get(a.annotationType()) };
|
||||
|
||||
if (Arrays.equals(m.getParameterTypes(), paramTypes))
|
||||
{
|
||||
m.setAccessible(true);
|
||||
@@ -247,12 +253,12 @@ public class FMLModContainer implements ModContainer
|
||||
Field f = (Field) o;
|
||||
f.set(modInstance, modMetadata);
|
||||
}
|
||||
|
||||
for (Object o : annotations.get(Block.class))
|
||||
{
|
||||
Field f = (Field) o;
|
||||
f.set(modInstance, GameRegistry.buildBlock(this, f.getType(), f.getAnnotation(Block.class)));
|
||||
}
|
||||
//TODO
|
||||
// for (Object o : annotations.get(Block.class))
|
||||
// {
|
||||
// Field f = (Field) o;
|
||||
// f.set(modInstance, GameRegistry.buildBlock(this, f.getType(), f.getAnnotation(Block.class)));
|
||||
// }
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -275,47 +281,16 @@ public class FMLModContainer implements ModContainer
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void preInitMod(FMLPreInitializationEvent event)
|
||||
public void handleModStateEvent(FMLStateEvent event)
|
||||
{
|
||||
Class<? extends Annotation> annotation = modAnnotationTypes.get(event.getClass());
|
||||
if (annotation == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
for (Object o : annotations.get(Mod.PreInit.class))
|
||||
{
|
||||
Method m = (Method) o;
|
||||
m.invoke(modInstance, event);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
controller.errorOccurred(this, t);
|
||||
Throwables.propagateIfPossible(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void initMod(FMLInitializationEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Object o : annotations.get(Mod.Init.class))
|
||||
{
|
||||
Method m = (Method) o;
|
||||
m.invoke(modInstance, event);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
controller.errorOccurred(this, t);
|
||||
Throwables.propagateIfPossible(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void postInitMod(FMLPostInitializationEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Object o : annotations.get(Mod.PostInit.class))
|
||||
for (Object o : annotations.get(annotation))
|
||||
{
|
||||
Method m = (Method) o;
|
||||
m.invoke(modInstance, event);
|
||||
|
||||
@@ -7,9 +7,9 @@ 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.FMLServerStarted;
|
||||
import cpw.mods.fml.common.event.FMLServerStarting;
|
||||
import cpw.mods.fml.common.event.FMLServerStopping;
|
||||
import cpw.mods.fml.common.event.FMLServerStartedEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||
import cpw.mods.fml.common.event.FMLStateEvent;
|
||||
|
||||
/**
|
||||
@@ -26,9 +26,9 @@ public enum LoaderState
|
||||
INITIALIZATION("Initializing mods", FMLInitializationEvent.class),
|
||||
POSTINITIALIZATION("Post-initializing mods", FMLPostInitializationEvent.class),
|
||||
AVAILABLE("Mod loading complete", FMLLoadCompleteEvent.class),
|
||||
SERVER_STARTING("Server starting", FMLServerStarting.class),
|
||||
SERVER_STARTED("Server started", FMLServerStarted.class),
|
||||
SERVER_STOPPING("Server stopping", FMLServerStopping.class),
|
||||
SERVER_STARTING("Server starting", FMLServerStartingEvent.class),
|
||||
SERVER_STARTED("Server started", FMLServerStartedEvent.class),
|
||||
SERVER_STOPPING("Server stopping", FMLServerStoppingEvent.class),
|
||||
ERRORED("Mod Loading errored",null);
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ import java.lang.annotation.Target;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
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.FMLServerStoppingEvent;
|
||||
|
||||
import net.minecraft.src.ItemBlock;
|
||||
|
||||
@@ -91,6 +94,36 @@ public @interface Mod
|
||||
public @interface PostInit {
|
||||
static Class<?>[] paramTypes = new Class[] { FMLPostInitializationEvent.class };
|
||||
}
|
||||
/**
|
||||
* Mark the designated method as being called at the "server-starting" phase
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ServerStarting {
|
||||
static Class<?>[] paramTypes = new Class[] { FMLServerStartingEvent.class };
|
||||
}
|
||||
/**
|
||||
* Mark the designated method as being called at the "post-initialization" phase
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ServerStarted {
|
||||
static Class<?>[] paramTypes = new Class[] { FMLServerStartedEvent.class };
|
||||
}
|
||||
/**
|
||||
* Mark the designated method as being called at the "post-initialization" phase
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ServerStopping {
|
||||
static Class<?>[] paramTypes = new Class[] { FMLServerStoppingEvent.class };
|
||||
}
|
||||
/**
|
||||
* Populate the annotated field with the mod instance.
|
||||
* @author cpw
|
||||
|
||||
+2
-2
@@ -3,10 +3,10 @@ package cpw.mods.fml.common.event;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.LoaderState.ModState;
|
||||
|
||||
public class FMLServerStarted extends FMLStateEvent
|
||||
public class FMLServerStartedEvent extends FMLStateEvent
|
||||
{
|
||||
|
||||
public FMLServerStarted(Object... data)
|
||||
public FMLServerStartedEvent(Object... data)
|
||||
{
|
||||
super(data);
|
||||
}
|
||||
+2
-2
@@ -3,12 +3,12 @@ package cpw.mods.fml.common.event;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.LoaderState.ModState;
|
||||
|
||||
public class FMLServerStarting extends FMLStateEvent
|
||||
public class FMLServerStartingEvent extends FMLStateEvent
|
||||
{
|
||||
|
||||
private Object server;
|
||||
|
||||
public FMLServerStarting(Object... data)
|
||||
public FMLServerStartingEvent(Object... data)
|
||||
{
|
||||
super(data);
|
||||
this.server = data[0];
|
||||
+2
-2
@@ -3,10 +3,10 @@ package cpw.mods.fml.common.event;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.LoaderState.ModState;
|
||||
|
||||
public class FMLServerStopping extends FMLStateEvent
|
||||
public class FMLServerStoppingEvent extends FMLStateEvent
|
||||
{
|
||||
|
||||
public FMLServerStopping(Object... data)
|
||||
public FMLServerStoppingEvent(Object... data)
|
||||
{
|
||||
super(data);
|
||||
}
|
||||
@@ -50,6 +50,11 @@
|
||||
<type>2</type>
|
||||
<locationURI>MCP_LOC/src-work/common</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>common/fmlversion.properties</name>
|
||||
<type>1</type>
|
||||
<locationURI>MCP_LOC/FML/fmlversion.properties</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
|
||||
Reference in new issue
Block a user