Skip to content

Commit

Permalink
Added stats & debug info commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wStorm committed Apr 13, 2020
1 parent 786a3c5 commit b2d1af2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/com/dre/brewery/BIngredients.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public int getIngredientsCount() {
return count;
}

/*public Map<Material, Integer> getIngredients() {
public List<Ingredient> getIngredientList() {
return ingredients;
}*/
}

public int getCookedTime() {
return cookedTime;
Expand Down
75 changes: 75 additions & 0 deletions src/com/dre/brewery/listeners/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit b2d1af2

Please sign in to comment.