Beispiel #1
0
  private List<AppliedRegion> filtered() throws InvalidRegionException {
    List<AppliedRegion> filtered = new ArrayList<>();

    Element regions = document.getRootElement().element("regions");
    for (Element region : XMLUtil.getElements(regions, "apply")) {
      AppliedRegion applied = RegionBuilder.parseFiltered(this, region);
      filtered.add(applied);
      // Log.info("Found an AppliedRegion (" + (applied instanceof AppliedRegion) + ") current total
      // = " + filtered.size());
    }

    return filtered;
  }
  public DestroyableModule parseDestroyable(SporkMap map, Element element)
      throws ModuleBuildException {
    String name = XMLUtil.getElementOrParentValue(element, "name");

    String[] names = new String[0];
    String types = XMLUtil.getElementOrParentValue(element, "materials");
    if (types != null) {
      names = new String[] {types};
      if (types.contains(";")) {
        types.split(";");
      }
    }

    List<Material> materialList = new ArrayList<>();
    for (String type : names) {
      Material material = StringUtil.convertStringToMaterial(type);
      if (material == null) {
        throw new ModuleBuildException("'" + type + "' is not a valid Minecraft material");
      }
      materialList.add(material);
    }

    int i = 0;
    Material[] materials = new Material[materialList.size()];
    for (Material material : materialList) {
      materials[i] = material;
      i++;
    }

    int completion = 0;
    String complete = XMLUtil.getElementOrParentValue(element, "completion");
    if (complete != null) {
      if (complete.endsWith("%")) {
        complete = complete.substring(0, complete.length() - 1);
      }

      completion = Integer.parseInt(complete);
    }

    TeamModule other = null;
    String team = XMLUtil.getElementOrParentValue(element, "owner");
    if (team != null) {
      other = map.getTeams().getTeam(team);
    }

    Region region = RegionBuilder.parseRegion(element.getChildren().get(0));
    TeamModule owner = other.getOpposite();

    if (name == null) {
      throw new ModuleBuildException("A Destroyable name could not be found");
    } else if (materials.length == 0) {
      throw new ModuleBuildException("No Materials were supplied");
    } else if (materialList.contains(null)) {
      throw new ModuleBuildException("An invalid list of Materials was found");
    } else if (completion <= 0) {
      throw new ModuleBuildException("Completion % must be greater than 0");
    } else if (owner == null) {
      throw new ModuleBuildException("The owner of a Destroyable can't be null");
    } else if (region == null) {
      throw new ModuleBuildException("The region of a Destroyable can't be null");
    }

    return new DestroyableModule(name, owner, region, materials, completion);
  }