Allow to append lore for setting gui's item.

This commit is contained in:
alexcrea 2024-04-28 19:39:11 +02:00
parent 95c976bd56
commit 91994a6e78
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
13 changed files with 159 additions and 73 deletions

View file

@ -79,7 +79,9 @@ public class BasicConfigGui extends ValueUpdatableGui {
// rename cost item // rename cost item
IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE; IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE;
this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this, 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, ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE,
1, 5, 10); 1, 5, 10);
@ -99,27 +101,35 @@ public class BasicConfigGui extends ValueUpdatableGui {
// item repair cost // item repair cost
range = ConfigOptions.REPAIR_COST_RANGE; range = ConfigOptions.REPAIR_COST_RANGE;
this.itemRepairCost = IntSettingsGui.intFactory("\u00A78Item Repair Cost", this, 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, ConfigOptions.DEFAULT_ITEM_REPAIR_COST,
1, 5, 10, 50, 100); 1, 5, 10, 50, 100);
// unit repair cost // unit repair cost
this.unitRepairCost = IntSettingsGui.intFactory("\u00A78Unit Repair Cost", this, 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, ConfigOptions.DEFAULT_UNIT_REPAIR_COST,
1, 5, 10, 50, 100); 1, 5, 10, 50, 100);
// item rename cost // item rename cost
range = ConfigOptions.ITEM_RENAME_COST_RANGE; range = ConfigOptions.ITEM_RENAME_COST_RANGE;
this.itemRenameCost = IntSettingsGui.intFactory("\u00A78Rename Cost", this, 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, ConfigOptions.DEFAULT_ITEM_RENAME_COST,
1, 5, 10, 50, 100); 1, 5, 10, 50, 100);
// sacrifice illegal enchant cost // sacrifice illegal enchant cost
range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE; range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE;
this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("\u00A78Sacrifice Illegal Enchant Cost", this, 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, ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST,
1, 5, 10, 50, 100); 1, 5, 10, 50, 100);

View file

@ -49,7 +49,9 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
} }
return EnchantCostSettingsGui.enchantCostFactory(prettyKey + " Level Cost", this, return EnchantCostSettingsGui.enchantCostFactory(prettyKey + " Level Cost", this,
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG, 0, 255, SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
null,
0, 255,
rarity.getItemValue(), rarity.getBookValue(), rarity.getItemValue(), rarity.getBookValue(),
1, 10, 50); 1, 10, 50);
} }

View file

@ -36,7 +36,9 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key); String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
return IntSettingsGui.intFactory(prettyKey + " Level Limit", this, return IntSettingsGui.intFactory(prettyKey + " Level Limit", this,
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG, 0, 255, SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
null,
0, 255,
enchant.getMaxLevel(), enchant.getMaxLevel(),
1, 5, 10, 50, 100); 1, 5, 10, 50, 100);
} }

View file

@ -116,6 +116,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
this, this,
material.name().toLowerCase()+"."+materialName, material.name().toLowerCase()+"."+materialName,
ConfigHolder.UNIT_REPAIR_HOLDER, ConfigHolder.UNIT_REPAIR_HOLDER,
null,
2, 2,
true, true, true, true,
0, 0,

View file

@ -82,6 +82,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this, this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this,
this.anvilRecipe +"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe +"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
null,
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10); costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);

View file

@ -97,6 +97,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory( this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory(
"\u00A78Minimum enchantment count", "\u00A78Minimum enchantment count",
this, this.enchantConflict + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER, this, this.enchantConflict + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
null,
0, 255, 0, 1 0, 255, 0, 1
); );

View file

@ -119,7 +119,9 @@ public abstract class AbstractSettingGui extends ChestGui {
* It is better to keep a factory that hold setting data than find what parameters to use every time. * It is better to keep a factory that hold setting data than find what parameters to use every time.
*/ */
public abstract static class SettingGuiFactory { public abstract static class SettingGuiFactory {
@NotNull
protected String configPath; protected String configPath;
@NotNull
protected ConfigHolder config; protected ConfigHolder config;
/** /**
@ -128,7 +130,7 @@ public abstract class AbstractSettingGui extends ChestGui {
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
*/ */
protected SettingGuiFactory(String configPath, ConfigHolder config) { protected SettingGuiFactory(@NotNull String configPath, @NotNull ConfigHolder config) {
this.configPath = configPath; this.configPath = configPath;
this.config = config; this.config = config;
} }
@ -136,6 +138,7 @@ public abstract class AbstractSettingGui extends ChestGui {
/** /**
* @return Configuration path of this setting. * @return Configuration path of this setting.
*/ */
@NotNull
public String getConfigPath() { public String getConfigPath() {
return configPath; return configPath;
} }
@ -143,6 +146,7 @@ public abstract class AbstractSettingGui extends ChestGui {
/** /**
* @return Configuration holder of this setting. * @return Configuration holder of this setting.
*/ */
@NotNull
public ConfigHolder getConfigHolder() { public ConfigHolder getConfigHolder() {
return config; return config;
} }

View file

@ -16,7 +16,9 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MetricsUtil; import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -142,20 +144,22 @@ public class BoolSettingsGui extends AbstractSettingGui {
/** /**
* Create a bool setting factory from setting's parameters. * Create a bool setting factory from setting's parameters.
* *
* @param title The title of the gui. * @param title The title of the gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param defaultVal Default value if not found on the config. * @param defaultVal Default value if not found on the config.
* @param displayLore Gui display item lore.
* @return A factory for a boolean setting gui. * @return A factory for a boolean setting gui.
*/ */
public static BoolSettingFactory boolFactory(@NotNull String title, ValueUpdatableGui parent, public static BoolSettingFactory boolFactory(@NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
boolean defaultVal) { boolean defaultVal,
String... displayLore) {
return new BoolSettingFactory( return new BoolSettingFactory(
title, parent, title, parent,
configPath, config, configPath, config,
defaultVal); defaultVal, displayLore);
} }
/** /**
@ -164,27 +168,33 @@ public class BoolSettingsGui extends AbstractSettingGui {
public static class BoolSettingFactory extends SettingGuiFactory { public static class BoolSettingFactory extends SettingGuiFactory {
@NotNull @NotNull
String title; String title;
@NotNull
ValueUpdatableGui parent; ValueUpdatableGui parent;
boolean defaultVal; boolean defaultVal;
@NotNull
List<String> displayLore;
/** /**
* Constructor for a boolean setting gui factory. * Constructor for a boolean setting gui factory.
* *
* @param title The title of the gui. * @param title The title of the gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param defaultVal Default value if not found on the config. * @param defaultVal Default value if not found on the config.
* @param displayLore Gui display item lore.
*/ */
protected BoolSettingFactory( protected BoolSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
boolean defaultVal) { boolean defaultVal, String... displayLore) {
super(configPath, config); super(configPath, config);
this.title = title; this.title = title;
this.parent = parent; this.parent = parent;
this.defaultVal = defaultVal; this.defaultVal = defaultVal;
this.displayLore = Arrays.asList(displayLore);
} }
/** /**
@ -233,7 +243,7 @@ public class BoolSettingsGui extends AbstractSettingGui {
} }
itemName.append(name); itemName.append(name);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value); return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore);
} }
/** /**

View file

@ -10,6 +10,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; 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 parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param displayLore Gui display item lore.
* @param scale The scale of the decimal. * @param scale The scale of the decimal.
* @param asPercentage If we should display the value as a %. * @param asPercentage If we should display the value as a %.
* @param nullOnZero Set the value as null (deleting it) when equal to 0 * @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. * If step only contain 1 value, no step item should be displayed.
* @return A factory for a double setting gui. * @return A factory for a double setting gui.
*/ */
public static DoubleSettingFactory doubleFactory(@NotNull String title, ValueUpdatableGui parent, @NotNull
String configPath, ConfigHolder config, public static DoubleSettingFactory doubleFactory(@NotNull String title, @NotNull ValueUpdatableGui parent,
@NotNull String configPath, @NotNull ConfigHolder config,
@Nullable List<String> displayLore,
int scale, boolean asPercentage, boolean nullOnZero, int scale, boolean asPercentage, boolean nullOnZero,
double min, double max, double defaultVal, double... steps) { double min, double max, double defaultVal, double... steps) {
return new DoubleSettingFactory( return new DoubleSettingFactory(
title, parent, title, parent,
configPath, config, configPath, config,
displayLore,
scale, asPercentage, nullOnZero, scale, asPercentage, nullOnZero,
min, max, defaultVal, steps); min, max, defaultVal, steps);
} }
@ -367,6 +372,7 @@ public class DoubleSettingGui extends AbstractSettingGui {
public static class DoubleSettingFactory extends SettingGuiFactory { public static class DoubleSettingFactory extends SettingGuiFactory {
@NotNull @NotNull
String title; String title;
@NotNull
ValueUpdatableGui parent; ValueUpdatableGui parent;
int scale; int scale;
@ -377,6 +383,9 @@ public class DoubleSettingGui extends AbstractSettingGui {
BigDecimal defaultVal; BigDecimal defaultVal;
BigDecimal[] steps; BigDecimal[] steps;
@NotNull
List<String> displayLore;
/** /**
* Constructor for a double setting gui factory. * 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 parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param displayLore Gui display item lore.
* @param scale The scale of the decimal. * @param scale The scale of the decimal.
* @param asPercentage If we should display the value as a %. * @param asPercentage If we should display the value as a %.
* @param nullOnZero Set the value as null (deleting it) when equal to 0 * @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. * If step only contain 1 value, no step item should be displayed.
*/ */
protected DoubleSettingFactory( protected DoubleSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
@Nullable List<String> displayLore,
int scale, boolean asPercentage, boolean nullOnZero, int scale, boolean asPercentage, boolean nullOnZero,
double min, double max, double defaultVal, double... steps) { double min, double max, double defaultVal, double... steps) {
super(configPath, config); super(configPath, config);
@ -414,6 +425,12 @@ public class DoubleSettingGui extends AbstractSettingGui {
for (int i = 0; i < steps.length; i++) { for (int i = 0; i < steps.length; i++) {
this.steps[i] = BigDecimal.valueOf(steps[i]).setScale(scale, RoundingMode.HALF_UP); 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(); BigDecimal value = getConfiguredValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(name); 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){ public GuiItem getItem(Material itemMat){

View file

@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; 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 xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -228,6 +230,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param displayLore Gui display item lore.
* @param min Minimum value of this setting. * @param min Minimum value of this setting.
* @param max Maximum value of this setting. * @param max Maximum value of this setting.
* @param defaultItemVal Default item value if not found on the config. * @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. * @return A factory for an enchant cost setting gui.
*/ */
public static EnchantCostSettingFactory enchantCostFactory( public static EnchantCostSettingFactory enchantCostFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
@Nullable List<String> displayLore,
int min, int max, int defaultItemVal, int defaultBookVal, int min, int max, int defaultItemVal, int defaultBookVal,
int... steps) { int... steps) {
return new EnchantCostSettingFactory( return new EnchantCostSettingFactory(
title, parent, title, parent,
configPath, config, configPath, config,
displayLore,
min, max, defaultItemVal, defaultBookVal, steps); min, max, defaultItemVal, defaultBookVal, steps);
} }
@ -263,6 +268,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param displayLore Gui display item lore.
* @param min Minimum value of this setting. * @param min Minimum value of this setting.
* @param max Maximum value of this setting. * @param max Maximum value of this setting.
* @param defaultItemVal Default item value if not found on the config. * @param defaultItemVal Default item value if not found on the config.
@ -274,12 +280,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
*/ */
protected EnchantCostSettingFactory( protected EnchantCostSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
@Nullable List<String> displayLore,
int min, int max, int defaultItemVal, int defaultBookVal, int min, int max, int defaultItemVal, int defaultBookVal,
int... steps) { int... steps) {
super(title, parent, super(title, parent,
configPath, config, configPath, config,
displayLore,
min, max, defaultItemVal, steps); min, max, defaultItemVal, steps);
this.defaultBookVal = defaultBookVal; this.defaultBookVal = defaultBookVal;
} }

View file

@ -9,6 +9,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; 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. * Create an int setting factory from setting's parameters.
* *
* @param title The title of the gui. * @param title The title of the gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param min Minimum value of this setting. * @param displayLore Gui display item lore.
* @param max Maximum value of this setting. * @param min Minimum value of this setting.
* @param defaultVal Default value if not found on the config. * @param max Maximum value of this setting.
* @param steps List of step the value can increment/decrement. * @param defaultVal Default value if not found on the config.
* List's size should be between 1 (included) and 5 (included). * @param steps List of step the value can increment/decrement.
* it is visually preferable to have an odd number of step. * List's size should be between 1 (included) and 5 (included).
* If step only contain 1 value, no step item should be displayed. * 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. * @return A factory for an int setting gui.
*/ */
public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent, public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent,
String configPath, ConfigHolder config, String configPath, ConfigHolder config,
@Nullable List<String> displayLore,
int min, int max, int defaultVal, int... steps) { int min, int max, int defaultVal, int... steps) {
return new IntSettingFactory( return new IntSettingFactory(
title, parent, title, parent,
configPath, config, configPath, config,
displayLore,
min, max, defaultVal, steps); min, max, defaultVal, steps);
} }
@ -295,30 +299,36 @@ public class IntSettingsGui extends AbstractSettingGui {
public static class IntSettingFactory extends SettingGuiFactory { public static class IntSettingFactory extends SettingGuiFactory {
@NotNull @NotNull
String title; String title;
@NotNull
ValueUpdatableGui parent; ValueUpdatableGui parent;
int min; int min;
int max; int max;
int defaultVal; int defaultVal;
int[] steps; int[] steps;
@NotNull
List<String> displayLore;
/** /**
* Constructor for an int setting gui factory. * Constructor for an int setting gui factory.
* *
* @param title The title of the gui. * @param title The title of the gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
* @param configPath Configuration path of this setting. * @param configPath Configuration path of this setting.
* @param config Configuration holder of this setting. * @param config Configuration holder of this setting.
* @param min Minimum value of this setting. * @param displayLore Gui display item lore.
* @param max Maximum value of this setting. * @param min Minimum value of this setting.
* @param defaultVal Default value if not found on the config. * @param max Maximum value of this setting.
* @param steps List of step the value can increment/decrement. * @param defaultVal Default value if not found on the config.
* List's size should be between 1 (included) and 5 (included). * @param steps List of step the value can increment/decrement.
* it is visually preferable to have an odd number of step. * List's size should be between 1 (included) and 5 (included).
* If step only contain 1 value, no step item should be displayed. * 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( protected IntSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
@Nullable List<String> displayLore,
int min, int max, int defaultVal, int... steps) { int min, int max, int defaultVal, int... steps) {
super(configPath, config); super(configPath, config);
this.title = title; this.title = title;
@ -327,6 +337,12 @@ public class IntSettingsGui extends AbstractSettingGui {
this.max = max; this.max = max;
this.defaultVal = defaultVal; this.defaultVal = defaultVal;
this.steps = steps; 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(); int value = getConfiguredValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(name); StringBuilder itemName = new StringBuilder("\u00A7a").append(name);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value); return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore);
} }
/** /**

View file

@ -10,6 +10,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
@ -171,9 +172,9 @@ public class ItemSettingGui extends AbstractSettingGui {
* @param displayLore Gui display item lore. * @param displayLore Gui display item lore.
* @return A factory for an item setting gui. * @return A factory for an item setting gui.
*/ */
public static ItemSettingGui.ItemSettingFactory itemFactory(@NotNull String title, ValueUpdatableGui parent, public static ItemSettingGui.ItemSettingFactory itemFactory(@NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
ItemStack defaultVal, @Nullable ItemStack defaultVal,
String... displayLore) { String... displayLore) {
return new ItemSettingGui.ItemSettingFactory( return new ItemSettingGui.ItemSettingFactory(
title, parent, title, parent,
@ -187,8 +188,11 @@ public class ItemSettingGui extends AbstractSettingGui {
public static class ItemSettingFactory extends SettingGuiFactory { public static class ItemSettingFactory extends SettingGuiFactory {
@NotNull @NotNull
String title; String title;
@NotNull
ValueUpdatableGui parent; ValueUpdatableGui parent;
@Nullable
ItemStack defaultVal; ItemStack defaultVal;
@NotNull
List<String> displayLore; List<String> displayLore;
/** /**
@ -202,9 +206,9 @@ public class ItemSettingGui extends AbstractSettingGui {
* @param displayLore Gui display item lore. * @param displayLore Gui display item lore.
*/ */
protected ItemSettingFactory( protected ItemSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, @NotNull ValueUpdatableGui parent,
String configPath, ConfigHolder config, @NotNull String configPath, @NotNull ConfigHolder config,
ItemStack defaultVal, @Nullable ItemStack defaultVal,
String... displayLore) { String... displayLore) {
super(configPath, config); super(configPath, config);
this.title = title; this.title = title;
@ -229,8 +233,9 @@ public class ItemSettingGui extends AbstractSettingGui {
return this.config.getConfig().getItemStack(this.configPath, this.defaultVal); return this.config.getConfig().getItemStack(this.configPath, this.defaultVal);
} }
@NotNull
public List<String> getDisplayLore() { public List<String> getDisplayLore() {
return displayLore; return this.displayLore;
} }
@Override @Override

View file

@ -13,7 +13,9 @@ import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
/** /**
* A utility class to store function that create generic GUI item. * 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. * Create an arbitrary GuiItem from a unique setting and item's property.
* *
* @param factory The setting's GUI factory. * @param factory The setting's GUI factory.
* @param itemMat Displayed material of the item. * @param itemMat Displayed material of the item.
* @param itemName Name of the item. * @param itemName Name of the item.
* @param value Value of the setting when the item is created. * @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. * 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. * @return A formatted GuiItem that will create and open a GUI for the setting.
*/ */
public static GuiItem createGuiItemFromProperties( public static GuiItem createGuiItemFromProperties(
@NotNull AbstractSettingGui.SettingGuiFactory factory, @NotNull AbstractSettingGui.SettingGuiFactory factory,
@NotNull Material itemMat, @NotNull Material itemMat,
@NotNull StringBuilder itemName, @NotNull StringBuilder itemName,
@NotNull Object value @NotNull Object value,
@NotNull List<String> displayLore
) { ) {
// Prepare lore
ArrayList<String> lore = new ArrayList<>();
lore.add(SETTING_ITEM_LORE_PREFIX + value);
lore.addAll(displayLore);
// Create & initialise item // Create & initialise item
ItemStack item = new ItemStack(itemMat); ItemStack item = new ItemStack(itemMat);
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(itemName.toString()); itemMeta.setDisplayName(itemName.toString());
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value)); itemMeta.setLore(lore);
itemMeta.addItemFlags(ItemFlag.values()); itemMeta.addItemFlags(ItemFlag.values());
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);