From 3f51fe2b313d27ef62539c1dd5ca62363d1783ff Mon Sep 17 00:00:00 2001 From: Jsinco Date: Thu, 4 Apr 2024 22:30:32 -0400 Subject: [PATCH] Add brew glint #617 --- resources/config/v13/en/config.yml | 2 ++ src/com/dre/brewery/BIngredients.java | 6 ++++ src/com/dre/brewery/Brew.java | 19 +++++++++++++ src/com/dre/brewery/recipe/BRecipe.java | 37 +++++++++++++++++-------- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/resources/config/v13/en/config.yml b/resources/config/v13/en/config.yml index 5c2c3b5c..4df88db9 100644 --- a/resources/config/v13/en/config.yml +++ b/resources/config/v13/en/config.yml @@ -437,6 +437,7 @@ cauldron: # Specific Commands for quality possible, using + bad, ++ normal, +++ good, added to the front of the line. # drinkmessage: Chat-message to the Player when drinking the Brew # drinktitle: Title on Screen to the Player when drinking the Brew +# glint: Boolean if the item should have a glint (enchant glint) # customModelData: Custom Model Data Tag. This is a number that can be used to add custom textures to the item. # Can specify one for all, or one for each quality, separated by / # effects: List of effect/level/duration Special potion-effect when drinking, duration in sek. @@ -478,6 +479,7 @@ recipes: - homes drinkmessage: Tastes good drinktitle: Warms you from inside + glint: true customModelData: 556/557/557 effects: - FIRE_RESISTANCE/20 diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index 1eb7b737..ae505fbb 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -11,6 +11,8 @@ import com.dre.brewery.recipe.PotionColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.jetbrains.annotations.Nullable; @@ -133,6 +135,10 @@ public ItemStack cook(int state, String brewer) { cookRecipe.getColor().colorBrew(potionMeta, potion, false); brew.updateCustomModelData(potionMeta); + if (cookRecipe.hasGlint()) { + potionMeta.addEnchant(Enchantment.LUCK, 1, true); + potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } } else { // new base potion brew = new Brew(this); diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index dd4e3bd4..5799efa9 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -10,7 +10,9 @@ import com.dre.brewery.utility.BUtil; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.BrewerInventory; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; @@ -53,6 +55,7 @@ public class Brew implements Cloneable { private boolean stripped; // Most Brewing information removed, only drinking and rough quality information available. Brew should not change anymore private int lastUpdate; // last update in hours after install time private boolean needsSave; // There was a change that has not yet been saved + private boolean hasGlint; // The Brew has a glint effect /** * A new Brew with only ingredients @@ -572,6 +575,10 @@ public boolean needsSave() { return needsSave; } + public boolean hasGlint() { + return hasGlint; + } + public void setNeedsSave(boolean needsSave) { this.needsSave = needsSave; } @@ -708,6 +715,11 @@ public void age(ItemStack item, float time, byte woodType) { lore.addOrReplaceEffects(getEffects(), quality); potionMeta.setDisplayName(BreweryPlugin.getInstance().color("&f" + recipe.getName(quality))); recipe.getColor().colorBrew(potionMeta, item, canDistill()); + + if (recipe.hasGlint()) { + potionMeta.addEnchant(Enchantment.LUCK, 1, true); + potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } } else { quality = 0; lore.convertLore(false); @@ -804,6 +816,13 @@ public ItemStack createItem(@Nullable BRecipe recipe, boolean event) { recipe.getColor().colorBrew(potionMeta, potion, false); updateCustomModelData(potionMeta); + + + if (recipe.hasGlint()) { + potionMeta.addEnchant(Enchantment.LUCK, 1, true); + potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } + potionMeta.setDisplayName(BreweryPlugin.getInstance().color("&f" + recipe.getName(quality))); //if (!P.use1_14) { // Before 1.14 the effects duration would strangely be only a quarter of what we tell it to be diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index 936b56cf..3c39a8fd 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -56,6 +56,7 @@ public class BRecipe { private @Nullable List> servercmds; // Commands executed as the server when drinking private String drinkMsg; // Message when drinking private String drinkTitle; // Title to show when drinking + private boolean glint; // If the potion should have a glint effect private BRecipe() { } @@ -101,7 +102,7 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri BreweryPlugin.getInstance().errorLog(recipeId + ": Recipe Name missing or invalid!"); return null; } - if (recipe.getRecipeName() == null || recipe.getRecipeName().length() < 1) { + if (recipe.getRecipeName() == null || recipe.getRecipeName().isEmpty()) { BreweryPlugin.getInstance().errorLog(recipeId + ": Recipe Name invalid"); return null; } @@ -138,6 +139,8 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri recipe.drinkMsg = BreweryPlugin.getInstance().color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage")); recipe.drinkTitle = BreweryPlugin.getInstance().color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle")); + recipe.glint = configSectionRecipes.getBoolean(recipeId + ".glint", false); + if (configSectionRecipes.isString(recipeId + ".customModelData")) { String[] cmdParts = configSectionRecipes.getString(recipeId + ".customModelData", "").split("/"); if (cmdParts.length == 3) { @@ -157,17 +160,15 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri } List effectStringList = configSectionRecipes.getStringList(recipeId + ".effects"); - if (effectStringList != null) { - for (String effectString : effectStringList) { - BEffect effect = new BEffect(effectString); - if (effect.isValid()) { - recipe.effects.add(effect); - } else { - BreweryPlugin.getInstance().errorLog("Error adding Effect to Recipe: " + recipe.getRecipeName()); - } - } - } - return recipe; + for (String effectString : effectStringList) { + BEffect effect = new BEffect(effectString); + if (effect.isValid()) { + recipe.effects.add(effect); + } else { + BreweryPlugin.getInstance().errorLog("Error adding Effect to Recipe: " + recipe.getRecipeName()); + } + } + return recipe; } public static List loadIngredients(ConfigurationSection cfg, String recipeId) { @@ -660,6 +661,10 @@ public String getDrinkTitle() { return drinkTitle; } + public boolean hasGlint() { + return glint; + } + public List getEffects() { return effects; } @@ -945,6 +950,14 @@ public Builder drinkTitle(String title) { return this; } + /** + * Add a Glint to the Potion + */ + public Builder glint(boolean glint) { + recipe.glint = glint; + return this; + } + /** * Set the Optional ID of this recipe */