コード例 #1
0
 public Properties searchForVersionProperties() {
   try {
     FMLLog.fine(
         "Attempting to load the file version.properties from %s to locate a version number for %s",
         getSource().getName(), getModId());
     Properties version = null;
     if (getSource().isFile()) {
       ZipFile source = new ZipFile(getSource());
       ZipEntry versionFile = source.getEntry("version.properties");
       if (versionFile != null) {
         version = new Properties();
         version.load(source.getInputStream(versionFile));
       }
       source.close();
     } else if (getSource().isDirectory()) {
       File propsFile = new File(getSource(), "version.properties");
       if (propsFile.exists() && propsFile.isFile()) {
         version = new Properties();
         FileInputStream fis = new FileInputStream(propsFile);
         version.load(fis);
         fis.close();
       }
     }
     return version;
   } catch (Exception e) {
     Throwables.propagateIfPossible(e);
     FMLLog.fine("Failed to find a usable version.properties file");
     return null;
   }
 }
コード例 #2
0
 private void parseSimpleFieldAnnotation(
     SetMultimap<String, ASMData> annotations,
     String annotationClassName,
     Function<ModContainer, Object> retreiver)
     throws IllegalAccessException {
   String[] annName = annotationClassName.split("\\.");
   String annotationName = annName[annName.length - 1];
   for (ASMData targets : annotations.get(annotationClassName)) {
     String targetMod = (String) targets.getAnnotationInfo().get("value");
     Field f = null;
     Object injectedMod = null;
     ModContainer mc = this;
     boolean isStatic = false;
     Class<?> clz = modInstance.getClass();
     if (!Strings.isNullOrEmpty(targetMod)) {
       if (Loader.isModLoaded(targetMod)) {
         mc = (ModContainer) Loader.instance().getIndexedModList().get(targetMod);
       } else {
         mc = null;
       }
     }
     if (mc != null) {
       try {
         clz = Class.forName(targets.getClassName(), true, Loader.instance().getModClassLoader());
         f = clz.getDeclaredField(targets.getObjectName());
         f.setAccessible(true);
         isStatic = Modifier.isStatic(f.getModifiers());
         injectedMod = retreiver.apply(mc);
       } catch (Exception e) {
         Throwables.propagateIfPossible(e);
         FMLLog.log(
             Level.WARNING,
             e,
             "Attempting to load @%s in class %s for %s and failing",
             annotationName,
             targets.getClassName(),
             mc.getModId());
       }
     }
     if (f != null) {
       Object target = null;
       if (!isStatic) {
         target = modInstance;
         if (!modInstance.getClass().equals(clz)) {
           FMLLog.warning(
               "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance",
               annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId());
           continue;
         }
       }
       f.set(target, injectedMod);
     }
   }
 }
コード例 #3
0
 @Subscribe
 public void handleModStateEvent(FMLEvent event) {
   Class<? extends Annotation> annotation = modAnnotationTypes.get(event.getClass());
   if (annotation == null) {
     return;
   }
   try {
     for (Object o : annotations.get(annotation)) {
       Method m = (Method) o;
       m.invoke(modInstance, event);
     }
   } catch (Throwable t) {
     controller.errorOccurred(this, t);
     Throwables.propagateIfPossible(t);
   }
 }
コード例 #4
0
 @Subscribe
 public void constructMod(FMLConstructionEvent event) {
   try {
     ModClassLoader modClassLoader = event.getModClassLoader();
     modClassLoader.addFile(source);
     // MCPC - show users what mod is being loaded in case a crash occurs
     FMLLog.fine("Constructing mod from file source : " + source);
     Class<?> clazz = Class.forName(className, true, modClassLoader);
     ASMDataTable asmHarvestedAnnotations = event.getASMHarvestedData();
     // TODO
     asmHarvestedAnnotations.getAnnotationsFor(this);
     annotations = gatherAnnotations(clazz);
     isNetworkMod =
         FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData());
     modInstance = clazz.newInstance();
     ProxyInjector.inject(
         this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
     processFieldAnnotations(event.getASMHarvestedData());
   } catch (Throwable e) {
     controller.errorOccurred(this, e);
     Throwables.propagateIfPossible(e);
   }
 }