Skip to content

Commit b2d1af2

Browse files
committed
Added stats & debug info commands
1 parent 786a3c5 commit b2d1af2

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

src/com/dre/brewery/BIngredients.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ public int getIngredientsCount() {
195195
return count;
196196
}
197197

198-
/*public Map<Material, Integer> getIngredients() {
198+
public List<Ingredient> getIngredientList() {
199199
return ingredients;
200-
}*/
200+
}
201201

202202
public int getCookedTime() {
203203
return cookedTime;

src/com/dre/brewery/listeners/CommandListener.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import com.dre.brewery.api.events.brew.BrewModifyEvent;
55
import com.dre.brewery.filedata.BConfig;
66
import com.dre.brewery.recipe.BRecipe;
7+
import com.dre.brewery.recipe.Ingredient;
8+
import com.dre.brewery.recipe.RecipeItem;
79
import com.dre.brewery.utility.BUtil;
810
import org.bukkit.Material;
911
import org.bukkit.command.Command;
1012
import org.bukkit.command.CommandExecutor;
1113
import org.bukkit.command.CommandSender;
14+
import org.bukkit.command.ConsoleCommandSender;
1215
import org.bukkit.entity.Player;
1316
import org.bukkit.inventory.ItemStack;
1417
import org.bukkit.inventory.meta.ItemMeta;
@@ -125,6 +128,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
125128
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
126129
}
127130

131+
} else if (cmd.equalsIgnoreCase("debuginfo")) {
132+
133+
debugInfo(sender, args.length > 1 ? args[1] : null);
134+
135+
} else if (cmd.equalsIgnoreCase("showstats")) {
136+
137+
showStats(sender);
138+
128139
} else {
129140

130141
if (p.getServer().getPlayerExact(cmd) != null || BPlayer.hasPlayerbyName(cmd)) {
@@ -443,6 +454,70 @@ public void cmdDelete(CommandSender sender) {
443454

444455
}
445456

457+
public void debugInfo(CommandSender sender, String recipeName) {
458+
if (!P.use1_9 || !sender.isOp()) return;
459+
if (!(sender instanceof Player)) {
460+
p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
461+
return;
462+
}
463+
Player player = (Player) sender;
464+
ItemStack hand = player.getInventory().getItemInMainHand();
465+
if (hand != null) {
466+
Brew brew = Brew.get(hand);
467+
if (brew == null) return;
468+
P.p.log(brew.toString());
469+
BIngredients ingredients = brew.getIngredients();
470+
if (recipeName == null) {
471+
P.p.log("&lIngredients:");
472+
for (Ingredient ing : ingredients.getIngredientList()) {
473+
P.p.log(ing.toString());
474+
}
475+
P.p.log("&lTesting Recipes");
476+
for (BRecipe recipe : BRecipe.getAllRecipes()) {
477+
int ingQ = ingredients.getIngredientQuality(recipe);
478+
int cookQ = ingredients.getCookingQuality(recipe, false);
479+
int cookDistQ = ingredients.getCookingQuality(recipe, true);
480+
P.p.log(recipe.getRecipeName() + ": ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ);
481+
}
482+
BRecipe distill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), true);
483+
BRecipe nonDistill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), false);
484+
P.p.log("&lWould prefer Recipe: " + (nonDistill == null ? "none" : nonDistill.getRecipeName()) + " and Distill-Recipe: " + (distill == null ? "none" : distill.getRecipeName()));
485+
} else {
486+
BRecipe recipe = BRecipe.get(recipeName);
487+
if (recipe == null) {
488+
P.p.msg(player, "Could not find Recipe " + recipeName);
489+
return;
490+
}
491+
P.p.log("&lIngredients in Recipe " + recipe.getRecipeName() + ":");
492+
for (RecipeItem ri : recipe.getIngredients()) {
493+
P.p.log(ri.toString());
494+
}
495+
P.p.log("&lIngredients in Brew:");
496+
for (Ingredient ingredient : ingredients.getIngredientList()) {
497+
int amountInRecipe = recipe.amountOf(ingredient);
498+
P.p.log(ingredient.toString() + ": " + amountInRecipe + " of this are in the Recipe");
499+
}
500+
int ingQ = ingredients.getIngredientQuality(recipe);
501+
int cookQ = ingredients.getCookingQuality(recipe, false);
502+
int cookDistQ = ingredients.getCookingQuality(recipe, true);
503+
P.p.log("ingQlty: " + ingQ + ", cookQlty:" + cookQ + ", cook+DistQlty: " + cookDistQ);
504+
}
505+
506+
P.p.msg(player, "Debug Info for item written into Log");
507+
}
508+
}
509+
510+
public void showStats(CommandSender sender) {
511+
if (sender instanceof ConsoleCommandSender && !sender.isOp()) return;
512+
513+
P.p.msg(sender, "Drunk Players: " + BPlayer.numDrunkPlayers());
514+
P.p.msg(sender, "Brews created: " + P.p.brewsCreated);
515+
P.p.msg(sender, "Barrels built: " + Barrel.barrels.size());
516+
P.p.msg(sender, "Cauldrons boiling: " + BCauldron.bcauldrons.size());
517+
P.p.msg(sender, "Number of Recipes: " + BRecipe.getAllRecipes().size());
518+
P.p.msg(sender, "Wakeups: " + Wakeup.wakeups.size());
519+
}
520+
446521
@SuppressWarnings("deprecation")
447522
public void cmdStatic(CommandSender sender) {
448523

0 commit comments

Comments
 (0)