diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java index f91cb57..85c4c1d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java @@ -79,7 +79,9 @@ public class BasicConfigGui extends ValueUpdatableGui { // rename cost item IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE; this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this, - ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(), + ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, + null, + range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE, 1, 5, 10); @@ -99,27 +101,35 @@ public class BasicConfigGui extends ValueUpdatableGui { // item repair cost range = ConfigOptions.REPAIR_COST_RANGE; this.itemRepairCost = IntSettingsGui.intFactory("\u00A78Item Repair Cost", this, - ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(), + ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, + null, + range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_ITEM_REPAIR_COST, 1, 5, 10, 50, 100); // unit repair cost this.unitRepairCost = IntSettingsGui.intFactory("\u00A78Unit Repair Cost", this, - ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(), + ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, + null, + range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_UNIT_REPAIR_COST, 1, 5, 10, 50, 100); // item rename cost range = ConfigOptions.ITEM_RENAME_COST_RANGE; this.itemRenameCost = IntSettingsGui.intFactory("\u00A78Rename Cost", this, - ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(), + ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, + null, + range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_ITEM_RENAME_COST, 1, 5, 10, 50, 100); // sacrifice illegal enchant cost range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE; this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("\u00A78Sacrifice Illegal Enchant Cost", this, - ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(), + ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, + null, + range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST, 1, 5, 10, 50, 100); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java index 2a1937b..91f304c 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java @@ -49,7 +49,9 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui displayLore; + /** * Constructor for a boolean setting gui factory. * - * @param title The title of the gui. - * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. - * @param config Configuration holder of this setting. - * @param defaultVal Default value if not found on the config. + * @param title The title of the gui. + * @param parent Parent gui to go back when completed. + * @param configPath Configuration path of this setting. + * @param config Configuration holder of this setting. + * @param defaultVal Default value if not found on the config. + * @param displayLore Gui display item lore. */ protected BoolSettingFactory( - @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, - boolean defaultVal) { + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + boolean defaultVal, String... displayLore) { super(configPath, config); this.title = title; this.parent = parent; this.defaultVal = defaultVal; + this.displayLore = Arrays.asList(displayLore); } /** @@ -233,7 +243,7 @@ public class BoolSettingsGui extends AbstractSettingGui { } itemName.append(name); - return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore); } /** diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java index 772f473..404aef1 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java @@ -10,6 +10,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; @@ -338,6 +339,7 @@ public class DoubleSettingGui extends AbstractSettingGui { * @param parent Parent gui to go back when completed. * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. * @param scale The scale of the decimal. * @param asPercentage If we should display the value as a %. * @param nullOnZero Set the value as null (deleting it) when equal to 0 @@ -350,13 +352,16 @@ public class DoubleSettingGui extends AbstractSettingGui { * If step only contain 1 value, no step item should be displayed. * @return A factory for a double setting gui. */ - public static DoubleSettingFactory doubleFactory(@NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, + @NotNull + public static DoubleSettingFactory doubleFactory(@NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable List displayLore, int scale, boolean asPercentage, boolean nullOnZero, double min, double max, double defaultVal, double... steps) { return new DoubleSettingFactory( title, parent, configPath, config, + displayLore, scale, asPercentage, nullOnZero, min, max, defaultVal, steps); } @@ -367,6 +372,7 @@ public class DoubleSettingGui extends AbstractSettingGui { public static class DoubleSettingFactory extends SettingGuiFactory { @NotNull String title; + @NotNull ValueUpdatableGui parent; int scale; @@ -377,6 +383,9 @@ public class DoubleSettingGui extends AbstractSettingGui { BigDecimal defaultVal; BigDecimal[] steps; + @NotNull + List displayLore; + /** * Constructor for a double setting gui factory. * @@ -384,6 +393,7 @@ public class DoubleSettingGui extends AbstractSettingGui { * @param parent Parent gui to go back when completed. * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. * @param scale The scale of the decimal. * @param asPercentage If we should display the value as a %. * @param nullOnZero Set the value as null (deleting it) when equal to 0 @@ -396,8 +406,9 @@ public class DoubleSettingGui extends AbstractSettingGui { * If step only contain 1 value, no step item should be displayed. */ protected DoubleSettingFactory( - @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable List displayLore, int scale, boolean asPercentage, boolean nullOnZero, double min, double max, double defaultVal, double... steps) { super(configPath, config); @@ -414,6 +425,12 @@ public class DoubleSettingGui extends AbstractSettingGui { for (int i = 0; i < steps.length; i++) { this.steps[i] = BigDecimal.valueOf(steps[i]).setScale(scale, RoundingMode.HALF_UP); } + + if(displayLore == null){ + this.displayLore = Collections.emptyList(); + }else { + this.displayLore = displayLore; + } } /** @@ -449,7 +466,7 @@ public class DoubleSettingGui extends AbstractSettingGui { BigDecimal value = getConfiguredValue(); StringBuilder itemName = new StringBuilder("\u00A7a").append(name); - return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, displayValue(value, this.asPercentage)); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, displayValue(value, this.asPercentage), this.displayLore); } public GuiItem getItem(Material itemMat){ diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java index c38b047..a593512 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; @@ -18,6 +19,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.util.MetricsUtil; import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; /** @@ -228,6 +230,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { * @param parent Parent gui to go back when completed. * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. * @param min Minimum value of this setting. * @param max Maximum value of this setting. * @param defaultItemVal Default item value if not found on the config. @@ -239,13 +242,15 @@ public class EnchantCostSettingsGui extends IntSettingsGui { * @return A factory for an enchant cost setting gui. */ public static EnchantCostSettingFactory enchantCostFactory( - @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable List displayLore, int min, int max, int defaultItemVal, int defaultBookVal, int... steps) { return new EnchantCostSettingFactory( title, parent, configPath, config, + displayLore, min, max, defaultItemVal, defaultBookVal, steps); } @@ -263,6 +268,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { * @param parent Parent gui to go back when completed. * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. * @param min Minimum value of this setting. * @param max Maximum value of this setting. * @param defaultItemVal Default item value if not found on the config. @@ -274,12 +280,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui { */ protected EnchantCostSettingFactory( @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable List displayLore, int min, int max, int defaultItemVal, int defaultBookVal, int... steps) { super(title, parent, configPath, config, + displayLore, min, max, defaultItemVal, steps); this.defaultBookVal = defaultBookVal; } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java index f19ea0f..dbd1d72 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java @@ -9,6 +9,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; @@ -267,25 +268,28 @@ public class IntSettingsGui extends AbstractSettingGui { /** * Create an int setting factory from setting's parameters. * - * @param title The title of the gui. - * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. - * @param config Configuration holder of this setting. - * @param min Minimum value of this setting. - * @param max Maximum value of this setting. - * @param defaultVal Default value if not found on the config. - * @param steps List of step the value can increment/decrement. - * List's size should be between 1 (included) and 5 (included). - * it is visually preferable to have an odd number of step. - * If step only contain 1 value, no step item should be displayed. + * @param title The title of the gui. + * @param parent Parent gui to go back when completed. + * @param configPath Configuration path of this setting. + * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. + * @param min Minimum value of this setting. + * @param max Maximum value of this setting. + * @param defaultVal Default value if not found on the config. + * @param steps List of step the value can increment/decrement. + * List's size should be between 1 (included) and 5 (included). + * it is visually preferable to have an odd number of step. + * If step only contain 1 value, no step item should be displayed. * @return A factory for an int setting gui. */ public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent, String configPath, ConfigHolder config, + @Nullable List displayLore, int min, int max, int defaultVal, int... steps) { return new IntSettingFactory( title, parent, configPath, config, + displayLore, min, max, defaultVal, steps); } @@ -295,30 +299,36 @@ public class IntSettingsGui extends AbstractSettingGui { public static class IntSettingFactory extends SettingGuiFactory { @NotNull String title; + @NotNull ValueUpdatableGui parent; int min; int max; int defaultVal; int[] steps; + @NotNull + List displayLore; + /** * Constructor for an int setting gui factory. * - * @param title The title of the gui. - * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. - * @param config Configuration holder of this setting. - * @param min Minimum value of this setting. - * @param max Maximum value of this setting. - * @param defaultVal Default value if not found on the config. - * @param steps List of step the value can increment/decrement. - * List's size should be between 1 (included) and 5 (included). - * it is visually preferable to have an odd number of step. - * If step only contain 1 value, no step item should be displayed. + * @param title The title of the gui. + * @param parent Parent gui to go back when completed. + * @param configPath Configuration path of this setting. + * @param config Configuration holder of this setting. + * @param displayLore Gui display item lore. + * @param min Minimum value of this setting. + * @param max Maximum value of this setting. + * @param defaultVal Default value if not found on the config. + * @param steps List of step the value can increment/decrement. + * List's size should be between 1 (included) and 5 (included). + * it is visually preferable to have an odd number of step. + * If step only contain 1 value, no step item should be displayed. */ protected IntSettingFactory( - @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable List displayLore, int min, int max, int defaultVal, int... steps) { super(configPath, config); this.title = title; @@ -327,6 +337,12 @@ public class IntSettingsGui extends AbstractSettingGui { this.max = max; this.defaultVal = defaultVal; this.steps = steps; + + if(displayLore == null){ + this.displayLore = Collections.emptyList(); + }else { + this.displayLore = displayLore; + } } /** @@ -369,7 +385,7 @@ public class IntSettingsGui extends AbstractSettingGui { int value = getConfiguredValue(); StringBuilder itemName = new StringBuilder("\u00A7a").append(name); - return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore); } /** diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java index d6e5552..b208a14 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java @@ -10,6 +10,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; @@ -171,9 +172,9 @@ public class ItemSettingGui extends AbstractSettingGui { * @param displayLore Gui display item lore. * @return A factory for an item setting gui. */ - public static ItemSettingGui.ItemSettingFactory itemFactory(@NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, - ItemStack defaultVal, + public static ItemSettingGui.ItemSettingFactory itemFactory(@NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable ItemStack defaultVal, String... displayLore) { return new ItemSettingGui.ItemSettingFactory( title, parent, @@ -187,8 +188,11 @@ public class ItemSettingGui extends AbstractSettingGui { public static class ItemSettingFactory extends SettingGuiFactory { @NotNull String title; + @NotNull ValueUpdatableGui parent; + @Nullable ItemStack defaultVal; + @NotNull List displayLore; /** @@ -202,9 +206,9 @@ public class ItemSettingGui extends AbstractSettingGui { * @param displayLore Gui display item lore. */ protected ItemSettingFactory( - @NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, - ItemStack defaultVal, + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config, + @Nullable ItemStack defaultVal, String... displayLore) { super(configPath, config); this.title = title; @@ -229,8 +233,9 @@ public class ItemSettingGui extends AbstractSettingGui { return this.config.getConfig().getItemStack(this.configPath, this.defaultVal); } + @NotNull public List getDisplayLore() { - return displayLore; + return this.displayLore; } @Override diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java index 42b9e3f..1491975 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java @@ -13,7 +13,9 @@ import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; /** * A utility class to store function that create generic GUI item. @@ -180,25 +182,32 @@ public class GuiGlobalItems { /** * Create an arbitrary GuiItem from a unique setting and item's property. * - * @param factory The setting's GUI factory. - * @param itemMat Displayed material of the item. - * @param itemName Name of the item. - * @param value Value of the setting when the item is created. - * Will not update automatically, if the setting's value change, the item need to be created again. + * @param factory The setting's GUI factory. + * @param itemMat Displayed material of the item. + * @param itemName Name of the item. + * @param value Value of the setting when the item is created. + * Will not update automatically, if the setting's value change, the item need to be created again. + * @param displayLore Gui display item lore. * @return A formatted GuiItem that will create and open a GUI for the setting. */ public static GuiItem createGuiItemFromProperties( @NotNull AbstractSettingGui.SettingGuiFactory factory, @NotNull Material itemMat, @NotNull StringBuilder itemName, - @NotNull Object value + @NotNull Object value, + @NotNull List displayLore ) { + // Prepare lore + ArrayList lore = new ArrayList<>(); + lore.add(SETTING_ITEM_LORE_PREFIX + value); + lore.addAll(displayLore); + // Create & initialise item ItemStack item = new ItemStack(itemMat); ItemMeta itemMeta = item.getItemMeta(); itemMeta.setDisplayName(itemName.toString()); - itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value)); + itemMeta.setLore(lore); itemMeta.addItemFlags(ItemFlag.values()); item.setItemMeta(itemMeta);