public ClassDiscoverer(IStringMatcher matcher, Class<?>... superclasses) { this.matcher = matcher; this.superclasses = new String[superclasses.length]; for (int i = 0; i < superclasses.length; i++) this.superclasses[i] = superclasses[i].getName().replace('.', '/'); classes = new ArrayList<Class<?>>(); modClassLoader = (ModClassLoader) Loader.instance().getModClassLoader(); }
@SuppressWarnings("unchecked") public FMLConstructionEvent(Object... eventData) { this.modClassLoader = (ModClassLoader)eventData[0]; this.asmData = (ASMDataTable) eventData[1]; this.reverseDependencies = (ListMultimap<String, String>) eventData[2]; }
private ClassLoader addClassPath(ClassLoader loader, File file) throws IOException { if (loader instanceof LaunchClassLoader) { ((LaunchClassLoader)loader).addURL(file.toURI().toURL()); return loader; } else if (loader instanceof ModClassLoader) { ((ModClassLoader)loader).addFile(file); return loader; } ClassLoader parent = loader.getParent(); return parent == null ? null : addClassPath(parent, file); }
@Subscribe public void constructMod(final FMLConstructionEvent event) { try { final ModClassLoader modClassLoader = event.getModClassLoader(); modClassLoader.addFile(this.mContainer.getSource()); modClassLoader.clearNegativeCacheFor(this.mCandidate.getClassList()); NetworkRegistry.INSTANCE.register(this.mContainer, (Class)this.mContainer.getClass(), (String)null, event.getASMHarvestedData()); Injector.inject(this.mMod, Injector.Phase.Construct, FMLCommonHandler.instance().getSide()); } catch (Throwable e) { throw new IllegalStateException("Cannot construct fan", e); } }
@Subscribe public void constructMod(FMLConstructionEvent event) { try { ModClassLoader modClassLoader = event.getModClassLoader(); modClassLoader.addFile(modSource); EnumSet<TickType> ticks = EnumSet.noneOf(TickType.class); this.gameTickHandler = new BaseModTicker(ticks, false); this.guiTickHandler = new BaseModTicker(ticks.clone(), true); Class<? extends BaseModProxy> modClazz = (Class<? extends BaseModProxy>) modClassLoader.loadBaseModClass(modClazzName); configureMod(modClazz, event.getASMHarvestedData()); isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, modClazz, event.getASMHarvestedData()); ModLoaderNetworkHandler dummyHandler = null; if (!isNetworkMod) { FMLLog.fine("Injecting dummy network mod handler for BaseMod %s", getModId()); dummyHandler = new ModLoaderNetworkHandler(this); FMLNetworkHandler.instance().registerNetworkMod(dummyHandler); } Constructor<? extends BaseModProxy> ctor = modClazz.getConstructor(); ctor.setAccessible(true); mod = modClazz.newInstance(); if (dummyHandler != null) { dummyHandler.setBaseMod(mod); } ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), new ILanguageAdapter.JavaAdapter()); } catch (Exception e) { controller.errorOccurred(this, e); Throwables.propagateIfPossible(e); } }
public static boolean has(boolean checkForUpdates) { try { checkForDatabaseUpdates = checkForUpdates; File databaseDir = new File(DownloadHelper.getDir(), "database"); if (!databaseDir.exists()) { databaseDir.mkdir(); DownloadHelper.downloadFile("database/Pixelmon.db", databaseURL); DownloadHelper.downloadFile("database/sqlite-jdbc-3.7.2.jar", sqliteURL); } else { File databaseFile = new File(databaseDir, "Pixelmon.db"); if (!databaseFile.exists()) { DownloadHelper.downloadFile("database/Pixelmon.db", databaseURL); } else { if (checkForDatabaseUpdates) checkVersion(); } File sqlitejar = new File(databaseDir, "sqlite-jdbc-3.7.2.jar"); if (!sqlitejar.exists()) DownloadHelper.downloadFile("database/sqlite-jdbc-3.7.2.jar", sqliteURL); if (!sqlitejar.exists()) System.out.println("SQLite Jar still not found at " + sqlitejar.getAbsolutePath()); if (!databaseFile.exists()) System.out.println("Database still not found at " + databaseFile.getAbsolutePath()); ((ModClassLoader) Loader.instance().getModClassLoader()).addFile(sqlitejar); } Class.forName("org.sqlite.JDBC"); Connection c = DriverManager.getConnection("jdbc:sqlite:" + DownloadHelper.getDir() + "/database/Pixelmon.db"); if (c == null) { return false; } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public void findClasspathMods(ModClassLoader modClassLoader) { List<String> knownLibraries = ImmutableList.<String>builder() // skip default libs .addAll(modClassLoader.getDefaultLibraries()) // skip loaded coremods .addAll(CoreModManager.getLoadedCoremods()) // skip reparse coremods here .addAll(CoreModManager.getReparseableCoremods()) .build(); File[] minecraftSources = modClassLoader.getParentSources(); if (minecraftSources.length == 1 && minecraftSources[0].isFile()) { FMLLog.fine("Minecraft is a file at %s, loading", minecraftSources[0].getAbsolutePath()); candidates.add(new ModCandidate(minecraftSources[0], minecraftSources[0], ContainerType.JAR, true, true)); } else { for (int i = 0; i < minecraftSources.length; i++) { if (minecraftSources[i].isFile()) { if (knownLibraries.contains(minecraftSources[i].getName())) { FMLLog.finer("Skipping known library file %s", minecraftSources[i].getAbsolutePath()); } else { FMLLog.fine("Found a minecraft related file at %s, examining for mod candidates", minecraftSources[i].getAbsolutePath()); candidates.add(new ModCandidate(minecraftSources[i], minecraftSources[i], ContainerType.JAR, i==0, true)); } } else if (minecraftSources[i].isDirectory()) { FMLLog.fine("Found a minecraft related directory at %s, examining for mod candidates", minecraftSources[i].getAbsolutePath()); candidates.add(new ModCandidate(minecraftSources[i], minecraftSources[i], ContainerType.DIR, i==0, true)); } } } }
public ModClassLoader getModClassLoader() { return modClassLoader; }
public FMLConstructionEvent(Object... eventData) { this.modClassLoader = (ModClassLoader)eventData[0]; this.asmData = (ASMDataTable) eventData[1]; }
/** * Attempts to load the specified library (must be a proper java archive!) * @param file The file representing the library * @throws MalformedURLException */ public static void loadLibrary(File file) throws MalformedURLException { ((ModClassLoader) Loader.instance().getModClassLoader()).addFile(file); }