diff --git a/src/main/java/cr0s/warpdrive/config/XmlPreprocessor.java b/src/main/java/cr0s/warpdrive/config/XmlPreprocessor.java index 619f42d2..a51029af 100644 --- a/src/main/java/cr0s/warpdrive/config/XmlPreprocessor.java +++ b/src/main/java/cr0s/warpdrive/config/XmlPreprocessor.java @@ -1,5 +1,8 @@ package cr0s.warpdrive.config; +import java.util.Map.Entry; +import java.util.TreeMap; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -18,9 +21,9 @@ public class XmlPreprocessor { * @return A string, which is empty if all the mods are loaded. * @throws InvalidXmlException */ - public static String checkModRequirements(Element e) { + public static ModCheckResults checkModRequirements(Element e) { - String missingMods = ""; + ModCheckResults modErrors = new ModCheckResults(); for (String mod : e.getAttribute("mods").split(",")) { @@ -30,13 +33,17 @@ public class XmlPreprocessor { if (mod.isEmpty()) continue; - if (!Loader.isModLoaded(mod)) { - missingMods = missingMods + mod + ", "; - } + if (mod.startsWith("!")) { + + if (Loader.isModLoaded(mod.substring(1))) + modErrors.addMod(mod, "loaded"); + + } else if (!Loader.isModLoaded(mod)) + modErrors.addMod(mod, "not loaded"); } - return missingMods; + return modErrors; } /** @@ -54,11 +61,11 @@ public class XmlPreprocessor { if (child instanceof Element) { - String res = checkModRequirements((Element) child); + ModCheckResults res = checkModRequirements((Element) child); if (!res.isEmpty()) { base.removeChild(child); - WarpDrive.logger.info("Removed child element " + child.getBaseURI() + " of element " + base.getBaseURI() + " because these mods arent loaded: " + res); + WarpDrive.logger.info("Removed child element " + child.getBaseURI() + " of element " + base.getBaseURI() + ", results: " + res); } else { doModReqSanitation(child); @@ -70,4 +77,33 @@ public class XmlPreprocessor { } + public static class ModCheckResults { + + private TreeMap mods; + + public ModCheckResults() { + mods = new TreeMap(); + } + + public void addMod(String name, String error) { + mods.put(name, error); + } + + public boolean isEmpty() { + return mods.isEmpty(); + } + + @Override + public String toString() { + String s = "{"; + + for (Entry e : mods.entrySet()) + s = s + e.getKey() + ": " + e.getValue() + ", "; + + return s + "}"; + + } + + } + } diff --git a/src/main/java/cr0s/warpdrive/config/filler/FillerManager.java b/src/main/java/cr0s/warpdrive/config/filler/FillerManager.java index e643d52e..ded653bc 100644 --- a/src/main/java/cr0s/warpdrive/config/filler/FillerManager.java +++ b/src/main/java/cr0s/warpdrive/config/filler/FillerManager.java @@ -15,8 +15,9 @@ import org.xml.sax.SAXException; import scala.actors.threadpool.Arrays; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.InvalidXmlException; -import cr0s.warpdrive.config.XmlPreprocessor; import cr0s.warpdrive.config.WarpDriveConfig; +import cr0s.warpdrive.config.XmlPreprocessor; +import cr0s.warpdrive.config.XmlPreprocessor.ModCheckResults; public class FillerManager { @@ -69,10 +70,10 @@ public class FillerManager { Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(file); - String res = XmlPreprocessor.checkModRequirements(base.getDocumentElement()); + ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement()); if (!res.isEmpty()) { - WarpDrive.logger.info("Skippping filler data file " + file.getPath() + " because the mods " + res + " are not loaded"); + WarpDrive.logger.info("Skippping filler data file " + file.getPath() + " because of: " + res); return; } diff --git a/src/main/java/cr0s/warpdrive/config/structures/StructureManager.java b/src/main/java/cr0s/warpdrive/config/structures/StructureManager.java index 672e73b8..ea9ca56d 100644 --- a/src/main/java/cr0s/warpdrive/config/structures/StructureManager.java +++ b/src/main/java/cr0s/warpdrive/config/structures/StructureManager.java @@ -13,8 +13,9 @@ import org.xml.sax.SAXException; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.InvalidXmlException; -import cr0s.warpdrive.config.XmlPreprocessor; import cr0s.warpdrive.config.WarpDriveConfig; +import cr0s.warpdrive.config.XmlPreprocessor; +import cr0s.warpdrive.config.XmlPreprocessor.ModCheckResults; public class StructureManager { @@ -61,10 +62,10 @@ public class StructureManager { private static void loadXmlStructureFile(File f) throws SAXException, IOException, InvalidXmlException { Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f); - String res = XmlPreprocessor.checkModRequirements(base.getDocumentElement()); + ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement()); if (!res.isEmpty()) { - WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because the mods " + res + " are not loaded"); + WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because of: " + res); return; }