use of com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException in project OreSpawn by MinecraftModDevelopmentMods.
the class OreSpawnReader method tryReadFile.
public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException {
JsonParser parser = new JsonParser();
try (BufferedReader data = Files.newBufferedReader(conf)) {
JsonElement json = parser.parse(data);
if (!json.isJsonObject()) {
throw new NotAProperConfigException();
}
JsonObject root = json.getAsJsonObject();
if (!root.has(Constants.ConfigNames.FILE_VERSION)) {
throw new MissingVersionException();
}
float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat();
if (version < 2f) {
throw new OldVersionException();
} else if (version != 2f) {
throw new UnknownVersionException();
}
if (!root.has(Constants.ConfigNames.SPAWNS)) {
throw new NotAProperConfigException();
}
JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS).getAsJsonObject();
spawnData.entrySet().stream().forEach(e -> {
try {
OreSpawn.API.mapEntryToFile(conf, e.getKey());
loadSingleEntry(e);
} catch (UnknownFieldException | BadValueException | UnknownNameException e1) {
CrashReport report = CrashReport.makeCrashReport(e1, "Error parsing an entry " + e.getKey() + " in " + conf.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
});
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config data " + conf.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
} catch (JsonIOException | JsonSyntaxException e) {
CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + conf.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
}
use of com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException in project OreSpawn by MinecraftModDevelopmentMods.
the class OS3APIImpl method loadConfigFiles.
public void loadConfigFiles() {
PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:**/features-*.json");
PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:**/replacements-*.json");
PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json");
try (Stream<Path> stream = Files.walk(Constants.SYSCONF, 1)) {
stream.filter(featuresFiles::matches).map(Path::toFile).forEach(features::loadFeaturesFile);
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
// have to do this twice or we have issues
try (Stream<Path> stream = Files.walk(Constants.SYSCONF, 1)) {
stream.filter(replacementsFiles::matches).forEach(replacements::loadFile);
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) {
presets.load(Constants.SYSCONF.resolve("presets-default.json"));
}
try (Stream<Path> stream = Files.walk(Constants.CONFDIR, 1)) {
stream.filter(jsonMatcher::matches).forEach(conf -> {
try {
OreSpawnReader.tryReadFile(conf, this);
} catch (MissingVersionException | NotAProperConfigException | OldVersionException | UnknownVersionException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + conf.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
});
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.CONFDIR.toString());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
}
}
Aggregations