diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index 7526e59..fb9b153 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -38,16 +38,6 @@ public class BIngredients { lastId++; } - //returns the recipe with the given name - public static BRecipe getRecipeByName(String name) { - for (BRecipe recipe : recipes) { - if (recipe.getName(5).equalsIgnoreCase(name)) { - return recipe; - } - } - return null; - } - // Add an ingredient to this public void add(Material ingredient) { if (ingredients.containsKey(ingredient)) { diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 98cbe9f..2953c21 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -22,8 +22,6 @@ public class Brew { public static Boolean colorInBarrels; // color the Lore while in Barrels public static Boolean colorInBrewer; // color the Lore while in Brewer - //public static Map> oldLore = new HashMap>(); - private BIngredients ingredients; private int quality; private int distillRuns; @@ -54,20 +52,7 @@ public class Brew { this.ageTime = ageTime; this.wood = wood; this.unlabeled = unlabeled; - if (recipe != null && !recipe.equals("")) { - currentRecipe = BIngredients.getRecipeByName(recipe); - if (currentRecipe == null) { - if (quality > 0) { - currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); - if (currentRecipe != null) { - this.quality = calcQuality(); - P.p.log("Brew was made from Recipe: '" + recipe + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); - } else { - P.p.errorLog("Brew was made from Recipe: '" + recipe + "' which could not be found!"); - } - } - } - } + setRecipeFromString(recipe); } // returns a Brew by its UID @@ -133,6 +118,37 @@ public class Brew { return uid; } + //returns the recipe with the given name, recalculates if not found + public boolean setRecipeFromString(String name) { + currentRecipe = null; + if (name != null && !name.equals("")) { + for (BRecipe recipe : BIngredients.recipes) { + if (recipe.getName(5).equalsIgnoreCase(name)) { + currentRecipe = recipe; + return true; + } + } + + if (quality > 0) { + currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); + if (currentRecipe != null) { + this.quality = calcQuality(); + P.p.log("Brew was made from Recipe: '" + name + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); + return true; + } else { + P.p.errorLog("Brew was made from Recipe: '" + name + "' which could not be found!"); + } + } + } + return false; + } + + public boolean reloadRecipe() { + if (currentRecipe != null) { + return setRecipeFromString(currentRecipe.getName(5)); + } + return true; + } // Copy a Brew with a new unique ID and return its item public ItemStack copy(ItemStack item) { diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 4b87e86..b0c8a15 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -97,7 +97,7 @@ public class P extends JavaPlugin { this.log(this.getDescription().getName() + " disabled!"); } - public void reload() { + public void reload(CommandSender sender) { BIngredients.possibleIngredients.clear(); BIngredients.recipes.clear(); BIngredients.cookedNames.clear(); @@ -105,6 +105,16 @@ public class P extends JavaPlugin { BPlayer.drainItems.clear(); readConfig(); + + Boolean successful = true; + for (Brew brew : Brew.potions.values()) { + if (!brew.reloadRecipe()) { + successful = false; + } + } + if (!successful) { + msg(sender, "&cEs konnten nicht alle Rezepte wiederhergesellt werden: Siehe Serverlog!"); + } } public void msg(CommandSender sender, String msg) { diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 1bc6d25..95b13e8 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -32,7 +32,7 @@ public class CommandListener implements CommandExecutor { } else if (cmd.equalsIgnoreCase("reload")) { if (p.permission.has(sender, "brewery.cmd.reload")) { - p.reload(); + p.reload(sender); p.msg(sender, "&aConfig wurde neu eingelesen"); } else { p.msg(sender, "&cDu hast keine Rechte dies zu tun!");