Search in sources :

Example 1 with MissingVersionException

use of com.mcmoddev.orespawn.api.exceptions.MissingVersionException in project OreSpawn by MinecraftModDevelopmentMods.

the class OreSpawnReader method tryReadFile.

public static void tryReadFile(final Path conf) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException {
    final JsonParser parser = new JsonParser();
    try (BufferedReader data = Files.newBufferedReader(conf)) {
        final JsonElement json = parser.parse(data);
        if (!json.isJsonObject()) {
            throw new NotAProperConfigException();
        }
        final JsonObject root = json.getAsJsonObject();
        if (!root.has(Constants.ConfigNames.FILE_VERSION)) {
            throw new MissingVersionException();
        }
        final 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();
        }
        final 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 (final 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 (final 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 MissingVersionException

use of com.mcmoddev.orespawn.api.exceptions.MissingVersionException 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 3 with MissingVersionException

use of com.mcmoddev.orespawn.api.exceptions.MissingVersionException in project OreSpawn by MinecraftModDevelopmentMods.

the class OS3APIImpl method loadConfigFiles.

public void loadConfigFiles() {
    final String failedReadingConfigsFrom = "Failed reading configs from ";
    PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:**/features-*.json");
    PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:**/replacements-*.json");
    PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json");
    try (final Stream<Path> stream = Files.walk(Constants.SYSCONF, 1)) {
        stream.filter(featuresFiles::matches).map(Path::toFile).forEach(features::loadFeaturesFile);
    } catch (final IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + 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 (final Stream<Path> stream = Files.walk(Constants.SYSCONF, 1)) {
        stream.filter(replacementsFiles::matches).forEach(replacements::loadFile);
    } catch (final IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + 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 (final Stream<Path> stream = Files.walk(Constants.CONFDIR, 1)) {
        stream.filter(jsonMatcher::matches).forEach(conf -> {
            try {
                OreSpawnReader.tryReadFile(conf);
            } catch (final 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 (final IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + 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)3 NotAProperConfigException (com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException)3 OldVersionException (com.mcmoddev.orespawn.api.exceptions.OldVersionException)3 UnknownVersionException (com.mcmoddev.orespawn.api.exceptions.UnknownVersionException)3 IOException (java.io.IOException)3 CrashReport (net.minecraft.crash.CrashReport)3 JsonElement (com.google.gson.JsonElement)2 JsonIOException (com.google.gson.JsonIOException)2 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 BadValueException (com.mcmoddev.orespawn.api.exceptions.BadValueException)2 UnknownFieldException (com.mcmoddev.orespawn.api.exceptions.UnknownFieldException)2 UnknownNameException (com.mcmoddev.orespawn.api.exceptions.UnknownNameException)2 BufferedReader (java.io.BufferedReader)2 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1