More logging
This commit is contained in:
parent
f37c8ae4d7
commit
44779a56b1
|
@ -69,6 +69,8 @@ public class Loader {
|
|||
try {
|
||||
fileHandler = new FileHandler("ForgeModLoader-%g.log", 0, 3);
|
||||
fileHandler.setLevel(Level.ALL);
|
||||
// We're stealing minecraft's log formatter
|
||||
fileHandler.setFormatter(FMLHandler.getMinecraftLogger().getHandlers()[0].getFormatter());
|
||||
Loader.log.addHandler(fileHandler);
|
||||
} catch (Exception e) {
|
||||
// Whatever - give up
|
||||
|
@ -82,31 +84,37 @@ public class Loader {
|
|||
|
||||
private void preModInit() {
|
||||
state = State.PREINIT;
|
||||
log.fine("Beginning mod pre-initialization.");
|
||||
for (ModContainer mod : mods) {
|
||||
if (mod.wantsPreInit()) {
|
||||
log.finer(String.format("Pre-initializing %s", mod.getName()));
|
||||
log.finer(String.format("Pre-initializing %s.", mod.getSource()));
|
||||
mod.preInit();
|
||||
namedMods.put(mod.getName(), mod);
|
||||
}
|
||||
}
|
||||
log.fine("Mod pre-initialization complete.");
|
||||
}
|
||||
|
||||
private void modInit() {
|
||||
state = State.INIT;
|
||||
log.fine("Beginning mod initialization.");
|
||||
for (ModContainer mod : mods) {
|
||||
log.finer(String.format("Initializing %s", mod.getName()));
|
||||
log.finer(String.format("Initializing %s.", mod.getName()));
|
||||
mod.init();
|
||||
}
|
||||
log.fine("Mod initialization complete.");
|
||||
}
|
||||
|
||||
private void postModInit() {
|
||||
state = State.POSTINIT;
|
||||
log.fine("Beginning mod post-initialization.");
|
||||
for (ModContainer mod : mods) {
|
||||
if (mod.wantsPostInit()) {
|
||||
log.finer(String.format("Post-initializing %s", mod.getName()));
|
||||
log.finer(String.format("Post-initializing %s.", mod.getName()));
|
||||
mod.postInit();
|
||||
}
|
||||
}
|
||||
log.fine("Mod post-initialization complete.");
|
||||
}
|
||||
|
||||
private void load() {
|
||||
|
@ -115,12 +123,12 @@ public class Loader {
|
|||
try {
|
||||
canonicalModsPath = modsDir.getCanonicalPath();
|
||||
} catch (IOException ioe) {
|
||||
log.severe(String.format("Failed to resolve mods directory mods %s", modsDir.getAbsolutePath()));
|
||||
log.severe(String.format("Failed to resolve mods directory mods %s.", modsDir.getAbsolutePath()));
|
||||
log.throwing("fml.server.Loader", "initialize", ioe);
|
||||
throw new LoaderException(ioe);
|
||||
}
|
||||
if (!modsDir.exists()) {
|
||||
log.fine(String.format("No mod directory found, creating one: %s", canonicalModsPath));
|
||||
log.fine(String.format("No mod directory found, creating one: %s.", canonicalModsPath));
|
||||
try {
|
||||
modsDir.mkdir();
|
||||
} catch (Exception e) {
|
||||
|
@ -129,11 +137,12 @@ public class Loader {
|
|||
}
|
||||
}
|
||||
if (!modsDir.isDirectory()) {
|
||||
log.severe(String.format("Attempting to load mods from %s, which is not a directory", canonicalModsPath));
|
||||
log.severe(String.format("Attempting to load mods from %s, which is not a directory.", canonicalModsPath));
|
||||
LoaderException loaderException = new LoaderException();
|
||||
log.throwing("fml.server.Loader", "initialize", loaderException);
|
||||
throw loaderException;
|
||||
}
|
||||
log.info(String.format("Loading mods from %s.",canonicalModsPath));
|
||||
File[] modList = modsDir.listFiles();
|
||||
// Sort the files into alphabetical order first
|
||||
Arrays.sort(modList);
|
||||
|
@ -141,27 +150,37 @@ public class Loader {
|
|||
state = State.LOADING;
|
||||
for (File modFile : modList) {
|
||||
if (modFile.isDirectory()) {
|
||||
log.info(String.format("Found directory %s. Attempting load", modFile.getName()));
|
||||
attemptDirLoad(modFile);
|
||||
log.info(String.format("Directory %s loaded successfully", modFile.getName()));
|
||||
log.info(String.format("Found directory %s. Attempting load.", modFile.getName()));
|
||||
boolean modFound=attemptDirLoad(modFile);
|
||||
if (modFound) {
|
||||
log.info(String.format("Directory %s loaded successfully.", modFile.getName()));
|
||||
} else {
|
||||
log.info(String.format("Directory %s contained no mods.", modFile.getName()));
|
||||
}
|
||||
} else {
|
||||
Matcher matcher = zipJar.matcher(modFile.getName());
|
||||
if (matcher.matches()) {
|
||||
log.info(String.format("Found zip or jar file %s. Attempting load.", matcher.group(0)));
|
||||
attemptFileLoad(modFile);
|
||||
boolean modFound=attemptFileLoad(modFile);
|
||||
if (modFound) {
|
||||
log.info(String.format("File %s loaded successfully.", matcher.group(0)));
|
||||
} else {
|
||||
log.info(String.format("File %s contained no mods.", matcher.group(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state == State.ERRORED) {
|
||||
log.severe("A problem has occured during mod loading. Giving up now");
|
||||
log.severe("A problem has occured during mod loading. Giving up now.");
|
||||
throw new RuntimeException("Giving up please");
|
||||
}
|
||||
log.fine(String.format("Forge Mod Loader has loaded %d mods.",mods.size()));
|
||||
}
|
||||
|
||||
private void attemptDirLoad(File modDir) {
|
||||
private boolean attemptDirLoad(File modDir) {
|
||||
extendClassLoader(modDir);
|
||||
|
||||
boolean foundAModClass=false;
|
||||
File[] content = modDir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
|
@ -173,7 +192,10 @@ public class Loader {
|
|||
log.fine(String.format("Found a mod class %s in directory %s. Attempting to load it", clazzName, modDir.getName()));
|
||||
loadModClass(modDir, modClassFile.getName(), clazzName);
|
||||
log.fine(String.format("Successfully loaded mod class %s", modClassFile.getName()));
|
||||
foundAModClass=true;
|
||||
}
|
||||
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
private void loadModClass(File classSource, String classFileName, String clazzName) {
|
||||
|
@ -188,7 +210,7 @@ public class Loader {
|
|||
log.fine(String.format("ModLoader BaseMod class found: %s. Loading", clazzName));
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends BaseMod> bmClazz = (Class<? extends BaseMod>) clazz;
|
||||
ModContainer mc=new ModLoaderModContainer(bmClazz);
|
||||
ModContainer mc=new ModLoaderModContainer(bmClazz,classSource.getCanonicalPath());
|
||||
mods.add(mc);
|
||||
log.fine(String.format("ModLoader BaseMod class loaded: %s.", clazzName));
|
||||
} else {
|
||||
|
@ -212,9 +234,10 @@ public class Loader {
|
|||
}
|
||||
}
|
||||
|
||||
private void attemptFileLoad(File modFile) {
|
||||
private boolean attemptFileLoad(File modFile) {
|
||||
extendClassLoader(modFile);
|
||||
|
||||
boolean foundAModClass=false;
|
||||
try {
|
||||
ZipFile jar = new ZipFile(modFile);
|
||||
for (ZipEntry ze : Collections.list(jar.entries())) {
|
||||
|
@ -225,6 +248,7 @@ public class Loader {
|
|||
log.fine(String.format("Found a mod class %s in file %s. Attempting to load it", clazzName, modFile.getName()));
|
||||
loadModClass(modFile, ze.getName(), clazzName);
|
||||
log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName()));
|
||||
foundAModClass=true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -232,6 +256,7 @@ public class Loader {
|
|||
log.throwing("fml.server.Loader", "attemptFileLoad", e);
|
||||
state = State.ERRORED;
|
||||
}
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
public static List<ModContainer> getModList() {
|
||||
|
@ -252,8 +277,9 @@ public class Loader {
|
|||
modInit();
|
||||
postModInit();
|
||||
state = State.UP;
|
||||
log.info("Forge Mod Loader load complete");
|
||||
log.info(String.format("Forge Mod Loader load complete. %d mods loaded.",mods.size()));
|
||||
}
|
||||
|
||||
public static boolean isModLoaded(String modname) {
|
||||
return instance().namedMods.containsKey(modname);
|
||||
}
|
||||
|
|
|
@ -23,4 +23,5 @@ public interface ModContainer {
|
|||
void tickStart();
|
||||
void tickEnd();
|
||||
boolean matches(Object mod);
|
||||
String getSource();
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@ public class ModLoaderModContainer implements ModContainer {
|
|||
private Class<? extends BaseMod> modClazz;
|
||||
private BaseMod mod;
|
||||
private boolean isTicking;
|
||||
public ModLoaderModContainer(Class<? extends BaseMod> modClazz) {
|
||||
private String modSource ;
|
||||
public ModLoaderModContainer(Class<? extends BaseMod> modClazz, String modSource) {
|
||||
this.modClazz=modClazz;
|
||||
this.modSource =modSource;
|
||||
}
|
||||
|
||||
public boolean wantsPreInit() {
|
||||
|
@ -100,4 +102,9 @@ public class ModLoaderModContainer implements ModContainer {
|
|||
}
|
||||
return modList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return modSource;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue