Search in sources :

Example 1 with NotAProperConfigException

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());
    }
}
Also used : MissingVersionException(com.mcmoddev.orespawn.api.exceptions.MissingVersionException) UnknownFieldException(com.mcmoddev.orespawn.api.exceptions.UnknownFieldException) BadValueException(com.mcmoddev.orespawn.api.exceptions.BadValueException) CrashReport(net.minecraft.crash.CrashReport) JsonObject(com.google.gson.JsonObject) NotAProperConfigException(com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) UnknownNameException(com.mcmoddev.orespawn.api.exceptions.UnknownNameException) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonIOException(com.google.gson.JsonIOException) JsonElement(com.google.gson.JsonElement) BufferedReader(java.io.BufferedReader) OldVersionException(com.mcmoddev.orespawn.api.exceptions.OldVersionException) UnknownVersionException(com.mcmoddev.orespawn.api.exceptions.UnknownVersionException) JsonParser(com.google.gson.JsonParser)

Example 2 with NotAProperConfigException

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());
    }
}
Also used : Path(java.nio.file.Path) MissingVersionException(com.mcmoddev.orespawn.api.exceptions.MissingVersionException) CrashReport(net.minecraft.crash.CrashReport) IOException(java.io.IOException) NotAProperConfigException(com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException) PathMatcher(java.nio.file.PathMatcher) OldVersionException(com.mcmoddev.orespawn.api.exceptions.OldVersionException) UnknownVersionException(com.mcmoddev.orespawn.api.exceptions.UnknownVersionException)

Aggregations

MissingVersionException (com.mcmoddev.orespawn.api.exceptions.MissingVersionException)2 NotAProperConfigException (com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException)2 OldVersionException (com.mcmoddev.orespawn.api.exceptions.OldVersionException)2 UnknownVersionException (com.mcmoddev.orespawn.api.exceptions.UnknownVersionException)2 IOException (java.io.IOException)2 CrashReport (net.minecraft.crash.CrashReport)2 JsonElement (com.google.gson.JsonElement)1 JsonIOException (com.google.gson.JsonIOException)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BadValueException (com.mcmoddev.orespawn.api.exceptions.BadValueException)1 UnknownFieldException (com.mcmoddev.orespawn.api.exceptions.UnknownFieldException)1 UnknownNameException (com.mcmoddev.orespawn.api.exceptions.UnknownNameException)1 BufferedReader (java.io.BufferedReader)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1