/** * Find mod classes in the class path and enumerated mod files list * * @param classPathEntries Java class path split into string entries * @return map of classes to load */ private HashMap<String, Class> findModClasses( String[] classPathEntries, LinkedList<File> modFiles) { // To try to avoid loading the same mod multiple times if it appears in more than one entry in // the class path, we index // the mods by name and hopefully match only a single instance of a particular mod HashMap<String, Class> modsToLoad = new HashMap<String, Class>(); try { logger.info("Searching protection domain code source..."); File packagePath = new File(LiteLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI()); LinkedList<Class> modClasses = getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); for (Class mod : modClasses) { modsToLoad.put(mod.getSimpleName(), mod); } if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); } catch (Throwable th) { logger.warning("Error loading from local class path: " + th.getMessage()); } // Search through the class path and find mod classes for (String classPathPart : classPathEntries) { logger.info(String.format("Searching %s...", classPathPart)); File packagePath = new File(classPathPart); LinkedList<Class> modClasses = getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); for (Class mod : modClasses) { modsToLoad.put(mod.getSimpleName(), mod); } if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); } // Search through mod files and find mod classes for (File modFile : modFiles) { logger.info(String.format("Searching %s...", modFile.getAbsolutePath())); LinkedList<Class> modClasses = getSubclassesFor(modFile, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); for (Class mod : modClasses) { modsToLoad.put(mod.getSimpleName(), mod); } if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); } return modsToLoad; }
public String toString() { return "type=" + type.getSimpleName() + ",data=" + data.getClass().getSimpleName() + ':' + data; }