Package org.spout.cereal.config

Examples of org.spout.cereal.config.ConfigurationNode


    try {
      config.load();
    } catch (ConfigurationException ex) {
      Spout.getLogger().warning("Unable to load recipes.yml: " + ex.getMessage());
    }
    ConfigurationNode recipesNode = config.getChild("recipes");
    for (String key : recipesNode.getKeys(false)) {
      ConfigurationNode recipe = recipesNode.getNode(key);
      RecipeBuilder builder = new RecipeBuilder();
      builder.setIncludeData(recipe.getNode("includedata") != null && recipe.getNode("includedata").getBoolean());
      String[] resultString = recipe.getNode("result").getString().split(",");
      Material matched = MaterialRegistry.get(resultString[0]);
      if (matched == null) {
        Spout.getLogger().log(Level.WARNING, "Unknown material result for {1}: {0}", new Object[] {resultString[0], key});
        continue;
      }
      int amount;
      try {
        amount = Integer.parseInt(resultString[1]);
      } catch (NumberFormatException numberFormatException) {
        Spout.getLogger().log(Level.WARNING, "Unknown number for {1}: {0}", new Object[] {resultString[1], key});
        amount = 1;
      } catch (IndexOutOfBoundsException ex) {
        Spout.getLogger().log(Level.WARNING, "Wrong number of parts for {1}: {0} should have a \",<amount>\" at the end of it.", new Object[] {recipe.getNode("result").getString(), key});
        amount = 1;
      }
      builder.setResult(matched, amount);
      if (recipe.getNode("type").getString().equalsIgnoreCase("Shaped")) {
        for (String inKey : recipe.getNode("ingredients").getKeys(false)) {
          Material ingredient = MaterialRegistry.get(recipe.getNode("ingredients").getNode(inKey).getString());
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {recipe.getNode("ingredients").getNode(inKey).getString(), key});
            continue;
          }
          builder.setIngredient(inKey.charAt(0), ingredient);
        }
        for (Iterator<String> it = recipe.getNode("rows").getStringList().iterator(); it.hasNext(); ) {
          String row = it.next();
          List<Character> rowChars = new ArrayList<Character>();
          for (char c : row.toCharArray()) {
            rowChars.add(c);
          }
          builder.addRow(rowChars);
        }
        try {
          recipes.put(key, builder.buildShapedRecipe());
        } catch (IllegalStateException ex) {
          Spout.getLogger().log(Level.WARNING, "Error when adding recipe {0} because: {1}", new Object[] {key, ex.getMessage()});
        }
      } else if (recipe.getNode("type").getString().equalsIgnoreCase("Shapeless")) {
        for (String rowString : recipe.getNode("ingredients").getStringList(new ArrayList<String>())) {
          Material ingredient = MaterialRegistry.get(rowString);
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {rowString, key});
            continue;
          }
          builder.addIngredient(ingredient);
        }
        try {
          recipes.put(key, builder.buildShapelessRecipe());
        } catch (IllegalStateException ex) {
          Spout.getLogger().log(Level.WARNING, "Error when adding recipe {0} because: {1}", new Object[] {key, ex.getMessage()});
        }
      } else if (recipe.getNode("type").getString().equalsIgnoreCase("Smelted")) {
        for (String rowString : recipe.getNode("ingredients").getStringList(new ArrayList<String>())) {
          Material ingredient = MaterialRegistry.get(rowString);
          if (ingredient == null) {
            Spout.getLogger().log(Level.WARNING, "Unknown material ingredient for {1}: {0}", new Object[] {recipe.getNode("ingredients").getNode(rowString).getString(), key});
            continue;
          }
          builder.addIngredient(ingredient);
        }
        try {
          recipes.put(key, builder.buildSmeltedRecipe());
        } catch (IllegalStateException ex) {
          Spout.getLogger().log(Level.WARNING, "Error when adding recipe {0} because: {1}", new Object[] {key, ex.getMessage()});
        }
      } else {
        Spout.getLogger().log(Level.INFO, "Unknown type " + recipe.getNode("type") + " when loading recipe from recipes.yml");
      }
    }
    recipes.remove(null);
    return new RecipeYaml(recipes);
  }
View Full Code Here


  }

  @Override
  public void save() throws ConfigurationException {
    super.save();
    ConfigurationNode node = this.getParent().getNode("worlds", this.getWorldName());
    for (Map.Entry<String, Object> entry : this.getValues().entrySet()) {
      node.getNode(entry.getKey()).setValue(entry.getValue());
    }
  }
View Full Code Here

    }

    public abstract String getTypeName();

    public void load(ConfigurationNode node) {
      final ConfigurationNode materials = node.getNode("materials");
      aboveSea = (BlockMaterial) MaterialRegistry.get(materials.getNode("above-sea").
          getString(aboveSea.getDisplayName()));
      bellowSea = (BlockMaterial) MaterialRegistry.get(materials.getNode("bellow-sea").
          getString(bellowSea.getDisplayName()));
    }
View Full Code Here

          getString(bellowSea.getDisplayName()));
    }

    public void save(ConfigurationNode node) {
      node.getNode("type").setValue(getTypeName());
      final ConfigurationNode materials = node.getNode("materials");
      materials.getNode("above-sea").setValue(aboveSea.getDisplayName());
      materials.getNode("bellow-sea").setValue(bellowSea.getDisplayName());
    }
View Full Code Here

    }

    @Override
    public void load(ConfigurationNode node) {
      super.load(node);
      final ConfigurationNode depthNode = node.getNode("depth");
      min = depthNode.getNode("min").getByte(min);
      max = depthNode.getNode("max").getByte(max);
    }
View Full Code Here

    }

    @Override
    public void save(ConfigurationNode node) {
      super.save(node);
      final ConfigurationNode depthNode = node.getNode("depth");
      depthNode.getNode("min").setValue(min);
      depthNode.getNode("max").setValue(max);
    }
View Full Code Here

    }
  }

  @Load
  private void load(ConfigurationNode node) {
    final ConfigurationNode groundCoverNode = node.getNode("ground-cover");
    final int count = groundCoverNode.getKeys(false).size();
    if (count == 0) {
      save(node);
      return;
    }
    groundCover = new GroundCoverLayer[count];
    for (int i = 0; i < count; i++) {
      groundCover[i] = GroundCoverLayer.loadNew(groundCoverNode.getNode(Integer.toString(i + 1)));
    }
  }
View Full Code Here

    }
  }

  @Save
  private void save(ConfigurationNode node) {
    final ConfigurationNode groundCoverNode = node.getNode("ground-cover");
    byte number = 0;
    for (GroundCoverLayer layer : groundCover) {
      layer.save(groundCoverNode.getNode(Byte.toString(++number)));
    }
  }
View Full Code Here

    return "Skylands";
  }

  @Load
  private void load(ConfigurationNode node) {
    final ConfigurationNode groundCoverNode = node.getNode("ground-cover");
    final int count = groundCoverNode.getKeys(false).size();
    if (count == 0) {
      save(node);
      return;
    }
    groundCover = new GroundCoverLayer[count];
    for (int i = 0; i < count; i++) {
      groundCover[i] = GroundCoverLayer.loadNew(groundCoverNode.getNode(Integer.toString(i + 1)));
    }
  }
View Full Code Here

    }
  }

  @Save
  private void save(ConfigurationNode node) {
    final ConfigurationNode groundCoverNode = node.getNode("ground-cover");
    byte number = 0;
    for (GroundCoverLayer layer : groundCover) {
      layer.save(groundCoverNode.getNode(Byte.toString(++number)));
    }
  }
View Full Code Here

TOP

Related Classes of org.spout.cereal.config.ConfigurationNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.