From eef4c19a47d3a2e40e0ead36707bdd4a2002731a Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 8 Jul 2015 13:56:27 +0200 Subject: [PATCH] Better error logging --- .../modtweaker2/helpers/ReflectionHelper.java | 10 +++++++++- .../thermalexpansion/handlers/Crucible.java | 8 +++++++- .../thermalexpansion/handlers/Furnace.java | 8 +++++++- .../thermalexpansion/handlers/Pulverizer.java | 8 +++++++- .../thermalexpansion/handlers/Sawmill.java | 8 +++++++- .../thermalexpansion/handlers/Smelter.java | 8 +++++++- .../thermalexpansion/handlers/Transposer.java | 18 +++++++++++++++--- 7 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main/java/modtweaker2/helpers/ReflectionHelper.java b/src/main/java/modtweaker2/helpers/ReflectionHelper.java index 2b258df..d2a0a0b 100644 --- a/src/main/java/modtweaker2/helpers/ReflectionHelper.java +++ b/src/main/java/modtweaker2/helpers/ReflectionHelper.java @@ -37,7 +37,7 @@ public class ReflectionHelper { Constructor constructor = clazz.getDeclaredConstructor(argumentTypes); constructor.setAccessible(true); return constructor; - } catch (Exception ex) { LogHelper.logError("Exception getting constructore of " + className, ex); } + } catch (Exception ex) { LogHelper.logError("Exception getting constructor of " + className, ex); } return null; } @@ -76,6 +76,8 @@ public class ReflectionHelper { } catch (Exception ex) {} } + LogHelper.logError("Could not retrieve any object for the provided field names."); + return null; } @@ -100,6 +102,8 @@ public class ReflectionHelper { } catch (Exception ex) {} } + LogHelper.logError("Could not retrieve any final object for the provided field names."); + return null; } @@ -118,6 +122,8 @@ public class ReflectionHelper { return (T) result.get(null); } catch (Exception e) {} } + + LogHelper.logError("Could not retrieve any static object for the provided field names."); return null; } @@ -134,6 +140,8 @@ public class ReflectionHelper { return getStaticObject(clazz, fieldNames); } catch (ClassNotFoundException e) { } + LogHelper.logError("Could not retrieve any static object for the provided field names."); + return null; } diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Crucible.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Crucible.java index ce494cf..3d0dbb0 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Crucible.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Crucible.java @@ -41,7 +41,13 @@ public class Crucible { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.crucibleRecipe, toStack(input), toFluid(output), energy))); + RecipeCrucible recipe = ReflectionHelper.getInstance(ThermalHelper.crucibleRecipe, toStack(input), toFluid(output), energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } } private static class Add extends BaseListAddition { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java index 253e9c2..ce85a93 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java @@ -41,7 +41,13 @@ public class Furnace { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.furanceRecipe, toStack(input), toStack(output), energy))); + RecipeFurnace recipe = ReflectionHelper.getInstance(ThermalHelper.furanceRecipe, toStack(input), toStack(output), energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } } private static class Add extends BaseListAddition { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Pulverizer.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Pulverizer.java index 8dfbba9..e12bfa0 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Pulverizer.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Pulverizer.java @@ -46,7 +46,13 @@ public class Pulverizer { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.pulverizerRecipe, toStack(input), toStack(output), toStack(secondary), secondaryChance, energy))); + RecipePulverizer recipe = ReflectionHelper.getInstance(ThermalHelper.pulverizerRecipe, toStack(input), toStack(output), toStack(secondary), secondaryChance, energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } } private static class Add extends BaseListAddition { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Sawmill.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Sawmill.java index efbcf14..52f1aea 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Sawmill.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Sawmill.java @@ -46,7 +46,13 @@ public class Sawmill { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.sawmillRecipe, toStack(input), toStack(output), toStack(secondary), secondaryChance, energy))); + RecipeSawmill recipe = ReflectionHelper.getInstance(ThermalHelper.sawmillRecipe, toStack(input), toStack(output), toStack(secondary), secondaryChance, energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } } private static class Add extends BaseListAddition { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Smelter.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Smelter.java index fab59a5..8771901 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Smelter.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Smelter.java @@ -46,7 +46,13 @@ public class Smelter { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.smelterRecipe, toStack(input), toStack(input2), toStack(output), toStack(output2), chance, energy))); + RecipeSmelter recipe = ReflectionHelper.getInstance(ThermalHelper.smelterRecipe, toStack(input), toStack(input2), toStack(output), toStack(output2), chance, energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } } private static class Add extends BaseListAddition { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Transposer.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Transposer.java index fd03ab7..6a571ec 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Transposer.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Transposer.java @@ -46,7 +46,13 @@ public class Transposer { return; } - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.transposerRecipe, toStack(input), toStack(output), toFluid(liquid), energy, 100), RecipeType.Fill)); + RecipeTransposer recipe = ReflectionHelper.getInstance(ThermalHelper.transposerRecipe, toStack(input), toStack(output), toFluid(liquid), energy, 100); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe, RecipeType.Fill)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", nameFill)); + } } @ZenMethod @@ -60,8 +66,14 @@ public class Transposer { LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s and %s. Command ignored!", Transposer.nameExtract, InputHelper.getStackDescription(toStack(input)), InputHelper.getStackDescription(toFluid(liquid)))); return; } - - MineTweakerAPI.apply(new Add(ReflectionHelper.getInstance(ThermalHelper.transposerRecipe, toStack(input), toStack(output), toFluid(liquid), energy, 100), RecipeType.Extract)); + + RecipeTransposer recipe = ReflectionHelper.getInstance(ThermalHelper.transposerRecipe, toStack(input), toStack(output), toFluid(liquid), energy, 100); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe, RecipeType.Extract)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", nameExtract)); + } } private static class Add extends BaseListAddition {