From bf70fe8d25a7fe5750c1d71275f44ad0ef4de0bd Mon Sep 17 00:00:00 2001 From: Francesco Macagno Date: Sun, 23 Aug 2015 14:38:29 -0700 Subject: [PATCH] Changed type to group --- .../conf/structures/StructureManager.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/conf/structures/StructureManager.java b/src/main/java/cr0s/warpdrive/conf/structures/StructureManager.java index bbe9b8ef..f5cb499c 100644 --- a/src/main/java/cr0s/warpdrive/conf/structures/StructureManager.java +++ b/src/main/java/cr0s/warpdrive/conf/structures/StructureManager.java @@ -18,87 +18,87 @@ import cr0s.warpdrive.conf.WarpDriveConfig; public class StructureManager { - + private static ArrayList stars = new ArrayList(); private static ArrayList moons = new ArrayList(); private static ArrayList gasClouds = new ArrayList(); - + public static void loadStructures(String structureConfDir) { loadStructures(new File(structureConfDir)); } - + public static void loadStructures(File dir) { - + dir.mkdir(); - + if (!dir.isDirectory()) { throw new IllegalArgumentException("File path " + dir.getPath() + " must be a directory!"); } - + File[] files = dir.listFiles(new FilenameFilter() { @Override public boolean accept(File file_notUsed, String name) { return name.startsWith("structure") && name.endsWith(".xml"); } }); - + for (File file : files) { try { - + WarpDrive.logger.info("Loading structure data file " + file.getPath()); - + loadXmlStructureFile(file); - + WarpDrive.logger.info("Finished loading structure data file " + file.getPath()); - + } catch (Exception e) { WarpDrive.logger.error("Error loading file " + file.getPath() + ": " + e.getMessage()); e.printStackTrace(); } } } - + private static void loadXmlStructureFile(File f) throws SAXException, IOException, InvalidXmlException { Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f); - - String res = ModRequirementChecker.checkModRequirements(base.getDocumentElement()); + String res = ModRequirementChecker.checkModRequirements(base.getDocumentElement()); + if (!res.isEmpty()) { WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because the mods " + res + " are not loaded"); return; } - + ModRequirementChecker.doModReqSanitation(base); - + NodeList structures = base.getElementsByTagName("structure"); for (int i = 0; i < structures.getLength(); i++) { - + Element struct = (Element) structures.item(i); - - String type = struct.getAttribute("type"); + + String group = struct.getAttribute("group"); String name = struct.getAttribute("name"); - - if(type.isEmpty()) - throw new InvalidXmlException("Structure must have a type!"); - + + if (group.isEmpty()) + throw new InvalidXmlException("Structure must have a group!"); + int radius; try { radius = Integer.parseInt(struct.getAttribute("radius")); } catch(NumberFormatException e) { throw new InvalidXmlException("Structure radius is invalid!"); } - - if (type.equalsIgnoreCase("star")) { + + if (group.equalsIgnoreCase("star")) { Star s = new Star(radius); s.loadFromXmlElement(struct); stars.add(s); - } else if(type.equalsIgnoreCase("moon")) { + } else if (group.equalsIgnoreCase("moon")) { Planetoid pl = new Planetoid(radius); pl.loadFromXmlElement(struct); } } } - + public static DeployableStructure getStructure(Random random, final String name, final String type) { if (name == null || name.length() == 0) { if (type == null || type.length() == 0) { @@ -114,19 +114,19 @@ public class StructureManager { return star; } } - + // not found or nothing defined => return null return null; } - + public static DeployableStructure getStar(Random random, final String name) { return getStructure(random, name, "star"); } - + public static DeployableStructure getMoon(Random random, final String name) { return getStructure(random, name, "moon"); } - + public static DeployableStructure getGasCloud(Random random, final String name) { return getStructure(random, name, "cloud"); }