From 1d402b1e7672eea4d27c4911e31b71da45c07c07 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 17 Aug 2026 01:38:14 +0200 Subject: [PATCH] a lot of progress inside the ui --- .../cuanvil/dependency/util/PlatformUtil.kt | 20 +++++ .../gui/config/ask/AbstractAskGui.java | 6 +- .../gui/config/ask/ConfirmActionGui.java | 20 +++-- .../gui/config/ask/SelectItemTypeGui.java | 26 ++++--- .../global/AbstractEnchantConfigGui.java | 5 +- .../config/global/CustomRecipeConfigGui.java | 11 +-- .../gui/config/global/EnchantConflictGui.java | 11 +-- .../config/global/EnchantCostConfigGui.java | 6 +- .../config/global/EnchantLimitConfigGui.java | 5 +- .../global/EnchantMergeLimitConfigGui.java | 6 +- .../gui/config/global/GroupConfigGui.java | 5 +- .../config/global/UnitRepairConfigGui.java | 10 +-- .../gui/config/list/ElementListConfigGui.java | 20 ++--- .../list/MappedElementListConfigGui.java | 9 ++- .../config/list/MappedGuiListConfigGui.java | 17 ++++- .../config/list/SettingGuiListConfigGui.java | 17 ++++- .../config/list/UnitRepairElementListGui.java | 17 +++-- .../elements/CustomRecipeSubSettingGui.java | 30 ++++---- .../EnchantConflictSubSettingGui.java | 43 ++++++----- .../elements/GroupConfigSubSettingGui.java | 55 ++++++++++---- .../elements/MappedToListSubSettingGui.java | 6 +- .../settings/EnchantSelectSettingGui.java | 7 +- .../settings/GroupSelectSettingGui.java | 7 +- .../settings/MaterialSelectSettingGui.java | 10 ++- .../xyz/alexcrea/cuanvil/lang/Message.kt | 20 +++++ .../kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt | 43 ++++++++++- .../alexcrea/cuanvil/util/ComponentUtil.kt | 33 ++++++--- src/main/resources/lang/en.yml | 73 +++++++++++++++++-- 28 files changed, 386 insertions(+), 152 deletions(-) diff --git a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt index 3b47adaa..f1d6fe42 100644 --- a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt +++ b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PlatformUtil.kt @@ -112,6 +112,26 @@ object PlatformUtil { return true } + return false + } /** + * Try to send paper component to the player + * + * @param component The used component + * @return true if sent, else otherwise + */ + + /** + * Try to set component lore of an item + * + * @param components The used component lore + * @return true if sent, else otherwise + */ + fun ItemMeta.setPaperLore(components: List): Boolean { + if(isPaper) { + this.lore(components) + return true + } + return false } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/AbstractAskGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/AbstractAskGui.java index 66dd9363..75cdf236 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/AbstractAskGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/AbstractAskGui.java @@ -10,13 +10,15 @@ import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; public abstract class AbstractAskGui extends ChestGui { protected PatternPane pane; - AbstractAskGui(int rows, @NotNull String name, + AbstractAskGui(int rows, + @NotNull Message name, @NotNull String param, Gui backOnCancel){ - super(rows, name, CustomAnvil.instance); + super(rows, name.textHolder(param), CustomAnvil.instance); Pattern pattern = getGuiPattern(); this.pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/ConfirmActionGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/ConfirmActionGui.java index 0b5a08e7..e3b02a12 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/ConfirmActionGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/ConfirmActionGui.java @@ -9,21 +9,26 @@ import org.bukkit.entity.HumanEntity; 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.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; +import xyz.alexcrea.cuanvil.util.ComponentUtil; import xyz.alexcrea.cuanvil.util.MetricsUtil; +import java.awt.*; import java.util.Arrays; import java.util.function.Supplier; import java.util.logging.Level; public class ConfirmActionGui extends AbstractAskGui { - public ConfirmActionGui(@NotNull String title, String actionDescription, + public ConfirmActionGui(@NotNull Message title, @NotNull String titleParam, + @Nullable Message actionDescription, @NotNull String actionParam, Gui backOnCancel, Gui backOnConfirm, Supplier onConfirm, boolean permanent) { - super(3, title, backOnCancel); + super(3, title, titleParam, backOnCancel); // Save item this.pane.bindItem('S', new GuiItem( @@ -42,7 +47,7 @@ public class ConfirmActionGui extends AbstractAskGui { try { success = onConfirm.get(); } catch (Exception e) { - CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e); + CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e); //TODO MESSAGE MetricsUtil.INSTANCE.trackError(e); success = false; } @@ -58,18 +63,19 @@ public class ConfirmActionGui extends AbstractAskGui { ItemStack infoItem = new ItemStack(Material.PAPER); ItemMeta infoMeta = infoItem.getItemMeta(); - infoMeta.setDisplayName("§eAre you sure ?"); + infoMeta.setDisplayName("§eAre you sure ?"); //TODO MESSAGE if(actionDescription != null){ - infoMeta.setLore(Arrays.asList(actionDescription.split("\n"))); + ComponentUtil.INSTANCE.applyLore(actionDescription.formatted(), infoMeta); } infoItem.setItemMeta(infoMeta); pane.bindItem('I', new GuiItem(infoItem, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); } - public ConfirmActionGui(@NotNull String title, String actionDescription, + public ConfirmActionGui(@NotNull Message title, @NotNull String titleParam, + @Nullable Message actionDescription, @NotNull String actionParam, Gui backOnCancel, Gui backOnConfirm, Supplier onConfirm){ - this(title, actionDescription, backOnCancel, backOnConfirm, onConfirm, true); + this(title, titleParam, actionDescription, actionParam, backOnCancel, backOnConfirm, onConfirm, true); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/SelectItemTypeGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/SelectItemTypeGui.java index f0369e6d..b4b10b6f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/SelectItemTypeGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/ask/SelectItemTypeGui.java @@ -12,7 +12,9 @@ import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; +import xyz.alexcrea.cuanvil.util.ComponentUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil; import java.util.Arrays; @@ -22,12 +24,14 @@ import java.util.function.BiConsumer; public class SelectItemTypeGui extends AbstractAskGui { private ItemStack selectedItem; - public SelectItemTypeGui(@NotNull String title, - @NotNull String actionDescription, + public SelectItemTypeGui(@NotNull Message title, + @NotNull String titleParam, + @NotNull Message actionDescription, + @NotNull String descriptionParam, @NotNull Gui backOnCancel, @NotNull BiConsumer onSave, boolean materialOnly) { - super(3, title, backOnCancel); + super(3, title, titleParam, backOnCancel); this.selectedItem = null; // Save item @@ -47,7 +51,7 @@ public class SelectItemTypeGui extends AbstractAskGui { this.pane.bindItem('S', GuiGlobalItems.backgroundItem()); // Select item - ItemStack selectItem = setDisplayMeta(new ItemStack(Material.BARRIER), actionDescription); + ItemStack selectItem = setDisplayMeta(new ItemStack(Material.BARRIER), actionDescription, descriptionParam); AtomicReference selectGuiItem = new AtomicReference<>(); selectGuiItem.set(new GuiItem(selectItem, event -> { @@ -58,7 +62,7 @@ public class SelectItemTypeGui extends AbstractAskGui { ItemStack finalItem; if(materialOnly){ - finalItem = setDisplayMeta(new ItemStack(cursor.getType()), actionDescription); + finalItem = setDisplayMeta(new ItemStack(cursor.getType()), actionDescription, descriptionParam); }else{ finalItem = cursor.clone(); } @@ -76,14 +80,18 @@ public class SelectItemTypeGui extends AbstractAskGui { GuiItem temporaryLeave = GuiGlobalItems.temporaryCloseGuiToSelectItem(Material.YELLOW_STAINED_GLASS_PANE, this); this.pane.bindItem('s', temporaryLeave); - } - private ItemStack setDisplayMeta(ItemStack item, String actionDescription){ + @NotNull + private ItemStack setDisplayMeta( + @NotNull ItemStack item, + @NotNull Message actionDescription, + @NotNull String param + ){ ItemMeta meta = item.getItemMeta(); - meta.setDisplayName("§ePlace an item here"); - meta.setLore(Arrays.asList(actionDescription.split("\n"))); + meta.setDisplayName("§ePlace an item here"); //TODO MESSAGE + ComponentUtil.INSTANCE.applyLore(actionDescription.formatted(param), meta); item.setItemMeta(meta); return item; diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java index 5583b382..198f2149 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java @@ -9,6 +9,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry; import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import java.util.Collection; import java.util.Collections; @@ -27,11 +28,11 @@ public abstract class AbstractEnchantConfigGui getRecipeLore(AnvilCustomRecipe recipe) { boolean shouldWork = recipe.validate(); - ArrayList lore = new ArrayList<>(); + ArrayList lore = new ArrayList<>();//TODO MESSAGE lore.add("§7Is valid: §" + (shouldWork ? "aYes" : "cNo")); lore.add("§7Exact count: §" + (recipe.getExactCount() ? "aYes" : "cNo")); lore.add("§7Recipe Level Cost: §e" + recipe.getLevelCostPerCraft()); @@ -90,7 +91,7 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui { NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java index 19d31d9f..673c2ec8 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import java.util.ArrayList; import java.util.Collection; @@ -32,16 +33,18 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU public static final int LIST_FILLER_LENGTH = 7; public static final int LIST_FILLER_HEIGHT = 4; - private final String namePrefix; + private final Message rawTitle; + private final String param; protected PatternPane backgroundPane; private Predicate filter = (t) -> true; private boolean hasDefaultFilter = true; - protected ElementListConfigGui(@NotNull String title, Gui parent) { - super(6, title, CustomAnvil.instance); - this.namePrefix = title; + protected ElementListConfigGui(@NotNull Message title, String param, Gui parent) { + super(6, title.textHolder(param, "", ""), CustomAnvil.instance); + this.rawTitle = title; + this.param = param; // Back item panel Pattern pattern = getBackgroundPattern(); @@ -259,13 +262,10 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU // and add actual page addPane(page); - // set title - StringBuilder title = new StringBuilder(this.namePrefix); + // intended parameter: (page/max_page) //TODO MESSAGE CHECK CHILDS int pagesSize = this.pages.size(); - if (pagesSize > 1) { - title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')'); - } - setTitle(title.toString()); + var title = this.rawTitle.textHolder(param, pageID + 1, pagesSize); + setTitle(title); super.show(humanEntity); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java index 7bfffdf8..2406fddc 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; import java.util.Arrays; @@ -20,14 +21,14 @@ public abstract class MappedElementListConfigGui extends ElementListConfig protected final HashMap elementGuiMap; - protected MappedElementListConfigGui(@NotNull String title, @NotNull Gui parent) { - super(title, parent); + protected MappedElementListConfigGui(@NotNull Message title, @NotNull String param, @NotNull Gui parent) { + super(title, param, parent); this.elementGuiMap = new HashMap<>(); } - protected MappedElementListConfigGui(@NotNull String title) { - this(title, MainConfigGui.getInstance()); + protected MappedElementListConfigGui(@NotNull Message title, @NotNull String param) { + this(title, param, MainConfigGui.getInstance()); } @Override diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java index d25d6e72..5d346a43 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java @@ -8,6 +8,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.util.LazyValue; @@ -19,12 +20,20 @@ import java.util.function.Supplier; public abstract class MappedGuiListConfigGui> extends MappedElementListConfigGui { - protected MappedGuiListConfigGui(@NotNull String title) { - super(title); + protected MappedGuiListConfigGui(@NotNull Message title, @NotNull String param) { + super(title, param); } - protected MappedGuiListConfigGui(@NotNull String title, @NotNull Gui parent) { - super(title, parent); + protected MappedGuiListConfigGui(@NotNull Message title, @NotNull String param, @NotNull Gui parent) { + super(title, param, parent); + } + + protected MappedGuiListConfigGui(@NotNull Message title) { + super(title, ""); + } + + protected MappedGuiListConfigGui(@NotNull Message title, @NotNull Gui parent) { + super(title, "", parent); } @Override diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java index cb55ed08..b7bf0002 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; +import xyz.alexcrea.cuanvil.lang.Message; import java.util.HashMap; import java.util.List; @@ -20,16 +21,26 @@ public abstract class SettingGuiListConfigGui guiItemMap; protected HashMap factoryMap; - protected SettingGuiListConfigGui(@NotNull String title, Gui parent) { - super(title, parent); + protected SettingGuiListConfigGui(@NotNull Message title, Gui parent) { + super(title, "", parent); this.guiItemMap = new HashMap<>(); this.factoryMap = new HashMap<>(); } - protected SettingGuiListConfigGui(@NotNull String title) { + protected SettingGuiListConfigGui(@NotNull Message title) { this(title, MainConfigGui.getInstance()); } + protected SettingGuiListConfigGui(@NotNull Message title, @NotNull String param, Gui parent) { + super(title, param, parent); + this.guiItemMap = new HashMap<>(); + this.factoryMap = new HashMap<>(); + } + + protected SettingGuiListConfigGui(@NotNull Message title, @NotNull String param) { + this(title, param, MainConfigGui.getInstance()); + } + @Override protected GuiItem prepareCreateNewItem() { ItemStack createItem = new ItemStack(Material.PAPER); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java index f39b7aaf..fcbfa733 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java @@ -33,12 +33,16 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui { ItemMeta meta = itemStack.getItemMeta(); NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack); if (!(meta instanceof Damageable)) { - MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW().send(player); + MsgUI.INSTANCE.getUNIT_REPAIR_NEW_ELEMENT_CANNOT_REPAIR().send(player); return; } if (type.equals(this.parentMaterial)) { - MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_SAME_TYPE_NEW().send(player); + MsgUI.INSTANCE.getUNIT_REPAIR_NEW_ELEMENT_SAME_TYPE().send(player); return; } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/CustomRecipeSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/CustomRecipeSubSettingGui.java index 9db6d622..83159d04 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/CustomRecipeSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/CustomRecipeSubSettingGui.java @@ -19,6 +19,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.ItemSettingGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe; import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager; import xyz.alexcrea.cuanvil.util.CasedStringUtil; @@ -36,7 +37,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { public CustomRecipeSubSettingGui( @NotNull CustomRecipeConfigGui parent, @NotNull AnvilCustomRecipe anvilRecipe) { - super(4, "§e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " §8Config"); + super(4, CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString())); this.parent = parent; this.anvilRecipe = anvilRecipe; @@ -73,19 +74,19 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { ItemMeta deleteMeta = deleteItem.getItemMeta(); assert deleteMeta != null; - deleteMeta.setDisplayName("§4DELETE RECIPE"); - deleteMeta.setLore(Collections.singletonList("§cCaution with this button !")); + deleteMeta.setDisplayName("§4DELETE RECIPE");//TODO MESSAGE + deleteMeta.setLore(Collections.singletonList("§cCaution with this button !"));//TODO MESSAGE deleteItem.setItemMeta(deleteMeta); this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance)); // Displayed item will be updated later IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE(); - this.exactCountFactory = new BoolSettingsGui.BoolSettingFactory("§8Exact count ?", this, + this.exactCountFactory = new BoolSettingsGui.BoolSettingFactory("§8Exact count ?", this,//TODO MESSAGE ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe + "." + AnvilCustomRecipe.EXACT_COUNT_CONFIG, AnvilCustomRecipe.DEFAULT_EXACT_COUNT_CONFIG); - this.removeExactLinearXpFactory = new BoolSettingsGui.BoolSettingFactory("§8Remove exact linear xp ?", this, + this.removeExactLinearXpFactory = new BoolSettingsGui.BoolSettingFactory("§8Remove exact linear xp ?", this,//TODO MESSAGE ConfigHolder.CUSTOM_RECIPE_HOLDER, this.anvilRecipe + "." + AnvilCustomRecipe.REMOVE_EXACT_XP_CONFIG, AnvilCustomRecipe.DEFAULT_REMOVE_EXACT_XP_CONFIG); @@ -93,18 +94,18 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName("§cRemove exact linear xp ?"); - meta.setLore(Collections.singletonList("§7Not usable if linear cost is 0")); + meta.setDisplayName("§cRemove exact linear xp ?");//TODO MESSAGE + meta.setLore(Collections.singletonList("§7Not usable if linear cost is 0"));//TODO MESSAGE item.setItemMeta(meta); this.noRemoveExactLinearXp = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); - this.levelCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Level Cost", this, + this.levelCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Level Cost", this,//TODO MESSAGE this.anvilRecipe + "." + AnvilCustomRecipe.XP_LEVEL_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, null, costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.DEFAULT_XP_LEVEL_COST_CONFIG, 1, 5, 10); - this.linearXpCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Linear Xp Cost", this, + this.linearXpCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Linear Xp Cost", this,//TODO MESSAGE this.anvilRecipe + "." + AnvilCustomRecipe.LINEAR_XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, null, @@ -117,21 +118,21 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(), "§7Set the left item of the custom craft", - "§7\u25A0 + \u25A1 = \u25A1"); + "§7■ + □ = □");//TODO MESSAGE this.rightItemFactory = new ItemSettingGui.ItemSettingFactory("§eRecipe Right §8Item", this, this.anvilRecipe + "." + AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(), "§7Set the right item of the custom craft", - "§7\u25A1 + \u25A0 = \u25A1"); + "§7□ + ■ = □");//TODO MESSAGE this.resultItemFactory = new ItemSettingGui.ItemSettingFactory("§aRecipe Result §8Item", this, this.anvilRecipe + "." + AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG(), "§7Set the result item of the custom craft", - "§7\u25A1 + \u25A1 = \u25A0"); + "§7□ + □ = ■");//TODO MESSAGE // Now we update the items updateLocal(); @@ -162,8 +163,9 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { return success; }; - return new ConfirmActionGui("§cDelete §e" + CasedStringUtil.snakeToUpperSpacedCase(this.anvilRecipe.toString()) + "§c?", - "§7Confirm that you want to delete this conflict.", + var type = CasedStringUtil.snakeToUpperSpacedCase(this.anvilRecipe.toString()); + return new ConfirmActionGui(MsgUI.INSTANCE.getCUSTOM_RECIPE_ELEMENT_DELETE_TITLE(), type, + MsgUI.INSTANCE.getCUSTOM_RECIPE_ELEMENT_DELETE_DESCRIPTION(), type, this, this.parent, deleteSupplier ); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java index 97bdfcb2..3e109873 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java @@ -24,6 +24,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.MetricsUtil; @@ -41,8 +42,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl public EnchantConflictSubSettingGui( @NotNull EnchantConflictGui parent, @NotNull EnchantConflictGroup enchantConflict) { - super(3, - "§e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " §8Config"); + super(3, CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString())); this.parent = parent; this.enchantConflict = enchantConflict; @@ -71,8 +71,8 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl ItemMeta deleteMeta = deleteItem.getItemMeta(); assert deleteMeta != null; - deleteMeta.setDisplayName("§4DELETE CONFLICT"); - deleteMeta.setLore(Collections.singletonList("§cCaution with this button !")); + deleteMeta.setDisplayName("§4DELETE CONFLICT");//TODO MESSAGE + deleteMeta.setLore(Collections.singletonList("§cCaution with this button !"));//TODO MESSAGE deleteItem.setItemMeta(deleteMeta); this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance)); @@ -80,22 +80,24 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl // Displayed item will be updated later this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), event -> { event.setCancelled(true); + var type = CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()); EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui( - "§e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + "§5", + MsgUI.INSTANCE.getENCHANTMENT_CONFLICT_ELEMENT_ENCHANTMENTS(), type, this, this); enchantGui.show(event.getWhoClicked()); }, CustomAnvil.instance); this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), event -> { event.setCancelled(true); + var type = CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()); GroupSelectSettingGui enchantGui = new GroupSelectSettingGui( - "§e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + " §3Groups", + MsgUI.INSTANCE.getENCHANTMENT_CONFLICT_ELEMENT_SUB_GROUPS(), type, this, this, 0); enchantGui.show(event.getWhoClicked()); }, CustomAnvil.instance); this.minBeforeActiveSettingFactory = new IntSettingsGui.IntSettingFactory( - "§8Minimum enchantment count", + "§8Minimum enchantment count",//TODO MESSAGE this, this.enchantConflict + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER, Arrays.asList( "§7Minimum enchantment count set to X mean only X enchantment can be put", @@ -137,8 +139,9 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl return success; }; - return new ConfirmActionGui("§cDelete §e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + "§c?", - "§7Confirm that you want to delete this conflict.", + var type = CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()); + return new ConfirmActionGui(MsgUI.INSTANCE.getENCHANTMENT_CONFLICT_ELEMENT_DELETE_TITLE(), type, + MsgUI.INSTANCE.getENCHANTMENT_CONFLICT_ELEMENT_DELETE_DESCRIPTION(), type, this, this.parent, deleteSupplier ); } @@ -159,12 +162,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl // Prepare enchantment lore ArrayList enchantLore = new ArrayList<>(); - enchantLore.add("§7Allow you to select a list of §5Enchantments §7that this conflict should include"); + enchantLore.add("§7Allow you to select a list of §5Enchantments §7that this conflict should include");//TODO MESSAGE Set enchants = getSelectedEnchantments(); if (enchants.isEmpty()) { - enchantLore.add("§7There is no included enchantment for this conflict."); + enchantLore.add("§7There is no included enchantment for this conflict.");//TODO MESSAGE } else { - enchantLore.add("§7List of included enchantment for this conflict:"); + enchantLore.add("§7List of included enchantment for this conflict:");//TODO MESSAGE Iterator enchantIterator = enchants.iterator(); boolean greaterThanMax = enchants.size() > 5; @@ -175,7 +178,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl enchantLore.add("§7- §5" + formattedName); } if (greaterThanMax) { - enchantLore.add("§7And " + (enchants.size() - 4) + " more..."); + enchantLore.add("§7And " + (enchants.size() - 4) + " more...");//TODO MESSAGE } } @@ -188,7 +191,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl ItemMeta enchantMeta = enchantItem.getItemMeta(); assert enchantMeta != null; - enchantMeta.setDisplayName("§aSelect included §5Enchantments §aSettings"); + enchantMeta.setDisplayName("§aSelect included §5Enchantments §aSettings");//TODO MESSAGE enchantMeta.setLore(enchantLore); enchantItem.setItemMeta(enchantMeta); @@ -200,7 +203,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl ItemMeta groupMeta = groupItem.getItemMeta(); assert groupMeta != null; - groupMeta.setDisplayName("§aSelect Excluded §3Groups §aSettings"); + groupMeta.setDisplayName("§aSelect Excluded §3Groups §aSettings");//TODO MESSAGE groupMeta.setLore(groupLore); groupItem.setItemMeta(groupMeta); @@ -208,7 +211,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl this.groupSettingItem.setItem(groupItem); // Just in case this.pane.bindItem('M', this.minBeforeActiveSettingFactory.getItem(Material.COMMAND_BLOCK, - "Minimum Enchantment Count")); + "Minimum Enchantment Count"));//TODO MESSAGE update(); } @@ -246,7 +249,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl @Override public boolean setSelectedEnchantments(Set enchantments) { if (!this.shouldWork) { - CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed"); + CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed");//TODO MESSAGE return false; } @@ -264,7 +267,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl try { updateGuiValues(); } catch (Exception e) { - CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict, e); + CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict, e);//TODO MESSAGE MetricsUtil.INSTANCE.trackError(e); } @@ -291,7 +294,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl @Override public boolean setSelectedGroups(Set groups) { if (!this.shouldWork) { - CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed"); + CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed");//TODO MESSAGE return false; } @@ -309,7 +312,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl try { updateGuiValues(); } catch (Exception e) { - CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict, e); + CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict, e);//TODO MESSAGE MetricsUtil.INSTANCE.trackError(e); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/GroupConfigSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/GroupConfigSubSettingGui.java index d26c33fe..be841d09 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/GroupConfigSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/GroupConfigSubSettingGui.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil; import xyz.alexcrea.cuanvil.group.*; import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer; import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer; @@ -20,11 +21,11 @@ import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui; import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui; import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.MaterialSelectSettingGui; -import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.util.CasedStringUtil; +import xyz.alexcrea.cuanvil.util.ComponentUtil; import java.util.*; import java.util.function.Consumer; @@ -40,8 +41,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen public GroupConfigSubSettingGui( @NotNull GroupConfigGui parent, @NotNull IncludeGroup group) { - super(3, - "§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rConfig"); + super(3, CasedStringUtil.snakeToUpperSpacedCase(group.getName())); this.parent = parent; this.group = group; @@ -66,38 +66,60 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen ItemStack deleteItem = new ItemStack(Material.RED_TERRACOTTA); ItemMeta deleteMeta = deleteItem.getItemMeta(); - deleteMeta.setDisplayName("§4DELETE GROUP"); - deleteMeta.setLore(Collections.singletonList("§cCaution with this button !")); + assert deleteMeta != null; + PlatformUtil.INSTANCE.setComponentDisplayName( + deleteMeta, + MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_BUTTON_NAME().formattedConcatenated(), + null + ); + ComponentUtil.INSTANCE.applyLore( + MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_BUTTON_LORE().formatted(), + deleteMeta + ); deleteItem.setItemMeta(deleteMeta); this.pane.bindItem('D', new GuiItem(deleteItem, openGuiAndCheckAction(), CustomAnvil.instance)); // Displayed item will be updated later - String materialSelectionName = "§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rMaterials"; + var materialSelectionName = MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_SELECTED_MATERIALS(); + var name = CasedStringUtil.snakeToUpperSpacedCase(group.getName()); + ItemStack selectItem = new ItemStack(Material.DIAMOND_SWORD); ItemMeta selectItemMeta = selectItem.getItemMeta(); - selectItemMeta.setDisplayName(materialSelectionName); + assert selectItemMeta != null; + + PlatformUtil.INSTANCE.setComponentDisplayName( + selectItemMeta, + materialSelectionName.formattedConcatenated(name), + null + ); selectItem.setItemMeta(selectItemMeta); this.materialSelection = new GuiItem(selectItem, (event) -> { event.setCancelled(true); MaterialSelectSettingGui selectGui = new MaterialSelectSettingGui(this, - materialSelectionName + materialSelectionName, name , this); selectGui.show(event.getWhoClicked()); }, CustomAnvil.instance); - String selectGroupName = "§e" + CasedStringUtil.snakeToUpperSpacedCase(this.group.getName()) + " §rGroups"; + var selectGroupName = MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_SELECTED_SUB_GROUPS(); ItemStack selectGroup = new ItemStack(Material.CHEST); ItemMeta selectGroupMeta = selectGroup.getItemMeta(); - selectGroupMeta.setDisplayName(selectGroupName); + assert selectGroupMeta != null; + + PlatformUtil.INSTANCE.setComponentDisplayName( + selectGroupMeta, + selectGroupName.formattedConcatenated(name), + null + ); selectGroup.setItemMeta(selectGroupMeta); this.groupSelection = new GuiItem(selectGroup, (event) -> { event.setCancelled(true); GroupSelectSettingGui enchantGui = new GroupSelectSettingGui( - selectGroupName, + selectGroupName, name, this, this, 0); enchantGui.show(event.getWhoClicked()); }, CustomAnvil.instance); @@ -152,8 +174,9 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen return success; }; - return new ConfirmActionGui("§cDelete §e" + CasedStringUtil.snakeToUpperSpacedCase(this.group.toString()) + "§c?", - "§7Confirm that you want to delete this group.", + var type = CasedStringUtil.snakeToUpperSpacedCase(this.group.toString()); + return new ConfirmActionGui(MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_TITLE(), type, + MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_DESCRIPTION(), type, this, this.parent, deleteSupplier ); } @@ -226,7 +249,8 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen ItemStack matSelectItem = this.materialSelection.getItem(); ItemMeta matSelectMeta = matSelectItem.getItemMeta(); - matSelectMeta.setDisplayName("§aSelect included §eMaterials §aSettings"); + assert matSelectMeta != null; + matSelectMeta.setDisplayName("§aSelect included §eMaterials §aSettings");//TODO MESSAGE matSelectMeta.setLore(matLore); matSelectMeta.addItemFlags(ItemFlag.values()); @@ -238,7 +262,8 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen ItemStack groupSelectItem = this.groupSelection.getItem(); ItemMeta groupSelectMeta = groupSelectItem.getItemMeta(); - groupSelectMeta.setDisplayName("§aSelect included §3Groups §aSettings"); + assert groupSelectMeta != null; + groupSelectMeta.setDisplayName("§aSelect included §3Groups §aSettings");//TODO MESSAGE groupSelectMeta.setLore(groupLore); groupSelectItem.setItemMeta(groupSelectMeta); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/MappedToListSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/MappedToListSubSettingGui.java index 1d867812..935e8671 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/MappedToListSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/MappedToListSubSettingGui.java @@ -1,18 +1,18 @@ package xyz.alexcrea.cuanvil.gui.config.list.elements; -import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; +import xyz.alexcrea.cuanvil.lang.MsgUI; public abstract class MappedToListSubSettingGui extends ChestGui implements ValueUpdatableGui, ElementMappedToListGui { protected MappedToListSubSettingGui( int rows, - @NotNull String title) { - super(rows, title, CustomAnvil.instance); + @NotNull String type) { + super(rows, MsgUI.INSTANCE.getSHARED_TYPED_CONFIG_TITLE().textHolder(type), CustomAnvil.instance); } @Override diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java index 4473eb29..54251a61 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java @@ -20,6 +20,7 @@ import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer; import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.util.CasedStringUtil; import java.util.*; @@ -35,8 +36,10 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui(enchantContainer.getSelectedEnchantments()); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/GroupSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/GroupSelectSettingGui.java index 578ca89e..2db12c20 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/GroupSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/GroupSelectSettingGui.java @@ -19,6 +19,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer; import xyz.alexcrea.cuanvil.gui.config.list.ElementListConfigGui; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.util.CasedStringUtil; import java.util.Collections; @@ -34,8 +35,10 @@ public class GroupSelectSettingGui extends AbstractSettingGui { Set selectedGroups; - public GroupSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectGroupContainer groupContainer, int page) { - super(6, title, parent); + public GroupSelectSettingGui( + @NotNull Message title, @NotNull String param, + ValueUpdatableGui parent, SelectGroupContainer groupContainer, int page) { + super(6, title.textHolder(param), parent); this.groupContainer = groupContainer; //Not used but planned this.page = page; diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java index 0f5759e0..102e1c9f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java @@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; +import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil; @@ -38,9 +39,10 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui { removeMaterial(material); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt index 5e9276d3..640ae297 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt @@ -1,5 +1,7 @@ package xyz.alexcrea.cuanvil.lang +import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder import io.delilaheve.CustomAnvil import net.kyori.adventure.text.Component import org.bukkit.command.CommandSender @@ -22,6 +24,7 @@ open class Message(val key: String, vararg val params: String) { for(i in 0 until min(params.size, values.size)) { val key = params[i] val replacement = values[i].toString() + if(replacement.isEmpty()) continue //May not be good but can be changed if cause an issue var current = 0 while(true) { @@ -77,9 +80,11 @@ open class Message(val key: String, vararg val params: String) { result.add(MiniMessageUtil.mm.deserialize(stb.toString())) } + if(result.isEmpty()) return listOf(Component.text(key)) return result } + // return a list of AT LEAST 1 element. calling first is safe fun formatted(vararg params: Any): List { val section = Lang.getSection(key) if(section != null) return formattedMultiline(section, *params) @@ -89,6 +94,21 @@ open class Message(val key: String, vararg val params: String) { return listOf(MiniMessageUtil.mm.deserialize(translated)) } + fun formattedConcatenated(vararg params: Any): Component { + val formated = formatted(*params) + + var result = formated.first() + for(i in 1 until formated.size) { + result = result.appendNewline().append(formated[i]) + } + + return result + } + + fun textHolder(vararg params: Any): TextHolder { + return ComponentHolder.of(formattedConcatenated(*params)) + } + fun legacy(vararg params: Any): String { val formated = formatted(*params) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt index c144f1fc..c11456be 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt @@ -5,6 +5,7 @@ import xyz.alexcrea.cuanvil.lang.UIMessage as Message object MsgUI { val SHARED_CONFIG_NO_EDIT_PERM = Message("shared.no-permission") + val SHARED_TYPED_CONFIG_TITLE = Message("shared.typed-config-title", "type") val CONFIRM_ACTION_FAILED = Message("confirm-action.fail") @@ -12,10 +13,44 @@ object MsgUI { val ELEMENT_LIST_CANCELLED_NEW = Message("element-list.cancelled-new", "type") val ELEMENT_LIST_DUPLICATED_NEW = Message("element-list.duplicated-new", "type") - val UNIT_REPAIR_ELEMENT_TITLE = Message("unit-repair.element.title") - val UNIT_REPAIR_ELEMENT_DESCRIPTION = Message("unit-repair.element.description") - val UNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW = Message("unit-repair.element.cannot-damage-new") - val UNIT_REPAIR_ELEMENT_SAME_TYPE_NEW = Message("unit-repair.element.same-type-new") + val UNIT_REPAIR_TITLE = Message("unit-repair.title") + val UNIT_REPAIR_ELEMENT_TITLE = Message("unit-repair.element_title") + val UNIT_REPAIR_NEW_TITLE = Message("unit-repair.new.title") + val UNIT_REPAIR_NEW_DESCRIPTION = Message("unit-repair.new.description") + val UNIT_REPAIR_NEW_ELEMENT_TITLE = Message("unit-repair.element.new.title", "name") + val UNIT_REPAIR_NEW_ELEMENT_DESCRIPTION = Message("unit-repair.element.new.description", "name") + val UNIT_REPAIR_NEW_ELEMENT_CANNOT_REPAIR = Message("unit-repair.element.new.cannot-damage") + val UNIT_REPAIR_NEW_ELEMENT_SAME_TYPE = Message("unit-repair.element.new.same-type") + + val CUSTOM_RECIPE_TITLE = Message("custom-recipe.title") + + val CUSTOM_RECIPE_ELEMENT_DELETE_TITLE = Message("custom-recipe.element.delete.title", "type") + val CUSTOM_RECIPE_ELEMENT_DELETE_DESCRIPTION = Message("custom-recipe.element.delete.description", "type") + + val ENCHANTMENT_LEVEL_COST_TITLE = Message("enchant-level-cost.title") + + val ENCHANTMENT_LEVEL_LIMIT_TITLE = Message("enchant-level-limit.title") + + val ENCHANTMENT_MERGE_LIMIT_TITLE = Message("enchant-merge-limit.title") + + val ENCHANTMENT_CONFLICT_TITLE = Message("enchant-conflict.title") + val ENCHANTMENT_CONFLICT_ELEMENT_ENCHANTMENTS = Message("enchant-conflict.element.selected-enchantments", "group") + val ENCHANTMENT_CONFLICT_ELEMENT_SUB_GROUPS = Message("enchant-conflict.element.selected-sub-groups", "group") + + val ENCHANTMENT_CONFLICT_ELEMENT_DELETE_TITLE = Message("enchant-conflict.element.delete.title", "type") + val ENCHANTMENT_CONFLICT_ELEMENT_DELETE_DESCRIPTION = Message("enchant-conflict.element.delete.description", "type") + + val MATERIAL_GROUP_TITLE = Message("material-group.title") + val MATERIAL_GROUP_ELEMENT_SELECTED_MATERIALS = Message("material-group.element.selected-materials", "group") + val MATERIAL_GROUP_ELEMENT_SELECTED_SUB_GROUPS = Message("material-group.element.selected-sub-groups", "group") + + val MATERIAL_GROUP_ELEMENT_DELETE_TITLE = Message("material-group.element.delete.title", "type") + val MATERIAL_GROUP_ELEMENT_DELETE_DESCRIPTION = Message("material-group.element.delete.description", "type") + val MATERIAL_GROUP_ELEMENT_DELETE_BUTTON_NAME = Message("material-group.element.delete.button.name") + val MATERIAL_GROUP_ELEMENT_DELETE_BUTTON_LORE = Message("material-group.element.delete.button.lore") + + val MATERIAL_SELECT_CONFIRM_TITLE = Message("material-select.confirm.title","name") + val MATERIAL_SELECT_CONFIRM_DESCRIPTION = Message("material-select.confirm.description","name") } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt index 2d9ec351..76bc7287 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt @@ -2,10 +2,28 @@ package xyz.alexcrea.cuanvil.util import net.kyori.adventure.text.Component import org.bukkit.command.CommandSender +import org.bukkit.inventory.meta.ItemMeta import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.sendPaperMessage +import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.setPaperLore object ComponentUtil { + fun Component.serializeMM(): String { + return MiniMessageUtil.mm.serialize(this) + } + + fun Component.serializeMMColor(): String { + return MiniMessageUtil.color_only_mm.serialize(this) + } + + fun Component.serializeLegacy(): String { + return MiniMessageUtil.legacy_mm.serialize(this) + } + + fun Component.serializePlain(): String { + return MiniMessageUtil.plain_text_mm.serialize(this) + } + fun Component.send(destination: CommandSender) { if(!destination.sendPaperMessage(this)) destination.sendMessage(this.serializeLegacy()) @@ -16,18 +34,9 @@ object ComponentUtil { component.send(destination) } - fun Component.serializeMM(): String { - return MiniMessageUtil.mm.serialize(this) + fun List.applyLore(meta: ItemMeta) { + if(!meta.setPaperLore(this)) + meta.lore = this.map {obj -> obj.serializeLegacy()} } - fun Component.serializeMMColor(): String { - return MiniMessageUtil.color_only_mm.serialize(this) - } - fun Component.serializeLegacy(): String { - return MiniMessageUtil.legacy_mm.serialize(this) - } - fun Component.serializePlain(): String { - return MiniMessageUtil.plain_text_mm.serialize(this) - } - } \ No newline at end of file diff --git a/src/main/resources/lang/en.yml b/src/main/resources/lang/en.yml index 75483d16..c6d043a9 100644 --- a/src/main/resources/lang/en.yml +++ b/src/main/resources/lang/en.yml @@ -24,6 +24,7 @@ error: listeners: "error registering listeners" enchant-system: "error initializing enchantment system" non-default-config: "Plugin has an issue while trying to load non default config... exiting..." + reload: resource: fail: "Resource %path Could not be loaded or reloaded." @@ -37,11 +38,13 @@ command: no-permission: "No permission to execute this command" warning: missing-subcmd: "Need to specify a subcommand. for example %example1 or %example2" + root: warning: unknown-sub: "Invalid subcommand. run `%command help` to see available commands" error: generic: "Error running this command" + debug: description: "Used to toggle debug logs and retrieve them" log-cleared: "Log Cleared" @@ -54,10 +57,12 @@ command: unspecified-type: "Need to specify which type of debug to toggle: \"default\" or \"verbose\"" invalid-type: "Invalid debug type \"%type\"" no-log: "No log to show ? make sure you tried with debug log toggled (%command)" + diagnostic: description: "Basic diagnostic of this plugin" had-error: "There was an error running the diagnostic" copy: "Click to copy diagnostic data" + config: description: "Used to edit the configuration of the plugin" folia-issue: @@ -72,6 +77,7 @@ command: warning: legacy-name: "/ca gui has been moved to /ca config" cannot_configure: "Cannot configure the item in hand" + enchant: description: "Allows to set enchantment to holden item" warning: @@ -81,9 +87,11 @@ command: cannot_enchant: "Cannot enchant this item" removed: "%name removed" set: "%name set to level %level" + help: description: "Help command" header: "List of available commands:" + reload: description: "Reload the configuration of this plugin" start: "Reloading config..." @@ -94,19 +102,74 @@ command: config-ui: shared: no-permission: "You do not have permission to edit the config" + typed-config-title: "%type Config" + confirm-action: fail: "Action could not be completed." + element-list: instruction-new: 1: "Write the %type name you want to create in the chat." 2: "Or write cancel to go back to %type config menu" cancelled-new: "%type creation cancelled..." duplicated-new: "Please enter a %type name that do not already exist..." + unit-repair: - element: - title: "Select item to be repaired." + tile: "Unit Repair Config" + new: + title: "Select unit repair item." description: 1: "Click here with an item to set the item" - 2: "You like to be repaired by %name" - cannot-damage-new: "This item can't be damaged, so it can't be repaired." - same-type-new: "Item can't repair something of the same type." \ No newline at end of file + 2: "You like to be an unit repair item" + element: + title: "%type Unit repair" + new: + title: "Select item to be repaired." + description: + 1: "Click here with an item to set the item" + 2: "You like to be repaired by %name" + cannot-damage: "This item can't be damaged, so it can't be repaired." + same-type: "Item can't repair something of the same type." + + custom-recipe: + title: "Custom Recipe Config" + element: + delete: + title: "Delete %type?" + description: "Confirm that you want to delete this recipe." + + enchant-level-cost: + title: "Enchantment Level Limit" + + enchant-level-limit: + title: "Enchantment Level Limit" + + enchant-merge-limit: + title: "Enchantment Maximum Merge Level" + + enchant-conflict: + title: "Conflict Config" + element: + selected-enchantments: "%group" # likely need page and max page + selected-sub-groups: "%group Groups" + delete: + title: "Delete %type?" + description: "Confirm that you want to delete this conflict." + + material-group: + title: "Group Config" + element: + selected-materials: "%group Materials" + selected-sub-groups: "%group Groups" + delete: + title: "Delete %type?" + description: "Confirm that you want to delete this group." + button: + name: "DELETE GROUP" + lore: "Caution with this button !" + + material-select: + new: + confirm: + title: "Remove %name" + description: "Confirm Remove %name from this list."