From c49c3ce4daf4399931e5089480194895ab22c89a Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Sun, 24 Jan 2016 20:45:37 +0000 Subject: [PATCH 1/2] Catch Throwables when dumping recipes. --- .../MineTweakerImplementationAPI.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java index 5ca27ba..fff1462 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java +++ b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java @@ -36,6 +36,8 @@ import minetweaker.api.player.IPlayer; import minetweaker.api.recipes.ICraftingRecipe; import minetweaker.api.recipes.IFurnaceManager; import minetweaker.api.recipes.IRecipeManager; +import minetweaker.api.recipes.ShapedRecipe; +import minetweaker.api.recipes.ShapelessRecipe; import minetweaker.api.server.ICommandFunction; import minetweaker.api.server.ICommandValidator; import minetweaker.api.server.IServer; @@ -204,7 +206,20 @@ public class MineTweakerImplementationAPI { MineTweakerAPI.logCommand("Recipes:"); for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) { - MineTweakerAPI.logCommand(recipe.toCommandString()); + try { + MineTweakerAPI.logCommand(recipe.toCommandString()); + } catch (Throwable ex) { + // Some recipes can result in an NPE :-( + if (recipe instanceof ShapedRecipe) { + ShapedRecipe shaped = (ShapedRecipe) recipe; + IItemStack out = shaped.getOutput(); + MineTweakerAPI.logError("Could not dump recipe for " + out, ex); + } else if (recipe instanceof ShapelessRecipe) { + ShapelessRecipe shapeless = (ShapelessRecipe) recipe; + IItemStack out = shapeless.getOutput(); + MineTweakerAPI.logError("Could not dump recipe for " + out, ex); + } + } } if (player != null) { From 06a849ad79dada47d83c3688d79262520f02dd97 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Mon, 25 Jan 2016 08:13:42 +0000 Subject: [PATCH 2/2] Add 'else' block to ensure all exceptions are logged. --- .../src/main/java/minetweaker/MineTweakerImplementationAPI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java index fff1462..8a67e3a 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java +++ b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java @@ -218,6 +218,8 @@ public class MineTweakerImplementationAPI { ShapelessRecipe shapeless = (ShapelessRecipe) recipe; IItemStack out = shapeless.getOutput(); MineTweakerAPI.logError("Could not dump recipe for " + out, ex); + } else { + MineTweakerAPI.logError("Could not dump recipe", ex) } } }