Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recipe description and ability to hide recipes from collection #20

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion resources/config/v13/en/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ customItems:
# You only need to add something here if you want to specify a custom name or color for the base potion

# name: Name of the base potion coming out of the Cauldron (Formatting codes possible: such as &6)
# undiscoveredLore: List of text that shows when the brew hasn't been crafted yet in the collection menu (Formatting codes possible: such as &6)
# hidden: Whether to hide the brew from the collection menu, defaults to false
# ingredients: List of 'material/amount'
# With an item in your hand, use /brew ItemName to get its material for use in a recipe
# (Item-ids instead of material are not supported by bukkit anymore and will not work)
Expand All @@ -157,6 +159,9 @@ cauldron:
# Example with all possible entries
ex:
name: Example
undiscoveredLore:
- An example for a Base Potion
hidden: false
ingredients:
- Bedrock/2
- Diamond
Expand Down Expand Up @@ -402,6 +407,8 @@ cauldron:
# -- Recipes for Potions --

# name: Different names for bad/normal/good (Formatting codes possible: such as &6)
# undiscoveredLore: List of text that shows when the brew hasn't been crafted yet in the collection menu (Formatting codes possible: such as &6)
# hidden: Whether to hide the brew from the collection menu, defaults to false
# ingredients: List of 'material/amount'
# With an item in your hand, use /brew ItemName to get its material for use in a recipe
# (Item-ids instead of material are not supported by bukkit anymore and will not work)
Expand Down Expand Up @@ -438,6 +445,9 @@ recipes:
# Example Recipe with every possible entry first:
ex:
name: Bad Example/Example/Good Example
undiscoveredLore:
- An example brew
hidden: false
ingredients:
- Diamond/1
- Spruce_Planks/8
Expand All @@ -454,7 +464,7 @@ recipes:
difficulty: 3
alcohol: 14
lore:
- This is an examble brew
- This is an example brew
- ++Just a normal Example
- This text would be on the brew
- + Smells disgusting
Expand Down
6 changes: 5 additions & 1 deletion src/com/dre/brewery/listeners/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ private Pane recipePagePane(Player player, List<BRecipe> recipes) {
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(meta.getDisplayName());
item.setItemMeta(itemMeta);
List<String> lore = recipe.getUndiscoveredLore() == null ? null : recipe.getUndiscoveredLore().stream()
.map(line -> "§r§f" + line)
.toList();
item.setLore(lore);
pane.addItem(new GuiItem(item, ev -> ev.setCancelled(true)));
}
}
Expand All @@ -239,7 +243,7 @@ public void cmdCollection(CommandSender sender) {
Player pSender = (Player)sender;

PaginatedPane paginatedPane = new PaginatedPane(0, 0, 9, 5);
List<BRecipe> eligible = BRecipe.getAllRecipes().stream().filter(recipe -> recipe.getOptionalID().isPresent()).toList();
List<BRecipe> eligible = BRecipe.getAllRecipes().stream().filter(recipe -> recipe.getOptionalID().isPresent()).filter(recipe -> !recipe.isHidden()).toList();
List<List<BRecipe>> pageRecipes = Lists.partition(eligible, 5*9);
ChestGui gui = new ChestGui(6, MessageFormat.format("{0} ({1}/{2})", GetText.tr("Crafted Brews"), 1, pageRecipes.size()));

Expand Down
34 changes: 34 additions & 0 deletions src/com/dre/brewery/recipe/BRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class BRecipe {
private String[] name;
private boolean saveInData; // If this recipe should be saved in data and loaded again when the server restarts. Applicable to non-config recipes
private String optionalID; // ID that might be given by the config
private List<String> undiscoveredLore; // The text that shows when a brew hasn't been crafted yet in the collection
private boolean hidden; // Whether to hide this brew from the collection

// brewing
private List<RecipeItem> ingredients = new ArrayList<>(); // Items and amounts
Expand Down Expand Up @@ -109,6 +111,9 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri
return null;
}

recipe.undiscoveredLore = BUtil.loadCfgStringList(configSectionRecipes, recipeId + ".undiscoveredLore");;
recipe.hidden = configSectionRecipes.getBoolean(recipeId + ".hidden", false);

recipe.ingredients = loadIngredients(configSectionRecipes, recipeId);
if (recipe.ingredients == null || recipe.ingredients.isEmpty()) {
P.p.errorLog("No ingredients for: " + recipe.getRecipeName());
Expand Down Expand Up @@ -663,6 +668,14 @@ public Optional<String> getOptionalID() {
return Optional.ofNullable(optionalID);
}

public List<String> getUndiscoveredLore() {
return undiscoveredLore;
}

public boolean isHidden() {
return hidden;
}

public List<RecipeItem> getIngredients() {
return ingredients;
}
Expand Down Expand Up @@ -785,6 +798,14 @@ public boolean isSaveInData() {

// Setters

public void setUndiscoveredLore(List<String> description) {
this.undiscoveredLore = description;
}

public void setHidden(boolean hidden) {
this.hidden = hidden;
}

/**
* When Changing ingredients, Accepted Lists have to be updated in BCauldronRecipe
*/
Expand Down Expand Up @@ -932,6 +953,19 @@ public Builder(String... names) {
}


public Builder addUndiscoveredLore(String line) {
if (recipe.undiscoveredLore == null) {
recipe.undiscoveredLore = new ArrayList<>();
}
recipe.undiscoveredLore.add(line);
return this;
}

public Builder setHidden(boolean hidden) {
recipe.hidden = hidden;
return this;
}

public Builder addIngredient(RecipeItem... item) {
Collections.addAll(recipe.ingredients, item);
return this;
Expand Down