Search in sources :

Example 66 with JsonParseException

use of com.google.gson.JsonParseException in project Almura by AlmuraDev.

the class RecipeManager method load.

public void load() throws IOException {
    this.logger.debug("Loading recipes...");
    for (final Path source : this.sources) {
        final Iterator<Path> it = Files.walk(source).iterator();
        while (it.hasNext()) {
            final Path path = it.next();
            if ("json".equals(FilenameUtils.getExtension(path.toString()))) {
                final String id = FilenameUtils.removeExtension(source.relativize(path).toString()).replace("\\\\", "/");
                try (final BufferedReader br = Files.newBufferedReader(path)) {
                    try {
                        final Object recipe = parseRecipe(JsonUtils.fromJson(GSON, br, JsonObject.class));
                        if (recipe instanceof IRecipe) {
                            ((IRecipe) recipe).setRegistryName(new ResourceLocation("almura", id));
                            GameData.register_impl((IRecipe) recipe);
                        } else if (recipe instanceof FurnaceRecipe) {
                            ((FurnaceRecipe) recipe).register();
                        }
                    } catch (final JsonParseException e) {
                        this.logger.error("Encountered an exception parsing recipe '{}'", path.toAbsolutePath().toString(), e);
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) IRecipe(net.minecraft.item.crafting.IRecipe) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException)

Aggregations

JsonParseException (com.google.gson.JsonParseException)66 JsonObject (com.google.gson.JsonObject)24 IOException (java.io.IOException)17 JsonElement (com.google.gson.JsonElement)15 Gson (com.google.gson.Gson)14 GsonBuilder (com.google.gson.GsonBuilder)9 Type (java.lang.reflect.Type)9 JsonArray (com.google.gson.JsonArray)7 JsonParser (com.google.gson.JsonParser)6 SocketTimeoutException (java.net.SocketTimeoutException)5 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)4 UnknownHostException (java.net.UnknownHostException)4 ArrayList (java.util.ArrayList)4 Resources (android.content.res.Resources)3 TextView (android.widget.TextView)3 RutgersServerIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException)3 InputStreamReader (java.io.InputStreamReader)3 ParseException (java.text.ParseException)3 Date (java.util.Date)3 ResourceLocation (net.minecraft.util.ResourceLocation)3