Added stats & debug info commands

This commit is contained in:
Sn0wStorm 2020-04-13 22:25:26 +02:00
parent 786a3c5741
commit b2d1af28cf
2 changed files with 77 additions and 2 deletions

View File

@ -195,9 +195,9 @@ public class BIngredients {
return count;
}
/*public Map<Material, Integer> getIngredients() {
public List<Ingredient> getIngredientList() {
return ingredients;
}*/
}
public int getCookedTime() {
return cookedTime;

View File

@ -4,11 +4,14 @@ import com.dre.brewery.*;
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 class CommandListener implements CommandExecutor {
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 class CommandListener implements CommandExecutor {
}
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) {