Add custom lore for item setting gui.

This commit is contained in:
alexcrea 2024-04-23 00:02:44 +02:00
parent 6feb3fbeeb
commit 257a3b4696
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 34 additions and 16 deletions

View file

@ -87,15 +87,21 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Left \u00A78Item", this, this.leftItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Left \u00A78Item", this,
this.anvilRecipe + "." + AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe + "." + AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG()); AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(),
"\u00A77Set the left item of the custom craft",
"\u00A77\u25A0 + \u25A1 = \u25A1");
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Right \u00A78Item", this, this.rightItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Right \u00A78Item", this,
this.anvilRecipe + "." + AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe + "." + AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG()); AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(),
"\u00A77Set the right item of the custom craft",
"\u00A77\u25A1 + \u25A0 = \u25A1");
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A7aRecipe Result \u00A78Item", this, this.resultItemFactory = ItemSettingGui.itemFactory("\u00A7aRecipe Result \u00A78Item", this,
this.anvilRecipe + "." + AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe + "." + AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG()); AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG(),
"\u00A77Set the result item of the custom craft",
"\u00A77\u25A1 + \u25A1 = \u25A0");
} }
private ConfirmActionGui createDeleteGui() { private ConfirmActionGui createDeleteGui() {

View file

@ -16,6 +16,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; 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.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -161,20 +162,22 @@ public class ItemSettingGui extends AbstractSettingGui {
/** /**
* Create aa item setting factory from setting's parameters. * Create aa item 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 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, ValueUpdatableGui parent,
String configPath, ConfigHolder config, String configPath, ConfigHolder config,
ItemStack defaultVal) { ItemStack defaultVal,
String... displayLore) {
return new ItemSettingGui.ItemSettingFactory( return new ItemSettingGui.ItemSettingFactory(
title, parent, title, parent,
configPath, config, configPath, config,
defaultVal); defaultVal, displayLore);
} }
/** /**
@ -185,25 +188,29 @@ public class ItemSettingGui extends AbstractSettingGui {
String title; String title;
ValueUpdatableGui parent; ValueUpdatableGui parent;
ItemStack defaultVal; ItemStack defaultVal;
List<String> displayLore;
/** /**
* Constructor for an item setting gui factory. * Constructor for an item 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 ItemSettingFactory( protected ItemSettingFactory(
@NotNull String title, ValueUpdatableGui parent, @NotNull String title, ValueUpdatableGui parent,
String configPath, ConfigHolder config, String configPath, ConfigHolder config,
ItemStack defaultVal) { ItemStack 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);
} }
/** /**
@ -221,6 +228,10 @@ public class ItemSettingGui extends AbstractSettingGui {
return this.config.getConfig().getItemStack(this.configPath, this.defaultVal); return this.config.getConfig().getItemStack(this.configPath, this.defaultVal);
} }
public List<String> getDisplayLore() {
return displayLore;
}
@Override @Override
public AbstractSettingGui create() { public AbstractSettingGui create() {
// Get current value or default // Get current value or default

View file

@ -288,6 +288,7 @@ public class GuiGlobalItems {
} }
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName("\u00A7a" + name); meta.setDisplayName("\u00A7a" + name);
meta.setLore(factory.getDisplayLore());
item.setItemMeta(meta); item.setItemMeta(meta);