Java 类net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.Name 实例源码

项目:CustomWorldGen    文件:CoreModManager.java   
private static FMLPluginWrapper loadCoreMod(LaunchClassLoader classLoader, String coreModClass, File location)
{
    String coreModName = coreModClass.substring(coreModClass.lastIndexOf('.') + 1);
    try
    {
        FMLRelaunchLog.fine("Instantiating coremod class %s", coreModName);
        classLoader.addTransformerExclusion(coreModClass);
        Class<?> coreModClazz = Class.forName(coreModClass, true, classLoader);
        Name coreModNameAnn = coreModClazz.getAnnotation(IFMLLoadingPlugin.Name.class);
        if (coreModNameAnn != null && !Strings.isNullOrEmpty(coreModNameAnn.value()))
        {
            coreModName = coreModNameAnn.value();
            FMLRelaunchLog.finer("coremod named %s is loading", coreModName);
        }
        MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class);
        if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value())))
        {
            FMLRelaunchLog.log(Level.WARN, "The coremod %s does not have a MCVersion annotation, it may cause issues with this version of Minecraft",
                    coreModClass);
        }
        else if (requiredMCVersion != null && !FMLInjectionData.mccversion.equals(requiredMCVersion.value()))
        {
            FMLRelaunchLog.log(Level.ERROR, "The coremod %s is requesting minecraft version %s and minecraft is %s. It will be ignored.", coreModClass,
                    requiredMCVersion.value(), FMLInjectionData.mccversion);
            return null;
        }
        else if (requiredMCVersion != null)
        {
            FMLRelaunchLog.log(Level.DEBUG, "The coremod %s requested minecraft version %s and minecraft is %s. It will be loaded.", coreModClass,
                    requiredMCVersion.value(), FMLInjectionData.mccversion);
        }
        TransformerExclusions trExclusions = coreModClazz.getAnnotation(IFMLLoadingPlugin.TransformerExclusions.class);
        if (trExclusions != null)
        {
            for (String st : trExclusions.value())
            {
                classLoader.addTransformerExclusion(st);
            }
        }
        DependsOn deplist = coreModClazz.getAnnotation(IFMLLoadingPlugin.DependsOn.class);
        String[] dependencies = new String[0];
        if (deplist != null)
        {
            dependencies = deplist.value();
        }
        SortingIndex index = coreModClazz.getAnnotation(IFMLLoadingPlugin.SortingIndex.class);
        int sortIndex = index != null ? index.value() : 0;

        IFMLLoadingPlugin plugin = (IFMLLoadingPlugin) coreModClazz.newInstance();
        String accessTransformerClass = plugin.getAccessTransformerClass();
        if (accessTransformerClass != null)
        {
            FMLRelaunchLog.log(Level.DEBUG, "Added access transformer class %s to enqueued access transformers", accessTransformerClass);
            accessTransformers.add(accessTransformerClass);
        }
        FMLPluginWrapper wrap = new FMLPluginWrapper(coreModName, plugin, location, sortIndex, dependencies);
        loadPlugins.add(wrap);
        FMLRelaunchLog.fine("Enqueued coremod %s", coreModName);
        return wrap;
    }
    catch (ClassNotFoundException cnfe)
    {
        if (!Lists.newArrayList(rootPlugins).contains(coreModClass))
            FMLRelaunchLog.log(Level.ERROR, cnfe, "Coremod %s: Unable to class load the plugin %s", coreModName, coreModClass);
        else
            FMLRelaunchLog.fine("Skipping root plugin %s", coreModClass);
    }
    catch (ClassCastException cce)
    {
        FMLRelaunchLog.log(Level.ERROR, cce, "Coremod %s: The plugin %s is not an implementor of IFMLLoadingPlugin", coreModName, coreModClass);
    }
    catch (InstantiationException ie)
    {
        FMLRelaunchLog.log(Level.ERROR, ie, "Coremod %s: The plugin class %s was not instantiable", coreModName, coreModClass);
    }
    catch (IllegalAccessException iae)
    {
        FMLRelaunchLog.log(Level.ERROR, iae, "Coremod %s: The plugin class %s was not accessible", coreModName, coreModClass);
    }
    return null;
}