Reduced complexity
This commit is contained in:
parent
398c8e91d5
commit
7e4f0764e6
|
@ -30,6 +30,7 @@ public class RecipeManager {
|
||||||
private static final int MAXIMUM_INVENTORY_SIZE = 49;
|
private static final int MAXIMUM_INVENTORY_SIZE = 49;
|
||||||
private final Greenhouses addon;
|
private final Greenhouses addon;
|
||||||
private static final List<BiomeRecipe> biomeRecipes = new ArrayList<>();
|
private static final List<BiomeRecipe> biomeRecipes = new ArrayList<>();
|
||||||
|
private static final String COULD_NOT_PARSE = "Could not parse ";
|
||||||
|
|
||||||
public RecipeManager(Greenhouses addon) {
|
public RecipeManager(Greenhouses addon) {
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
|
@ -179,45 +180,54 @@ public class RecipeManager {
|
||||||
ConfigurationSection conversionSec = biomeRecipeConfig.getConfigurationSection("conversions");
|
ConfigurationSection conversionSec = biomeRecipeConfig.getConfigurationSection("conversions");
|
||||||
if (conversionSec != null) {
|
if (conversionSec != null) {
|
||||||
for (String oldMat : conversionSec.getKeys(false)) {
|
for (String oldMat : conversionSec.getKeys(false)) {
|
||||||
try {
|
parseConversions(oldMat, conversionSec, b);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get the list of conversions
|
// Get the list of conversions
|
||||||
for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) {
|
for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) {
|
||||||
try {
|
parseConversionList(oldMat, conversionSec, b);
|
||||||
// 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 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 > 2) {
|
||||||
|
localMaterial = Material.valueOf(split[2]);
|
||||||
|
}
|
||||||
|
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
addon.logError(COULD_NOT_PARSE + oldMat);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void loadMobs(ConfigurationSection biomeRecipeConfig, BiomeRecipe b) {
|
private void loadMobs(ConfigurationSection biomeRecipeConfig, BiomeRecipe b) {
|
||||||
ConfigurationSection temp = biomeRecipeConfig.getConfigurationSection("mobs");
|
ConfigurationSection temp = biomeRecipeConfig.getConfigurationSection("mobs");
|
||||||
// Mob EntityType: Probability:Spawn on Material
|
// Mob EntityType: Probability:Spawn on Material
|
||||||
|
@ -235,7 +245,7 @@ public class RecipeManager {
|
||||||
Material mobSpawnOn = Material.valueOf(split[1]);
|
Material mobSpawnOn = Material.valueOf(split[1]);
|
||||||
b.addMobs(mobType, mobProbability, mobSpawnOn);
|
b.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
addon.logError("Could not parse " + s.getKey());
|
addon.logError(COULD_NOT_PARSE + s.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue