mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-02-15 01:01:20 +01:00
Errorhandling for Recipeloading
This commit is contained in:
parent
07a9778c8b
commit
c691fea1ee
@ -124,7 +124,7 @@ recipes:
|
|||||||
distillruns: 0
|
distillruns: 0
|
||||||
wood: 2
|
wood: 2
|
||||||
age: 4
|
age: 4
|
||||||
COLOR: ORANGE
|
color: ORANGE
|
||||||
difficulty: 4
|
difficulty: 4
|
||||||
alcohol: 12
|
alcohol: 12
|
||||||
effects:
|
effects:
|
||||||
|
@ -21,18 +21,34 @@ public class BRecipe {
|
|||||||
private Map<String, Integer> effects = new HashMap<String, Integer>(); // Special Effect, Duration
|
private Map<String, Integer> effects = new HashMap<String, Integer>(); // Special Effect, Duration
|
||||||
|
|
||||||
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
|
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
|
||||||
String[] name = configSectionRecipes.getString(recipeId + ".name").split("/");
|
String nameList = configSectionRecipes.getString(recipeId + ".name");
|
||||||
if (name.length > 2) {
|
if (nameList != null) {
|
||||||
this.name = name;
|
String[] name = nameList.split("/");
|
||||||
|
if (name.length > 2) {
|
||||||
|
this.name = name;
|
||||||
|
} else {
|
||||||
|
this.name = new String[1];
|
||||||
|
this.name[0] = name[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.name = new String[1];
|
return;
|
||||||
this.name[0] = name[0];
|
|
||||||
}
|
}
|
||||||
List<String> ingredientsList = configSectionRecipes.getStringList(recipeId + ".ingredients");
|
List<String> ingredientsList = configSectionRecipes.getStringList(recipeId + ".ingredients");
|
||||||
for (String item : ingredientsList) {
|
if (ingredientsList != null) {
|
||||||
String[] ingredParts = item.split("/");
|
for (String item : ingredientsList) {
|
||||||
ingredParts[0] = ingredParts[0].toUpperCase();
|
String[] ingredParts = item.split("/");
|
||||||
this.ingredients.put(Material.getMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1]));
|
if (ingredParts.length == 2) {
|
||||||
|
Material mat = Material.matchMaterial(ingredParts[0]);
|
||||||
|
if (mat != null) {
|
||||||
|
this.ingredients.put(Material.matchMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1]));
|
||||||
|
} else {
|
||||||
|
P.p.errorLog("Unknown Material: " + ingredParts[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime");
|
this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime");
|
||||||
this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns");
|
this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns");
|
||||||
@ -129,6 +145,11 @@ public class BRecipe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// true if name and ingredients are correct
|
||||||
|
public boolean isValid() {
|
||||||
|
return (name != null && ingredients != null && !ingredients.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Getter
|
// Getter
|
||||||
|
|
||||||
@ -164,7 +185,10 @@ public class BRecipe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color.toUpperCase();
|
if (color != null) {
|
||||||
|
return color.toUpperCase();
|
||||||
|
}
|
||||||
|
return "BLUE";
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the woodtype
|
// get the woodtype
|
||||||
|
@ -161,7 +161,12 @@ public class P extends JavaPlugin {
|
|||||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||||
if (configSection != null) {
|
if (configSection != null) {
|
||||||
for (String recipeId : configSection.getKeys(false)) {
|
for (String recipeId : configSection.getKeys(false)) {
|
||||||
BIngredients.recipes.add(new BRecipe(configSection, recipeId));
|
BRecipe recipe = new BRecipe(configSection, recipeId);
|
||||||
|
if (recipe.isValid()) {
|
||||||
|
BIngredients.recipes.add(recipe);
|
||||||
|
} else {
|
||||||
|
errorLog("Recipe with id: '" + recipeId + "' failed to load!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user