From b2d1af28cf06a0a2d3813f16e400694552e32dd4 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Mon, 13 Apr 2020 22:25:26 +0200 Subject: [PATCH] Added stats & debug info commands --- src/com/dre/brewery/BIngredients.java | 4 +- .../brewery/listeners/CommandListener.java | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index e8c9390d..6f132453 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -195,9 +195,9 @@ public int getIngredientsCount() { return count; } - /*public Map getIngredients() { + public List getIngredientList() { return ingredients; - }*/ + } public int getCookedTime() { return cookedTime; diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index eea3b3f4..93c89e48 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -4,11 +4,14 @@ import com.dre.brewery.api.events.brew.BrewModifyEvent; import com.dre.brewery.filedata.BConfig; import com.dre.brewery.recipe.BRecipe; +import com.dre.brewery.recipe.Ingredient; +import com.dre.brewery.recipe.RecipeItem; import com.dre.brewery.utility.BUtil; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -125,6 +128,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command p.msg(sender, p.languageReader.get("Error_NoPermissions")); } + } else if (cmd.equalsIgnoreCase("debuginfo")) { + + debugInfo(sender, args.length > 1 ? args[1] : null); + + } else if (cmd.equalsIgnoreCase("showstats")) { + + showStats(sender); + } else { if (p.getServer().getPlayerExact(cmd) != null || BPlayer.hasPlayerbyName(cmd)) { @@ -443,6 +454,70 @@ public void cmdDelete(CommandSender sender) { } + public void debugInfo(CommandSender sender, String recipeName) { + if (!P.use1_9 || !sender.isOp()) return; + if (!(sender instanceof Player)) { + p.msg(sender, p.languageReader.get("Error_PlayerCommand")); + return; + } + Player player = (Player) sender; + ItemStack hand = player.getInventory().getItemInMainHand(); + if (hand != null) { + Brew brew = Brew.get(hand); + if (brew == null) return; + P.p.log(brew.toString()); + BIngredients ingredients = brew.getIngredients(); + if (recipeName == null) { + P.p.log("&lIngredients:"); + for (Ingredient ing : ingredients.getIngredientList()) { + P.p.log(ing.toString()); + } + P.p.log("&lTesting Recipes"); + for (BRecipe recipe : BRecipe.getAllRecipes()) { + int ingQ = ingredients.getIngredientQuality(recipe); + int cookQ = ingredients.getCookingQuality(recipe, false); + int cookDistQ = ingredients.getCookingQuality(recipe, true); + P.p.log(recipe.getRecipeName() + ": ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ); + } + BRecipe distill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), true); + BRecipe nonDistill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), false); + P.p.log("&lWould prefer Recipe: " + (nonDistill == null ? "none" : nonDistill.getRecipeName()) + " and Distill-Recipe: " + (distill == null ? "none" : distill.getRecipeName())); + } else { + BRecipe recipe = BRecipe.get(recipeName); + if (recipe == null) { + P.p.msg(player, "Could not find Recipe " + recipeName); + return; + } + P.p.log("&lIngredients in Recipe " + recipe.getRecipeName() + ":"); + for (RecipeItem ri : recipe.getIngredients()) { + P.p.log(ri.toString()); + } + P.p.log("&lIngredients in Brew:"); + for (Ingredient ingredient : ingredients.getIngredientList()) { + int amountInRecipe = recipe.amountOf(ingredient); + P.p.log(ingredient.toString() + ": " + amountInRecipe + " of this are in the Recipe"); + } + int ingQ = ingredients.getIngredientQuality(recipe); + int cookQ = ingredients.getCookingQuality(recipe, false); + int cookDistQ = ingredients.getCookingQuality(recipe, true); + P.p.log("ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ); + } + + P.p.msg(player, "Debug Info for item written into Log"); + } + } + + public void showStats(CommandSender sender) { + if (sender instanceof ConsoleCommandSender && !sender.isOp()) return; + + P.p.msg(sender, "Drunk Players: " + BPlayer.numDrunkPlayers()); + P.p.msg(sender, "Brews created: " + P.p.brewsCreated); + P.p.msg(sender, "Barrels built: " + Barrel.barrels.size()); + P.p.msg(sender, "Cauldrons boiling: " + BCauldron.bcauldrons.size()); + P.p.msg(sender, "Number of Recipes: " + BRecipe.getAllRecipes().size()); + P.p.msg(sender, "Wakeups: " + Wakeup.wakeups.size()); + } + @SuppressWarnings("deprecation") public void cmdStatic(CommandSender sender) {