java类cpw.mods.fml.common.event.FMLEvent的实例源码

FMLModContainer.java 文件源码 项目:RuneCraftery 阅读 25 收藏 0 点赞 0 评论 0
private Method gatherAnnotations(Class<?> clazz) throws Exception
{
    Method factoryMethod = null;
    for (Method m : clazz.getDeclaredMethods())
    {
        for (Annotation a : m.getAnnotations())
        {
            if (modTypeAnnotations.containsKey(a.annotationType()))
            {
                Class<?>[] paramTypes = new Class[] { modTypeAnnotations.get(a.annotationType()) };
                if (Arrays.equals(m.getParameterTypes(), paramTypes))
                {
                    m.setAccessible(true);
                    eventMethods.put(modTypeAnnotations.get(a.annotationType()), m);
                }
                else
                {
                    FMLLog.log(getModId(), Level.SEVERE,"The mod %s appears to have an invalid method annotation %s. This annotation can only apply to methods with argument types %s -it will not be called", getModId(), a.annotationType().getSimpleName(), Arrays.toString(paramTypes));
                }
            }
            else if (a.annotationType().equals(Mod.EventHandler.class))
            {
                if (m.getParameterTypes().length == 1 && modAnnotationTypes.containsKey(m.getParameterTypes()[0]))
                {
                    m.setAccessible(true);
                    eventMethods.put((Class<? extends FMLEvent>) m.getParameterTypes()[0],m);
                }
                else
                {
                    FMLLog.log(getModId(), Level.SEVERE,"The mod %s appears to have an invalid event annotation %s. This annotation can only apply to methods with recognized event arguments - it will not be called", getModId(), a.annotationType().getSimpleName());
                }
            }
            else if (a.annotationType().equals(Mod.InstanceFactory.class))
            {
                if (Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && factoryMethod == null)
                {
                    m.setAccessible(true);
                    factoryMethod = m;
                }
                else if (!(Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0))
                {
                    FMLLog.log(getModId(),  Level.SEVERE, "The InstanceFactory annotation can only apply to a static method, taking zero arguments - it will be ignored on %s(%s)", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
                else if (factoryMethod != null)
                {
                    FMLLog.log(getModId(), Level.SEVERE, "The InstanceFactory annotation can only be used once, the application to %s(%s) will be ignored", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
            }
        }
    }
    return factoryMethod;
}
FMLModContainer.java 文件源码 项目:BetterNutritionMod 阅读 27 收藏 0 点赞 0 评论 0
private Method gatherAnnotations(Class<?> clazz) throws Exception
{
    Method factoryMethod = null;
    for (Method m : clazz.getDeclaredMethods())
    {
        for (Annotation a : m.getAnnotations())
        {
            if (modTypeAnnotations.containsKey(a.annotationType()))
            {
                Class<?>[] paramTypes = new Class[] { modTypeAnnotations.get(a.annotationType()) };
                if (Arrays.equals(m.getParameterTypes(), paramTypes))
                {
                    m.setAccessible(true);
                    eventMethods.put(modTypeAnnotations.get(a.annotationType()), m);
                }
                else
                {
                    FMLLog.log(getModId(), Level.SEVERE,"The mod %s appears to have an invalid method annotation %s. This annotation can only apply to methods with argument types %s -it will not be called", getModId(), a.annotationType().getSimpleName(), Arrays.toString(paramTypes));
                }
            }
            else if (a.annotationType().equals(Mod.EventHandler.class))
            {
                if (m.getParameterTypes().length == 1 && modAnnotationTypes.containsKey(m.getParameterTypes()[0]))
                {
                    m.setAccessible(true);
                    eventMethods.put((Class<? extends FMLEvent>) m.getParameterTypes()[0],m);
                }
                else
                {
                    FMLLog.log(getModId(), Level.SEVERE,"The mod %s appears to have an invalid event annotation %s. This annotation can only apply to methods with recognized event arguments - it will not be called", getModId(), a.annotationType().getSimpleName());
                }
            }
            else if (a.annotationType().equals(Mod.InstanceFactory.class))
            {
                if (Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && factoryMethod == null)
                {
                    m.setAccessible(true);
                    factoryMethod = m;
                }
                else if (!(Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0))
                {
                    FMLLog.log(getModId(),  Level.SEVERE, "The InstanceFactory annotation can only apply to a static method, taking zero arguments - it will be ignored on %s(%s)", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
                else if (factoryMethod != null)
                {
                    FMLLog.log(getModId(), Level.SEVERE, "The InstanceFactory annotation can only be used once, the application to %s(%s) will be ignored", m.getName(), Arrays.asList(m.getParameterTypes()));
                }
            }
        }
    }
    return factoryMethod;
}
HelloWorldOre.java 文件源码 项目:dch_hack1ng_d4ys_workshop 阅读 15 收藏 0 点赞 0 评论 0
@EventHandler
public void init(FMLEvent event) {

}
OreMod.java 文件源码 项目:dch_hack1ng_d4ys_workshop 阅读 23 收藏 0 点赞 0 评论 0
@EventHandler
public void init(FMLEvent event) {

}


问题


面经


文章

微信
公众号

扫码关注公众号