Skip to content

Commit

Permalink
Reduced complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 4, 2023
1 parent 398c8e9 commit 7e4f076
Showing 1 changed file with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class RecipeManager {
private static final int MAXIMUM_INVENTORY_SIZE = 49;
private final Greenhouses addon;
private static final List<BiomeRecipe> biomeRecipes = new ArrayList<>();
private static final String COULD_NOT_PARSE = "Could not parse ";

public RecipeManager(Greenhouses addon) {
this.addon = addon;
Expand Down Expand Up @@ -179,43 +180,52 @@ private void loadBlockConversions(ConfigurationSection biomeRecipeConfig, BiomeR
ConfigurationSection conversionSec = biomeRecipeConfig.getConfigurationSection("conversions");
if (conversionSec != null) {
for (String oldMat : conversionSec.getKeys(false)) {
try {
Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH));
String conversions = conversionSec.getString(oldMat);
if (!Objects.requireNonNull(conversions).isEmpty()) {
String[] split = conversions.split(":");
double convChance = Double.parseDouble(split[0]);
Material newMaterial = Material.valueOf(split[1]);
Material localMaterial = null;
if(split.length > 2) {
localMaterial = Material.valueOf(split[2]);
}
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
}
} catch (Exception e) {
addon.logError("Could not parse " + oldMat);
}

parseConversions(oldMat, conversionSec, b);
}
}
// Get the list of conversions
for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) {
try {
// Split the string
String[] split = oldMat.split(":");
Material oldMaterial = Material.valueOf(split[0].toUpperCase());
double convChance = Double.parseDouble(split[1]);
Material newMaterial = Material.valueOf(split[2]);
parseConversionList(oldMat, conversionSec, b);

}
}

private void parseConversionList(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) {
try {
// Split the string
String[] split = oldMat.split(":");
Material oldMaterial = Material.valueOf(split[0].toUpperCase());
double convChance = Double.parseDouble(split[1]);
Material newMaterial = Material.valueOf(split[2]);
Material localMaterial = null;
if(split.length > 3) {
localMaterial = Material.valueOf(split[3]);
}
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
} catch (Exception e) {
addon.logError(COULD_NOT_PARSE + oldMat);
}

}

private void parseConversions(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) {
try {
Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH));
String conversions = conversionSec.getString(oldMat);
if (!Objects.requireNonNull(conversions).isEmpty()) {
String[] split = conversions.split(":");
double convChance = Double.parseDouble(split[0]);
Material newMaterial = Material.valueOf(split[1]);
Material localMaterial = null;
if(split.length > 3) {
localMaterial = Material.valueOf(split[3]);
if(split.length > 2) {
localMaterial = Material.valueOf(split[2]);
}
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
} catch (Exception e) {
addon.logError("Could not parse " + oldMat);
}

} catch (Exception e) {
addon.logError(COULD_NOT_PARSE + oldMat);
}

}

private void loadMobs(ConfigurationSection biomeRecipeConfig, BiomeRecipe b) {
Expand All @@ -235,7 +245,7 @@ private void parseMob(Entry<String, Object> s, BiomeRecipe b) {
Material mobSpawnOn = Material.valueOf(split[1]);
b.addMobs(mobType, mobProbability, mobSpawnOn);
} catch (Exception e) {
addon.logError("Could not parse " + s.getKey());
addon.logError(COULD_NOT_PARSE + s.getKey());
}
}

Expand Down

0 comments on commit 7e4f076

Please sign in to comment.