diff --git a/build.gradle.kts b/build.gradle.kts index 2b603a7d..4ce228f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ plugins { } group = "xyz.alexcrea" -version = "2.1.0" +version = "2.0.2" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" 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 d7913020..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 @@ -15,12 +15,9 @@ import xyz.alexcrea.cuanvil.lang.Message; public abstract class AbstractAskGui extends ChestGui { protected PatternPane pane; - - AbstractAskGui( - int rows, - @NotNull Message name, @NotNull String param, - Gui backOnCancel - ) { + AbstractAskGui(int rows, + @NotNull Message name, @NotNull String param, + Gui backOnCancel){ super(rows, name.textHolder(param), CustomAnvil.instance); Pattern pattern = getGuiPattern(); 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 d98cc399..b570e1d5 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 @@ -23,12 +23,10 @@ import java.util.logging.Level; public class ConfirmActionGui extends AbstractAskGui { - public ConfirmActionGui( - @NotNull Message title, @NotNull String titleParam, - @Nullable Message actionDescription, @NotNull String actionParam, - Gui backOnCancel, Gui backOnConfirm, Supplier onConfirm, - boolean permanent - ) { + 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, titleParam, backOnCancel); // Save item @@ -73,11 +71,9 @@ public class ConfirmActionGui extends AbstractAskGui { pane.bindItem('I', new GuiItem(infoItem, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); } - public ConfirmActionGui( - @NotNull Message title, @NotNull String titleParam, - @Nullable Message actionDescription, @NotNull String actionParam, - Gui backOnCancel, Gui backOnConfirm, Supplier onConfirm - ){ + public ConfirmActionGui(@NotNull Message title, @NotNull String titleParam, + @Nullable Message actionDescription, @NotNull String actionParam, + Gui backOnCancel, Gui backOnConfirm, Supplier onConfirm){ 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 c3f52388..fc96c282 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 @@ -22,7 +22,6 @@ import java.util.function.BiConsumer; public class SelectItemTypeGui extends AbstractAskGui { private ItemStack selectedItem; - public SelectItemTypeGui(@NotNull Message title, @NotNull String titleParam, @NotNull Message actionDescription, @@ -38,7 +37,7 @@ public class SelectItemTypeGui extends AbstractAskGui { event.setCancelled(true); HumanEntity player = event.getWhoClicked(); - if(!player.hasPermission(CustomAnvil.editConfigPermission)) { + if (!player.hasPermission(CustomAnvil.editConfigPermission)) { player.closeInventory(); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player); return; @@ -60,9 +59,9 @@ public class SelectItemTypeGui extends AbstractAskGui { if(MaterialUtil.INSTANCE.isAir(cursor)) return; ItemStack finalItem; - if(materialOnly) { + if(materialOnly){ finalItem = setDisplayMeta(new ItemStack(cursor.getType()), actionDescription, descriptionParam); - } else { + }else{ finalItem = cursor.clone(); } this.selectedItem = finalItem.clone(); @@ -86,7 +85,7 @@ public class SelectItemTypeGui extends AbstractAskGui { @NotNull ItemStack item, @NotNull Message actionDescription, @NotNull String param - ) { + ){ ItemMeta meta = item.getItemMeta(); assert meta != null; 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 f2ee0529..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 @@ -21,7 +21,7 @@ import java.util.function.Consumer; * * @param Type of the factory of the type of setting the gui should edit. */ -public abstract class AbstractEnchantConfigGui extends SettingGuiListConfigGui { +public abstract class AbstractEnchantConfigGui extends SettingGuiListConfigGui{ /** * Constructor for a gui displaying available enchantment to edit a enchantment setting. @@ -47,7 +47,7 @@ public abstract class AbstractEnchantConfigGui getCreateItemLore() { return Collections.emptyList(); } - @Override protected Consumer getCreateClickConsumer() { return null; diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java index 149a4aa0..51936c7e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java @@ -14,6 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil; import xyz.alexcrea.cuanvil.dependency.packet.PacketManager; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; @@ -23,11 +24,10 @@ import xyz.alexcrea.cuanvil.gui.config.settings.WorkPenaltyTypeSettingGui; 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 java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; /** * Global config to edit basic basic settings. @@ -42,12 +42,11 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { } private final PacketManager packetManager; - /** * Constructor of this Global gui for basic settings. */ public BasicConfigGui(PacketManager packetManager) { - super(4, MsgUI.INSTANCE.getBASIC_TITLE().textHolder(), CustomAnvil.instance); + super(4, "§8Basic Config", CustomAnvil.instance); if(INSTANCE == null) INSTANCE = this; this.packetManager = packetManager; @@ -102,60 +101,61 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { */ protected void prepareValues() { // cap anvil cost - this.capAnvilCost = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_CAP_ANVIL_COST_TITLE(), this, + this.capAnvilCost = new BoolSettingsGui.BoolSettingFactory("§8Cap Anvil Cost ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.CAP_ANVIL_COST, ConfigOptions.DEFAULT_CAP_ANVIL_COST, - null, MsgUI.INSTANCE.getBASIC_CAP_ANVIL_COST_DESCRIPTION() - ); + "§7All anvil cost will be capped to §aMax Anvil Cost§7 if enabled.", + "§7In other words:", + "§7For any anvil cost greater than §aMax Anvil Cost§7, Cost will be set to §aMax Anvil Cost§7."); // cap anvil cost not needed ItemStack item = new ItemStack(Material.BARRIER); ItemMeta meta = item.getItemMeta(); assert meta != null; - ComponentUtil.INSTANCE.setMessageName(meta, MsgUI.INSTANCE.getBASIC_CAP_ANVIL_COST_DISABLED_TITLE()); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getBASIC_CAP_ANVIL_COST_DISABLED_DESCRIPTION().formatted(), meta); - + meta.setDisplayName("§cCap Anvil Cost ?"); + meta.setLore(Collections.singletonList("§7This config only work if §cLimit Repair Cost§7 is disabled.")); item.setItemMeta(meta); this.noCapRepairItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); // repair cost item IntRange range = ConfigOptions.MAX_ANVIL_COST_RANGE; - this.maxAnvilCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_MAX_ANVIL_COST_TITLE(), this, + this.maxAnvilCost = new IntSettingsGui.IntSettingFactory("§8Max Anvil Cost", this, ConfigOptions.MAX_ANVIL_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_MAX_ANVIL_COST_DESCRIPTION(), + Arrays.asList( + "§7Max cost the Anvil can get to.", + "§7Valid values include §e0 §7to §e1000§7.", + "§7Cost will be displayed as §cToo Expensive§7:", + "§7- If Cost is above §e39", + "§7- And §eReplace Too Expensive§7 is disabled" + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_MAX_ANVIL_COST, - 1, 5, 10 - ); + 1, 5, 10); // max anvil cost not needed item = new ItemStack(Material.BARRIER); meta = item.getItemMeta(); assert meta != null; - ComponentUtil.INSTANCE.setMessageName(meta, MsgUI.INSTANCE.getBASIC_MAX_ANVIL_COST_DISABLED_TITLE()); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getBASIC_MAX_ANVIL_COST_DISABLED_DESCRIPTION().formatted(), meta); + meta.setDisplayName("§cMax Anvil Cost"); + meta.setLore(Collections.singletonList("§7This config only work if §cLimit Repair Cost§7 is disabled.")); item.setItemMeta(meta); this.noMaxCostItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); // remove repair limit item - this.removeAnvilCostLimit = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_REMOVE_COST_LIMIT_TITLE(), this, + this.removeAnvilCostLimit = new BoolSettingsGui.BoolSettingFactory("§8Remove Anvil Cost Limit ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.REMOVE_ANVIL_COST_LIMIT, ConfigOptions.DEFAULT_REMOVE_ANVIL_COST_LIMIT, - null, MsgUI.INSTANCE.getBASIC_REMOVE_COST_LIMIT_DESCRIPTION() - ); + "§7Whether the anvil's cost limit should be removed entirely.", + "§7The anvil will still visually display §cToo Expensive§7 if §eReplace Too Expensive§7 is disabled.", + "§7However, the action will be completable if xp requirement is meet."); // replace too expensive item - this.replaceTooExpensive = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_REPLACE_TOO_EXPENSIVE_TITLE(), this, + this.replaceTooExpensive = new BoolSettingsGui.BoolSettingFactory("§8Replace Too Expensive ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.REPLACE_TOO_EXPENSIVE, ConfigOptions.DEFAULT_REPLACE_TOO_EXPENSIVE, - null, getReplaceToExpensiveLore() - ); + getReplaceToExpensiveLore()); // ------------ // Cost config @@ -163,118 +163,132 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // item repair cost range = ConfigOptions.REPAIR_COST_RANGE; - this.itemRepairCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_ITEM_REPAIR_COST_TITLE(), this, + this.itemRepairCost = new IntSettingsGui.IntSettingFactory("§8Item Repair Cost", this, ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_ITEM_REPAIR_COST_DESCRIPTION(), + Arrays.asList( + "§7XP Level amount added to the anvil when the item", + "§7is repaired by another item of the same type." + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_ITEM_REPAIR_COST, - 1, 5, 10, 50, 100 - ); + 1, 5, 10, 50, 100); // unit repair cost - this.unitRepairCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_UNIT_REPAIR_COST_TITLE(), this, + this.unitRepairCost = new IntSettingsGui.IntSettingFactory("§8Unit Repair Cost", this, ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_UNIT_REPAIR_COST_DESCRIPTION(), + Arrays.asList( + "§7XP Level amount added to the anvil when the item is repaired by an §eunit§7.", + "§7For example: a Diamond on a Diamond Sword.", + "§7What's considered unit for what can be edited on the unit repair configuration." + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_UNIT_REPAIR_COST, - 1, 5, 10, 50, 100 - ); + 1, 5, 10, 50, 100); // item rename cost range = ConfigOptions.ITEM_RENAME_COST_RANGE; - this.itemRenameCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_ITEM_RENAME_COST_TITLE(), this, + this.itemRenameCost = new IntSettingsGui.IntSettingFactory("§8Rename Cost", this, ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_ITEM_RENAME_COST_DESCRIPTION(), + Arrays.asList( + "§7XP Level amount added to the anvil when the item is renamed." + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_ITEM_RENAME_COST, - 1, 5, 10, 50, 100 - ); + 1, 5, 10, 50, 100); // sacrifice illegal enchant cost range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE; - this.sacrificeIllegalEnchantCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_SACRIFICE_ILLEGAL_COST_TITLE(), this, + this.sacrificeIllegalEnchantCost = new IntSettingsGui.IntSettingFactory("§8Sacrifice Illegal Enchant Cost", this, ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_SACRIFICE_ILLEGAL_COST_DESCRIPTION(), + Arrays.asList( + "§7XP Level amount added to the anvil when a sacrifice enchantment", + "§7conflict With one of the left item enchantment" + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST, - 1, 5, 10, 50, 100 - ); + 1, 5, 10, 50, 100); // ------------- // Color config // ------------- // Allow us of color code - this.allowColorCode = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_COLOR_CODE_LIMIT_TITLE(), this, + this.allowColorCode = new BoolSettingsGui.BoolSettingFactory("§8Allow Use Of Color Code ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.ALLOW_COLOR_CODE, ConfigOptions.DEFAULT_ALLOW_COLOR_CODE, - null, MsgUI.INSTANCE.getBASIC_COLOR_CODE_LIMIT_DESCRIPTION() - ); + "§7Whether players can use color code.", + "§7Color code a formatted like §a&a§7 and is used in the rename field of the anvil.", + "§7Player may need permission to use color code if §ePlayer need permission to use color§7 is enabled."); // Allow us of hexadecimal color - this.allowHexColor = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_COLOR_HEX_LIMIT_TITLE(), this, + this.allowHexColor = new BoolSettingsGui.BoolSettingFactory("§8Allow Use Of Hexadecimal Color ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.ALLOW_HEXADECIMAL_COLOR, ConfigOptions.DEFAULT_ALLOW_HEXADECIMAL_COLOR, - null, MsgUI.INSTANCE.getBASIC_COLOR_HEX_LIMIT_DESCRIPTION() - ); + "§7Whether players can use hexadecimal color.", + "§7Color code a formatted like §2#012345 §7and is used in the rename field of the anvil.", + "§7Player may need permission to use color code if §ePermission Needed For Color§7 is enabled."); // Permission needed for color - this.permissionNeededForColor = new BoolSettingsGui.BoolSettingFactory( - MsgUI.INSTANCE.getBASIC_COLOR_PERMISSION_TITLE(), this, + this.permissionNeededForColor = new BoolSettingsGui.BoolSettingFactory("§8Need Permission To Use Color ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.PERMISSION_NEEDED_FOR_COLOR, ConfigOptions.DEFAULT_PERMISSION_NEEDED_FOR_COLOR, - null, MsgUI.INSTANCE.getBASIC_COLOR_PERMISSION_DESCRIPTION() - ); + "§7Whether players should have permission to be able to use colors.", + "§7Give player §eca.color.code§7 Permission to allow use of color code.", + "§7Give player §eca.color.hex§7 Permission to allow use of hexadecimal color."); // Permission needed for color not necessary item = new ItemStack(Material.BARRIER); meta = item.getItemMeta(); assert meta != null; - ComponentUtil.INSTANCE.setMessageName(meta, MsgUI.INSTANCE.getBASIC_COLOR_PERMISSION_DISABLED_TITLE()); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getBASIC_COLOR_PERMISSION_DISABLED_DESCRIPTION().formatted(), meta); + meta.setDisplayName("§cNeed Permission To Use Color ?"); + meta.setLore(Arrays.asList("§7This config can do something only if one of the following config is enabled:", + "§7- §aAllow Use Of Color Code", + "§7- §aAllow Use Of Hexadecimal Color")); item.setItemMeta(meta); this.noPermissionNeededItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); // Cost of using color range = ConfigOptions.USE_OF_COLOR_COST_RANGE; - this.useOfColorCost = new IntSettingsGui.IntSettingFactory( - MsgUI.INSTANCE.getBASIC_COLOR_COST_TITLE(), this, + this.useOfColorCost = new IntSettingsGui.IntSettingFactory("§8Cost Of Using Color", this, ConfigOptions.USE_OF_COLOR_COST, ConfigHolder.DEFAULT_CONFIG, - MsgUI.INSTANCE.getBASIC_COLOR_COST_DESCRIPTION(), + Arrays.asList( + "§7XP level cost when using color code or hexadecimal color using the anvil.", + "§7conflict With one of the left item enchantment" + ), range.getFirst(), range.getLast(), ConfigOptions.DEFAULT_USE_OF_COLOR_COST, - 1, 5, 10, 50, 100 - ); + 1, 5, 10, 50, 100); // Permission needed for color not necessary item = new ItemStack(Material.BARRIER); meta = item.getItemMeta(); assert meta != null; - ComponentUtil.INSTANCE.setMessageName(meta, MsgUI.INSTANCE.getBASIC_COLOR_COST_DISABLED_TITLE()); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getBASIC_COLOR_COST_DISABLED_DESCRIPTION().formatted(), meta); - + meta.setDisplayName("§cCost Of Using Color"); + meta.setLore(Arrays.asList("§7This config can do something only if one of the following config is enabled:", + "§7- §aAllow Use Of Color Code", + "§7- §aAllow Use Of Hexadecimal Color")); item.setItemMeta(meta); this.noColorCostItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); } @NotNull - private Message[] getReplaceToExpensiveLore() { - ArrayList lore = new ArrayList<>(); - lore.add(MsgUI.INSTANCE.getBASIC_REPLACE_TOO_EXPENSIVE_DESCRIPTION()); + private String[] getReplaceToExpensiveLore() { + ArrayList lore = new ArrayList<>(); + lore.add("§7Whenever anvil cost is above §e39§7 should display the true price and not §cToo Expensive§7."); + lore.add("§7However, when bypassing §cToo Expensive§7, anvil price will be displayed as §aGreen§7."); + lore.add("§7Even if cost is displayed as §aGreen§7:"); + lore.add("§7If the player do not have the required xp level, the action will not be completable."); - if(!this.packetManager.getCanSetInstantBuild()) - lore.add(MsgUI.INSTANCE.getBASIC_REPLACE_TOO_EXPENSIVE_DESCRIPTION_NO_NMS()); + if(!this.packetManager.getCanSetInstantBuild()){ + lore.add(""); + lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a paper server."); + lore.add("§cCurrently ProtocoLib is not detected."); + } - Message[] loreAsArray = new Message[lore.size()]; + String[] loreAsArray = new String[lore.size()]; return lore.toArray(loreAsArray); } @@ -283,14 +297,9 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // limit and cap anvil cost item GuiItem capAnvilCostItem; GuiItem maxAnvilCostItem; - if(!this.removeAnvilCostLimit.getConfiguredValue()) { - capAnvilCostItem = this.capAnvilCost.getItem( - MsgUI.INSTANCE.getBASIC_CAP_ANVIL_COST_ITEM() - ); - maxAnvilCostItem = this.maxAnvilCost.getItem( - Material.EXPERIENCE_BOTTLE, - MsgUI.INSTANCE.getBASIC_MAX_ANVIL_COST_ITEM() - ); + if (!this.removeAnvilCostLimit.getConfiguredValue()) { + capAnvilCostItem = this.capAnvilCost.getItem("Cap Anvil Cost"); + maxAnvilCostItem = this.maxAnvilCost.getItem(Material.EXPERIENCE_BOTTLE, "Max Anvil Cost"); } else { capAnvilCostItem = this.noCapRepairItem; maxAnvilCostItem = this.noMaxCostItem; @@ -300,9 +309,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { pane.bindItem('C', maxAnvilCostItem); // remove repair limit item - GuiItem removeRepairLimitItem = this.removeAnvilCostLimit.getItem( - MsgUI.INSTANCE.getBASIC_REMOVE_COST_LIMIT_ITEM() - ); + GuiItem removeRepairLimitItem = this.removeAnvilCostLimit.getItem("Remove Anvil Cost Limit"); pane.bindItem('R', removeRepairLimitItem); // replace too expensive item @@ -327,11 +334,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { pane.bindItem('S', illegalCostItem); // work penalty type - GuiItem workPenaltyType = WorkPenaltyTypeSettingGui.getDisplayItem( - this, - Material.DAMAGED_ANVIL, - MsgUI.INSTANCE.getBASIC_WORK_PENALTY_ITEM() - ); + GuiItem workPenaltyType = WorkPenaltyTypeSettingGui.getDisplayItem(this, Material.DAMAGED_ANVIL, "§aWork Penalty Type"); pane.bindItem('W', workPenaltyType); // allow color code @@ -343,22 +346,20 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { pane.bindItem('h', allowHexColorItem); // True if player could place color - if(ConfigOptions.INSTANCE.getRenameColorPossible()) { + if(ConfigOptions.INSTANCE.getRenameColorPossible()){ // use permission for color GuiItem permissionNeededItem = this.permissionNeededForColor.getItem(); pane.bindItem('p', permissionNeededItem); // using color cost - GuiItem useColorCostItem = this.useOfColorCost.getItem( - Material.EXPERIENCE_BOTTLE, - MsgUI.INSTANCE.getBASIC_COLOR_COST_ITEM() - ); + GuiItem useColorCostItem = this.useOfColorCost.getItem(Material.EXPERIENCE_BOTTLE, "Use color"); pane.bindItem('P', useColorCostItem); - } else { + }else{ pane.bindItem('p', this.noPermissionNeededItem); pane.bindItem('P', this.noColorCostItem); } + update(); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java index c0c32471..060ff35a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java @@ -61,7 +61,7 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " Custom recipe");//TODO MESSAGE + meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " §fCustom recipe");//TODO MESSAGE meta.addItemFlags(ItemFlag.values()); meta.setLore(getRecipeLore(recipe)); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java index c9938fd5..a531798a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java @@ -2,7 +2,6 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; -import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -12,12 +11,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; -import xyz.alexcrea.cuanvil.lang.Message; import xyz.alexcrea.cuanvil.lang.MsgUI; import xyz.alexcrea.cuanvil.util.CasedStringUtil; -import xyz.alexcrea.cuanvil.util.ComponentUtil; -import java.awt.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -63,10 +59,13 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui lore = new ArrayList<>(); - lore.addAll(MsgUI.INSTANCE.getENCHANTMENT_LEVEL_COST_ELEMENT_ITEM_COST().formatted(itemCost)); - lore.addAll(MsgUI.INSTANCE.getENCHANTMENT_LEVEL_COST_ELEMENT_BOOK_COST().formatted(bookCost)); + List lore = new ArrayList<>(); + lore.add("§7Item Cost: §e" + itemCost); + lore.add("§7Book Cost: §e" + bookCost); - List displayLore = factory.getDisplayLore(); - if (displayLore != null) { - lore.add(Component.empty()); - lore.addAll(ComponentUtil.INSTANCE.asComponents(displayLore, factory.getParam())); + List displayLore = factory.getDisplayLore(); + if (!displayLore.isEmpty()) { + lore.add(""); + lore.addAll(displayLore); } // Edit name and lore - ComponentUtil.INSTANCE.setMessageName(itemMeta, itemName, factory.getParam()); - ComponentUtil.INSTANCE.applyLore(lore, itemMeta); + itemMeta.setDisplayName(itemName); + itemMeta.setLore(lore); item.setItemMeta(itemMeta); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java index e1a2759e..4ed529cf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java @@ -54,10 +54,11 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui getCreateItemLore() { - return Arrays.asList(//TODO MESSAGE + return Arrays.asList( "§7Select a new item to be repairable.", "§7You will be asked the material to use." ); @@ -60,7 +60,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui getCreateClickConsumer() { return event -> { event.setCancelled(true); - if(!this.shouldWork) { + if (!this.shouldWork) { return; } event.setCancelled(true); @@ -73,11 +73,11 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui getEveryInstanceOfGeneric() { Set keys = new HashSet<>(); - if(!this.shouldWork) { + if (!this.shouldWork) { return keys; } @@ -157,10 +155,10 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui keys) { - if(section == null) return; - for(var key : section.getKeys(false)) { + if (section == null) return; + for (var key : section.getKeys(false)) { var material = NamespacedKey.fromString(key); - if(material == null) continue; + if (material == null) continue; keys.add(material); } @@ -168,7 +166,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui valueLore = new ArrayList<>(); - if(holder.displayLore != null){ - valueLore.addAll(ComponentUtil.INSTANCE.asComponents(holder.displayLore)); - valueLore.add(Component.empty()); + ArrayList valueLore = new ArrayList<>(); + if(!holder.displayLore.isEmpty()){ + valueLore.addAll(holder.displayLore); + valueLore.add(""); } - valueLore.addAll(MsgUI.INSTANCE.getSHARED_CLICK_TO_CHANGE().formatted()); + valueLore.add(AbstractSettingGui.CLICK_LORE); ItemStack valueItemStack = new ItemStack(displayedMat); ItemMeta valueMeta = valueItemStack.getItemMeta(); assert valueMeta != null; - valueMeta.setDisplayName(displayedName);//TODO MESSAGE ? - ComponentUtil.INSTANCE.applyLore(valueLore, valueMeta); + valueMeta.setDisplayName(displayedName); + valueMeta.setLore(valueLore); valueItemStack.setItemMeta(valueMeta); - GuiItem resultItem = new GuiItem(valueItemStack, inverseNowConsumer(), CustomAnvil.instance); pane.bindItem('v', resultItem); @@ -172,15 +166,13 @@ public class BoolSettingsGui extends AbstractSettingGui { */ public static class BoolSettingFactory extends SettingGuiFactory { @NotNull - Message title; + String title; @NotNull ValueUpdatableGui parent; boolean defaultVal; - @Nullable - List displayLore; - @Nullable - Object param; + @NotNull + List displayLore; /** * Constructor for a boolean setting gui factory. @@ -193,25 +185,22 @@ public class BoolSettingsGui extends AbstractSettingGui { * @param displayLore Gui display item lore. */ public BoolSettingFactory( - @NotNull Message title, @NotNull ValueUpdatableGui parent, + @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull ConfigHolder config, @NotNull String configPath, - boolean defaultVal, - @Nullable Object param, @Nullable Message... displayLore) { + boolean defaultVal, String... displayLore) { super(configPath, config); this.title = title; this.parent = parent; this.defaultVal = defaultVal; - - this.displayLore = displayLore == null ? null : Arrays.asList(displayLore); - this.param = param; + this.displayLore = Arrays.asList(displayLore); } /** * @return Get setting's gui title. */ @NotNull - public Message getTitle() { + public String getTitle() { return title; } @@ -236,36 +225,25 @@ public class BoolSettingsGui extends AbstractSettingGui { * The item will have its value written in the lore part of the item. * * @param name Name of the item. - * @param params parameters for the given name. * @return A formatted GuiItem that will create and open a GUI for the boolean setting. */ - public GuiItem getItem( - @NotNull Message name, - Object... params - ){ + public GuiItem getItem(String name){ // Get item properties boolean value = getConfiguredValue(); Material itemMat; - Component itemName = name.formattedConcatenated(params); - + StringBuilder itemName = new StringBuilder("§e"); String finalValue; if (value) { itemMat = Material.GREEN_TERRACOTTA; - finalValue = "Yes";//TODO MESSAGE + finalValue = "§aYes"; } else { itemMat = Material.RED_TERRACOTTA; - finalValue = "No";//TODO MESSAGE + finalValue = "§cNo"; } + itemName.append(name); - return GuiGlobalItems.createGuiItemFromProperties( - this, - itemMat, itemName, - finalValue, - this.displayLore, - false, - this.param - ); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, finalValue, this.displayLore, false); } /** @@ -280,7 +258,7 @@ public class BoolSettingsGui extends AbstractSettingGui { // Get item properties String configPath = GuiGlobalItems.getConfigNameFromPath(getConfigPath()); - return getItem(MsgUI.INSTANCE.getSHARED_YELLOW_GET_ITEM(), CasedStringUtil.detectToUpperSpacedCase(configPath)); + return getItem(CasedStringUtil.detectToUpperSpacedCase(configPath)); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java index 1d14a566..c0dcff60 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/DoubleSettingGui.java @@ -5,7 +5,6 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.PatternPane; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import io.delilaheve.CustomAnvil; -import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; @@ -18,10 +17,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; 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.ComponentUtil; import java.math.BigDecimal; import java.math.RoundingMode; @@ -170,7 +166,7 @@ public class DoubleSettingGui extends AbstractSettingGui { ItemMeta resultMeta = resultPaper.getItemMeta(); assert resultMeta != null; - resultMeta.setDisplayName("Value: " + displayValue(now)); + resultMeta.setDisplayName("§fValue: §e" + displayValue(now)); resultPaper.setItemMeta(resultMeta); GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance); @@ -189,12 +185,12 @@ public class DoubleSettingGui extends AbstractSettingGui { private GuiItem getSetValueItem(Material mat, BigDecimal planned, String numberPrefix){ // Create set item lore - ArrayList setLoreItem = new ArrayList<>(); - if(holder.displayLore != null){ - setLoreItem.addAll(holder.displayLore.formatted(holder.param, holder.param2)); - setLoreItem.add(Component.empty()); + ArrayList setLoreItem = new ArrayList<>(); + if(!holder.displayLore.isEmpty()){ + setLoreItem.addAll(holder.displayLore); + setLoreItem.add(""); } - setLoreItem.addAll(MsgUI.INSTANCE.getSHARED_CLICK_TO_CHANGE().formatted()); + setLoreItem.add(AbstractSettingGui.CLICK_LORE); // Create & return set value item ItemStack item = new ItemStack(mat); @@ -203,7 +199,7 @@ public class DoubleSettingGui extends AbstractSettingGui { meta.setDisplayName("§e" + displayValue(now) + " §f-> §e" + displayValue(planned) + " §r(" + numberPrefix + (displayValue(planned.subtract(now).abs()) + "§r)")); - ComponentUtil.INSTANCE.applyLore(setLoreItem, meta); + meta.setLore(setLoreItem); item.setItemMeta(meta); return new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance); @@ -361,7 +357,7 @@ public class DoubleSettingGui extends AbstractSettingGui { */ public static class DoubleSettingFactory extends SettingGuiFactory { @NotNull - Message title; + String title; @NotNull ValueUpdatableGui parent; @@ -373,12 +369,8 @@ public class DoubleSettingGui extends AbstractSettingGui { BigDecimal defaultVal; BigDecimal[] steps; - @Nullable - Message displayLore; - @Nullable - Object param; - @Nullable - Object param2; + @NotNull + List displayLore; /** * Constructor for a double setting gui factory. @@ -400,11 +392,10 @@ public class DoubleSettingGui extends AbstractSettingGui { * If step only contain 1 value, no step item should be displayed. */ public DoubleSettingFactory( - @NotNull Message title, @NotNull ValueUpdatableGui parent, + @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull ConfigHolder config, @NotNull String configPath, - @Nullable Message displayLore, - @Nullable Object param, @Nullable Object param2, + @Nullable List displayLore, int scale, boolean asPercentage, boolean nullOnZero, double min, double max, double defaultVal, double... steps) { super(configPath, config); @@ -422,16 +413,18 @@ public class DoubleSettingGui extends AbstractSettingGui { this.steps[i] = BigDecimal.valueOf(steps[i]).setScale(scale, RoundingMode.HALF_UP); } - this.displayLore = displayLore; - this.param = param; - this.param2 = param2; + if(displayLore == null){ + this.displayLore = Collections.emptyList(); + }else { + this.displayLore = displayLore; + } } /** * @return Get setting's gui title */ @NotNull - public Message getTitle() { + public String getTitle() { return title; } @@ -455,29 +448,21 @@ public class DoubleSettingGui extends AbstractSettingGui { } - public GuiItem getItem( - @NotNull Material itemMat, - @NotNull Message name, - Object... params - ){ + public GuiItem getItem(Material itemMat, String name){ // Get item properties BigDecimal value = getConfiguredValue(); + StringBuilder itemName = new StringBuilder("§a").append(name); - var itemName = name.formattedConcatenated(params); - - return GuiGlobalItems.createGuiItemFromProperties( - this, itemMat, itemName, - "" + displayValue(value, this.asPercentage), //TODO MESSAGE ? maybe ? - Collections.singletonList(this.displayLore), true, - this.param, this.param2 - ); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, + "§e" + displayValue(value, this.asPercentage), + this.displayLore, true); } public GuiItem getItem(Material itemMat){ // Get item properties String configPath = GuiGlobalItems.getConfigNameFromPath(getConfigPath()); - return getItem(itemMat, MsgUI.INSTANCE.getSHARED_GREEN_GET_ITEM(), CasedStringUtil.detectToUpperSpacedCase(configPath)); + return getItem(itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath)); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java index 1e880512..0d4bc89a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java @@ -19,9 +19,6 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; 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 java.util.Arrays; import java.util.Collections; @@ -153,7 +150,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { assert meta != null; meta.setDisplayName("§e" + nowBook + " §f-> §e" + planned + " §r(§c-" + (nowBook - planned) + "§r)"); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getSHARED_CLICK_TO_CHANGE().formatted(), meta); + meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE)); item.setItemMeta(meta); minusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance); @@ -170,8 +167,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui { ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName("§e" + nowBook + " §f-> §e" + planned + " §r(§a+" + (planned - nowBook) + "§r)");//TODO MESSAGE - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getSHARED_CLICK_TO_CHANGE().formatted(), meta); + meta.setDisplayName("§e" + nowBook + " §f-> §e" + planned + " §r(§a+" + (planned - nowBook) + "§r)"); + meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE)); item.setItemMeta(meta); plusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance); @@ -185,9 +182,9 @@ public class EnchantCostSettingsGui extends IntSettingsGui { ItemMeta nowMeta = nowPaper.getItemMeta(); assert nowMeta != null; - nowMeta.setDisplayName("Value: " + nowBook);//TODO MESSAGE - if (holder.displayLore != null) { - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(holder.displayLore, holder.param), nowMeta); + nowMeta.setDisplayName("§fValue: §e" + nowBook); + if (!holder.displayLore.isEmpty()) { + nowMeta.setLore(holder.displayLore); } nowPaper.setItemMeta(nowMeta); @@ -266,15 +263,15 @@ public class EnchantCostSettingsGui extends IntSettingsGui { * If step only contain 1 value, no step item should be displayed. */ public EnchantCostSettingFactory( - @NotNull Message title, ValueUpdatableGui parent, + @NotNull String title, ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config, - @Nullable Message displayLore, @Nullable Object param, + @Nullable List displayLore, @NotNull CAEnchantment enchantment, int min, int max, int... steps) { super(title, parent, configPath, config, - displayLore, param, + displayLore, min, max, enchantment.defaultRarity().getItemValue(), steps); @@ -305,8 +302,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { return new EnchantCostSettingsGui(this, nowItem); } - @Nullable - public List getDisplayLore() { + public List getDisplayLore() { return this.displayLore; } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java index 9ff90d8a..5bf4c24e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java @@ -15,7 +15,6 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder; 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.Collections; import java.util.List; @@ -138,7 +137,7 @@ public class EnumSettingGui & EnumSettingGui.ConfigurableEnum> */ public abstract static class EnumSettingFactory & ConfigurableEnum> extends SettingGuiFactory { @NotNull - Message title; + String title; @NotNull ValueUpdatableGui parent; @@ -151,7 +150,7 @@ public class EnumSettingGui & EnumSettingGui.ConfigurableEnum> * @param config Configuration holder of this setting. */ protected EnumSettingFactory( - @NotNull Message title, @NotNull ValueUpdatableGui parent, + @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config) { super(configPath, config); this.title = title; @@ -162,7 +161,7 @@ public class EnumSettingGui & EnumSettingGui.ConfigurableEnum> * @return Get setting's gui title. */ @NotNull - public Message getTitle() { + public String getTitle() { return title; } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java index 13cf72e5..c32d22ca 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java @@ -5,9 +5,6 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.PatternPane; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import io.delilaheve.CustomAnvil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.TextColor; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; @@ -19,10 +16,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; 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.ComponentUtil; import java.util.Collections; import java.util.List; @@ -77,8 +71,8 @@ public class IntSettingsGui extends AbstractSettingGui { ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName("§eReset to default value");//TODO MESSAGE - meta.setLore(Collections.singletonList("§7Default value is §e" +//TODO MESSAGE + meta.setDisplayName("§eReset to default value"); + meta.setLore(Collections.singletonList("§7Default value is §e" + holder.valueDisplayName(ValueDisplayType.RESET, holder.defaultVal))); item.setItemMeta(meta); returnToDefault = new GuiItem(item, event -> { @@ -97,7 +91,7 @@ public class IntSettingsGui extends AbstractSettingGui { // minus item GuiItem minusItem; - if(now > holder.min) { + if (now > holder.min) { int planned = Math.max(holder.min, now - step); minusItem = valueEditItem(Material.RED_TERRACOTTA, ValueDisplayType.REMOVE, planned); } else { @@ -107,7 +101,7 @@ public class IntSettingsGui extends AbstractSettingGui { //plus item GuiItem plusItem; - if(now < holder.max) { + if (now < holder.max) { int planned = Math.min(holder.max, now + step); plusItem = valueEditItem(Material.GREEN_TERRACOTTA, ValueDisplayType.ADD, planned); } else { @@ -120,9 +114,8 @@ public class IntSettingsGui extends AbstractSettingGui { ItemMeta resultMeta = resultPaper.getItemMeta(); assert resultMeta != null; - resultMeta.setDisplayName("Value: " + holder.valueDisplayName(ValueDisplayType.CURRENT, now));//TODO MESSAGE - if(holder.displayLore != null) - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(holder.displayLore, holder.param), resultMeta); + resultMeta.setDisplayName("§fValue: §e" + holder.valueDisplayName(ValueDisplayType.CURRENT, now)); + resultMeta.setLore(holder.displayLore); resultPaper.setItemMeta(resultMeta); @@ -132,7 +125,7 @@ public class IntSettingsGui extends AbstractSettingGui { // reset to default GuiItem returnToDefault; - if(now != holder.defaultVal) { + if (now != holder.defaultVal) { returnToDefault = this.returnToDefault; } else { returnToDefault = GuiGlobalItems.backgroundItem(); @@ -149,9 +142,9 @@ public class IntSettingsGui extends AbstractSettingGui { var nowDisplay = holder.valueDisplayName(type, now); var plannedDisplay = holder.valueDisplayName(type, planned); var deltaDisplay = holder.deltaDisplay(type, now, planned); - meta.setDisplayName("§e" + nowDisplay + " §f-> §e" + plannedDisplay + " §r(§c" + deltaDisplay + "§r)");//TODO MESSAGE + meta.setDisplayName("§e" + nowDisplay + " §f-> §e" + plannedDisplay + " §r(§c" + deltaDisplay + "§r)"); - ComponentUtil.INSTANCE.applyLore(MsgUI.INSTANCE.getSHARED_CLICK_TO_CHANGE().formatted(), meta); + meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE)); item.setItemMeta(meta); return new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance); } @@ -177,7 +170,7 @@ public class IntSettingsGui extends AbstractSettingGui { GuiItem background = GuiGlobalItems.backgroundItem(); PatternPane pane = getPane(); - for(char i = 'a'; i < (getMidStepChar() - 'a') * 2 + 1; i++) { + for (char i = 'a'; i < (getMidStepChar() - 'a') * 2 + 1; i++) { pane.bindItem(i, background); } // Then update legit step values @@ -188,7 +181,7 @@ public class IntSettingsGui extends AbstractSettingGui { * Update steps items value. */ protected void updateStepValue() { - if(holder.steps.length <= 1) return; + if (holder.steps.length <= 1) return; // We assume steps have a length of 2k+1 cause its more pretty char val = getMidStepChar(); // Offset to start (not the best way to do it) @@ -196,7 +189,7 @@ public class IntSettingsGui extends AbstractSettingGui { // Then place items PatternPane pane = getPane(); - for(int i = 0; i < holder.steps.length; i++) { + for (int i = 0; i < holder.steps.length; i++) { pane.bindItem(val + i, stepGuiItem(i)); } @@ -225,7 +218,7 @@ public class IntSettingsGui extends AbstractSettingGui { StringBuilder stepName = new StringBuilder("§"); List stepLore; Consumer clickEvent; - if(stepValue == step) { + if (stepValue == step) { stepMat = Material.GREEN_STAINED_GLASS_PANE; stepName.append('a'); stepLore = Collections.singletonList("§7Value is changing by " + stepValue); @@ -268,7 +261,7 @@ public class IntSettingsGui extends AbstractSettingGui { public boolean onSave() { holder.config.getConfig().set(holder.configPath, now); - if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) { + if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) { return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE); } return true; @@ -285,7 +278,7 @@ public class IntSettingsGui extends AbstractSettingGui { public static class IntSettingFactory extends SettingGuiFactory { @NotNull - Message title; + String title; @NotNull ValueUpdatableGui parent; int min; @@ -293,11 +286,8 @@ public class IntSettingsGui extends AbstractSettingGui { int defaultVal; int[] steps; - @Nullable - List displayLore; - - @Nullable - Object param; + @NotNull + List displayLore; /** * Constructor for an int setting gui factory. @@ -316,9 +306,9 @@ public class IntSettingsGui extends AbstractSettingGui { * If step only contain 1 value, no step item should be displayed. */ public IntSettingFactory( - @NotNull Message title, @NotNull ValueUpdatableGui parent, + @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config, - @Nullable Message displayLore, @Nullable Object param, + @Nullable List displayLore, int min, int max, int defaultVal, int... steps) { super(configPath, config); this.title = title; @@ -327,15 +317,19 @@ public class IntSettingsGui extends AbstractSettingGui { this.max = max; this.defaultVal = defaultVal; this.steps = steps; - this.displayLore = displayLore == null ? null : Collections.singletonList(displayLore); - this.param = param; + + if (displayLore == null) { + this.displayLore = Collections.emptyList(); + } else { + this.displayLore = displayLore; + } } /** * @return Get setting's gui title */ @NotNull - public Message getTitle() { + public String getTitle() { return title; } @@ -361,24 +355,19 @@ public class IntSettingsGui extends AbstractSettingGui { * * @param itemMat Displayed material of the item. * @param name Name of the item. - * @param params parameters for the given name. * @return A formatted GuiItem that will create and open a GUI for the int setting. */ public GuiItem getItem( @NotNull Material itemMat, - @NotNull Message name, - Object... params + @NotNull String name ) { // Get item properties int value = getConfiguredValue(); - var itemName = name.formattedConcatenated(params); + StringBuilder itemName = new StringBuilder("§a").append(name); - return GuiGlobalItems.createGuiItemFromProperties( - this, itemMat, itemName, - "" + value, //TODO MESSAGE ? maybe ? - this.displayLore, true, - this.param - ); + return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, + "§e" + value, + this.displayLore, true); } /** @@ -394,7 +383,7 @@ public class IntSettingsGui extends AbstractSettingGui { @NotNull Material itemMat ) { String configPath = GuiGlobalItems.getConfigNameFromPath(getConfigPath()); - return getItem(itemMat, MsgUI.INSTANCE.getSHARED_GREEN_GET_ITEM(), CasedStringUtil.detectToUpperSpacedCase(configPath)); + return getItem(itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath)); } protected String valueDisplayName(ValueDisplayType type, int value) { @@ -403,13 +392,10 @@ public class IntSettingsGui extends AbstractSettingGui { protected String deltaDisplay(ValueDisplayType type, int now, int planned) { var delta = planned - now; - if(delta < 0) return "§c" + delta; + if (delta < 0) return "§c" + delta; else return "§a+" + delta; } - public @Nullable Object getParam() { - return param; - } } public enum ValueDisplayType { diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java index 81de4586..3df2af8c 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java @@ -17,11 +17,8 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder; 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 xyz.alexcrea.cuanvil.util.CasedStringUtil; -import xyz.alexcrea.cuanvil.util.ComponentUtil; -import java.awt.*; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -171,13 +168,13 @@ public class ItemSettingGui extends AbstractSettingGui { */ public static class ItemSettingFactory extends SettingGuiFactory { @NotNull - Message title; + String title; @NotNull ValueUpdatableGui parent; @Nullable ItemStack defaultVal; @NotNull - List displayLore; + List displayLore; /** * Constructor for an item setting gui factory. @@ -190,10 +187,10 @@ public class ItemSettingGui extends AbstractSettingGui { * @param displayLore Gui display item lore. */ public ItemSettingFactory( - @NotNull Message title, @NotNull ValueUpdatableGui parent, + @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config, @Nullable ItemStack defaultVal, - Message... displayLore) { + String... displayLore) { super(configPath, config); this.title = title; this.parent = parent; @@ -206,7 +203,7 @@ public class ItemSettingGui extends AbstractSettingGui { * @return Get setting's gui title. */ @NotNull - public Message getTitle() { + public String getTitle() { return title; } @@ -218,7 +215,7 @@ public class ItemSettingGui extends AbstractSettingGui { } @NotNull - public List getDisplayLore() { + public List getDisplayLore() { return this.displayLore; } @@ -248,9 +245,8 @@ public class ItemSettingGui extends AbstractSettingGui { ItemMeta meta = item.getItemMeta(); assert meta != null; - //TODO MESSAGE name ? meta.setDisplayName("§a" + name); - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(getDisplayLore()), meta); + meta.setLore(getDisplayLore()); meta.addItemFlags(ItemFlag.values()); item.setItemMeta(meta); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/WorkPenaltyTypeSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/WorkPenaltyTypeSettingGui.java index 439376aa..8cc3d2ce 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/WorkPenaltyTypeSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/WorkPenaltyTypeSettingGui.java @@ -15,48 +15,55 @@ import xyz.alexcrea.cuanvil.anvil.AnvilUseType; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.WorkPenaltyType; import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui; -import xyz.alexcrea.cuanvil.lang.Message; +import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.lang.MsgUI; -import xyz.alexcrea.cuanvil.util.ComponentUtil; import java.util.ArrayList; import java.util.EnumMap; +import java.util.List; import java.util.Map; public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { + private static final String INCREASING_EXPLANATION = "§eIncreasing§7: will penalty be increased (in item)"; + private static final String ADDING_EXPLANATION = "§eAdditive§7: will penalty be added to the cost"; + + private static final String SHARED_EXPLANATION = "§eShared§7: Vanilla, shared penalty. it will be kept from before the plugin installation."; + private static final String EXCLUSIVE_EXPLANATION = "§eExclusive§7: Custom, per anvil use type penalty. it will be lost after plugin uninstallation"; + private final @NotNull WorkPenaltyType currentType; private final @NotNull Map items; public WorkPenaltyTypeSettingGui(@NotNull BasicConfigGui parent) { - super(4, MsgUI.INSTANCE.getBASIC_WORK_PENALTY_TITLE(), parent); + super(4, "§8Work Penalty Type", parent); this.currentType = ConfigOptions.INSTANCE.getWorkPenaltyType(); this.items = new EnumMap<>(this.currentType.getPartMap()); - for(AnvilUseType type : useTypes.keySet()) { + for (AnvilUseType type : useTypes.keySet()) { updateGuiForType(type); } } public static GuiItem getDisplayItem(@NotNull BasicConfigGui parent, @NotNull Material itemMat, - @NotNull Message name) { - var item = new ItemStack(itemMat); + @NotNull String name) { + List displayLore = new ArrayList<>(); - var meta = item.getItemMeta(); - assert meta != null; + displayLore.add("§7Work penalty increase the price for every anvil use."); + displayLore.add("§7This config allow you to choose the comportment of work penalty."); + displayLore.add(INCREASING_EXPLANATION); + displayLore.add(ADDING_EXPLANATION); + displayLore.add(""); + displayLore.add("§7About shared/exclusive penalty:"); + displayLore.add(SHARED_EXPLANATION); + displayLore.add(EXCLUSIVE_EXPLANATION); - var lore = new ArrayList(); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_LORE()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_INCREASING()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_ADDITIVE()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_LORE_BREAK()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_SHARED()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_EXCLUSIVE()); + ItemStack item = new ItemStack(itemMat); - ComponentUtil.INSTANCE.setMessageName(meta, name); - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(lore), meta); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(name); + meta.setLore(displayLore); item.setItemMeta(meta); @@ -65,7 +72,7 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { HumanEntity player = event.getWhoClicked(); // Do not allow to open inventory if player do not have edit configuration permission - if(!player.hasPermission(CustomAnvil.editConfigPermission)) { + if (!player.hasPermission(CustomAnvil.editConfigPermission)) { player.closeInventory(); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player); return; @@ -104,7 +111,6 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { char exclusiveAdditive = typeVals.charAt(4); WorkPenaltyType.WorkPenaltyPart part = items.get(type); - //TODO MESSAGE String increasingStr = (part.penaltyIncrease() ? "§a" : "§c") + "Increasing"; String additiveStr = (part.penaltyAdditive() ? "§a" : "§c") + "Additive"; String exclusiveIncreasingStr = (part.exclusivePenaltyIncrease() ? "§a" : "§c") + "Increasing"; @@ -118,7 +124,6 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { displayLore.add("§eExclusive§7: " + exclusiveAdditiveStr + " §7| " + exclusiveIncreasingStr); ItemMeta meta = displayItem.getItemMeta(); - assert meta != null; meta.setDisplayName("§e" + type.getDisplayName()); meta.setLore(displayLore); displayItem.setItemMeta(meta); @@ -132,14 +137,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { ItemStack incrementItem = new ItemStack(part.penaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA); meta = incrementItem.getItemMeta(); - assert meta != null; meta.setDisplayName(increasingStr); - - var lore = new ArrayList(); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_INCREASING()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_SHARED()); - - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(lore), meta); + meta.setLore(List.of(INCREASING_EXPLANATION)); + meta.setLore(List.of(SHARED_EXPLANATION)); incrementItem.setItemMeta(meta); pane.bindItem(increment, new GuiItem(incrementItem, (event) -> { @@ -157,14 +157,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { ItemStack additiveItem = new ItemStack(part.penaltyAdditive() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA); meta = additiveItem.getItemMeta(); - assert meta != null; meta.setDisplayName(additiveStr); - - lore.clear(); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_ADDITIVE()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_SHARED()); - - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(lore), meta); + meta.setLore(List.of(ADDING_EXPLANATION)); + meta.setLore(List.of(SHARED_EXPLANATION)); additiveItem.setItemMeta(meta); pane.bindItem(additive, new GuiItem(additiveItem, (event) -> { @@ -182,14 +177,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { ItemStack exclusiveIncrementItem = new ItemStack(part.exclusivePenaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA); meta = exclusiveIncrementItem.getItemMeta(); - assert meta != null; meta.setDisplayName(exclusiveIncreasingStr); - - lore.clear(); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_INCREASING()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_EXCLUSIVE()); - - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(lore), meta); + meta.setLore(List.of(INCREASING_EXPLANATION)); + meta.setLore(List.of(EXCLUSIVE_EXPLANATION)); exclusiveIncrementItem.setItemMeta(meta); pane.bindItem(exclusiveIncrement, new GuiItem(exclusiveIncrementItem, (event) -> { @@ -207,14 +197,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { ItemStack exclusiveAdditiveItem = new ItemStack(part.exclusivePenaltyAdditive() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA); meta = exclusiveAdditiveItem.getItemMeta(); - assert meta != null; meta.setDisplayName(exclusiveAdditiveStr); - - lore.clear(); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_ADDITIVE()); - lore.add(MsgUI.INSTANCE.getBASIC_WORK_PENALTY_EXPLAIN_EXCLUSIVE()); - - ComponentUtil.INSTANCE.applyLore(ComponentUtil.INSTANCE.asComponents(lore), meta); + meta.setLore(List.of(ADDING_EXPLANATION)); + meta.setLore(List.of(EXCLUSIVE_EXPLANATION)); exclusiveAdditiveItem.setItemMeta(meta); pane.bindItem(exclusiveAdditive, new GuiItem(exclusiveAdditiveItem, (event) -> { @@ -239,9 +224,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { FileConfiguration config = configHolder.getConfig(); partEnum.forEach((key, value) -> { - String partPath = key.getPath(); + String partPath = key.getPath(); - if(key.getDefaultPenalty().equals(value)) { + if (key.getDefaultPenalty().equals(value)) { config.set(partPath, null); return; } @@ -257,8 +242,8 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui { @Override public boolean hadChange() { - for(AnvilUseType type : items.keySet()) { - if(!currentType.getPenaltyInfo(type).equals(items.get(type))) { + for (AnvilUseType type : items.keySet()) { + if (!currentType.getPenaltyInfo(type).equals(items.get(type))) { return true; } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java index d0d7cd4f..79f1462e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiGlobalItems.java @@ -4,20 +4,14 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.PatternPane; import io.delilaheve.CustomAnvil; -import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; -import xyz.alexcrea.cuanvil.lang.Message; -import xyz.alexcrea.cuanvil.lang.MsgUI; -import xyz.alexcrea.cuanvil.util.ComponentUtil; import java.util.ArrayList; import java.util.Collections; @@ -190,6 +184,9 @@ public class GuiGlobalItems { return new GuiItem(item, GuiGlobalActions.openSettingGuiAction(factory), CustomAnvil.instance); } + // Prefix of the one line lore that will be added to setting's item. + public static final String SETTING_ITEM_LORE_PREFIX = "§7value: "; + /** * Create an arbitrary GuiItem from a unique setting and item's property. * @@ -204,23 +201,17 @@ public class GuiGlobalItems { public static GuiItem createGuiItemFromProperties( @NotNull SettingGui.SettingGuiFactory factory, @NotNull Material itemMat, - @NotNull Component itemName, - @NotNull Object value,//TODO ???? - @Nullable List displayLore, - boolean displayValuePrefix, - @Nullable Object... params + @NotNull StringBuilder itemName, + @NotNull Object value, + @NotNull List displayLore, + boolean displayValuePrefix ) { // Prepare lore - var loreHeader = (displayValuePrefix ? - MsgUI.INSTANCE.getGLOBAL_ITEM_ITEM_LORE_PREFIX() : - MsgUI.INSTANCE.getGLOBAL_ITEM_ITEM_LORE_PREFIX_ALONE()); - - List lore = loreHeader.formatted(value); - if(displayLore != null){ - lore.add(Component.empty()); - for(Message message : displayLore) { - lore.addAll(message.formatted(params)); - } + ArrayList lore = new ArrayList<>(); + lore.add((displayValuePrefix ? SETTING_ITEM_LORE_PREFIX : "") + value); + if(!displayLore.isEmpty()){ + lore.add(""); + lore.addAll(displayLore); } // Create & initialise item @@ -228,8 +219,8 @@ public class GuiGlobalItems { ItemMeta itemMeta = item.getItemMeta(); assert itemMeta != null; - PlatformUtil.INSTANCE.setComponentDisplayName(itemMeta, itemName, null); - ComponentUtil.INSTANCE.applyLore(lore, itemMeta); + itemMeta.setDisplayName(itemName.toString()); + itemMeta.setLore(lore); itemMeta.addItemFlags(ItemFlag.values()); item.setItemMeta(itemMeta); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt index 17ae3796..d42c8d22 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt @@ -109,7 +109,7 @@ class DebugToggleExecutor: CASubCommand { Text(MsgCommand.SHARED_HOVER_COPY.legacy()) ) - sender.spigot().sendMessage(message) + sender.spigot().sendMessage(message); } else { sender.sendMessage(stb.toString()) } @@ -137,14 +137,7 @@ class DebugToggleExecutor: CASubCommand { if(Lang.has(message.key)) validCount++ val valid = (100.0 * validCount) / registeredKeys.size - sender.sendMessage( - "Translated (${Lang.currentLang()}): ${ - "%.1f".format( - Locale.ROOT, - valid - ) - }% ($validCount/${registeredKeys.size})" - ) + sender.sendMessage("Translated (${Lang.currentLang()}): ${"%.1f".format(Locale.ROOT, valid)}% ($validCount/${registeredKeys.size})") } private fun detailedLangDebug(sender: CommandSender) { @@ -186,7 +179,7 @@ class DebugToggleExecutor: CASubCommand { Text(MsgCommand.SHARED_HOVER_COPY.legacy()) ) - sender.spigot().sendMessage(message) + sender.spigot().sendMessage(message); } else { sender.sendMessage("No additional issue found") } @@ -197,7 +190,7 @@ class DebugToggleExecutor: CASubCommand { val texts = if(section == null) listOf(Lang.getTranslated(message.key)) else - section.getValues(false).map {it.value.toString()} + section.getValues(false).map { it.value.toString() } val textParams = ArrayList() @@ -205,7 +198,8 @@ class DebugToggleExecutor: CASubCommand { var index = 0 while(true) { index = text.indexOf('%', index) - if(index > 0 && text[index - 1] == '\\') { + //TODO add \% to "ignore" % as param inside param finder + if(index > 0 && text[index-1] == '\\') { index++ continue } @@ -224,29 +218,23 @@ class DebugToggleExecutor: CASubCommand { for(textParam in textParams) { var found = false for(param in message.params) { - if(param == null) continue + if(param.isEmpty()) continue if(textParam.startsWith(param)) { found = true usedParam.add(param) break } } - if(found) break - hadIssue = true - stb.append("Did not found param %$textParam in register list for ${message.key}\n") + if(!found) { + hadIssue = true + stb.append("Did not found param %$textParam in register list for ${message.key}\n") + } } for(param in message.params) { - if(param == null) continue - var found = false - for(used in usedParam) { - if(!used.startsWith(param)) continue - found = true - break - } - - if(found) continue + if(usedParam.contains(param)) continue + if("unused".contentEquals(param)) continue hadIssue = true stb.append("Param %$param is not used for key ${message.key}\n") } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index 07f03ab0..0644a6fa 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -219,8 +219,8 @@ class DiagnosticExecutor : CASubCommand { } private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) { - val enabledPlugins: MutableList = ArrayList() - val disabledPlugins: MutableList = ArrayList() + val enabledPlugins: MutableList = ArrayList() + val disabledPlugins: MutableList = ArrayList() for (plugin in Bukkit.getPluginManager().plugins) { if (plugin.isEnabled) { enabledPlugins.add(plugin) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt index 82a43ba5..64d9242d 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/Message.kt @@ -12,10 +12,9 @@ import xyz.alexcrea.cuanvil.util.ComponentUtil.serializePlain import xyz.alexcrea.cuanvil.util.MiniMessageUtil import java.util.Collections import java.util.logging.Level -import kotlin.math.max import kotlin.math.min -open class Message(val key: String, vararg val params: String?, register: Boolean = true) { +open class Message(val key: String, vararg val params: String, register: Boolean = true) { companion object { private val values = ArrayList() @@ -29,61 +28,30 @@ open class Message(val key: String, vararg val params: String?, register: Boolea if(register) values.add(this) } - protected fun replaceParameters(stb: StringBuilder, vararg values: Any?) { + protected fun replaceParameters(stb: StringBuilder, vararg values: Any) { // replace all placeholder thingy %key -> value if(params.size != values.size) { CustomAnvil.log("Wrong number of argument for parameter for key $key (${params.size}/${values.size})") - for(i in 0 until max(params.size, values.size)) { - val key = if(i >= params.size) "NOT KEY" - else params[i] - val value = if(i >= values.size) "NOT VALUE" - else values[i] - - CustomAnvil.log("Parameter ${i + 1} is $key with value $value") - } } - var foundBackslashPercent = false for(i in 0 until min(params.size, values.size)) { - val key = params[i] ?: continue - val value = values[i] - if(value == null) { - CustomAnvil.log("Passed a null value for key ${this.key} for Parameter $key (${i + 1})") - continue - } - - val replacement = value.toString() - if(replacement.isEmpty()) continue //May not be good but can be changed if cause an issue //TODO REPLACE WITH NULL + 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) { - current = stb.indexOf('%', current) - if(current > 0 && stb[current - 1] == '\\') { - foundBackslashPercent = true - continue - } - if(++current <= 0 || current + key.length > stb.length) break // may be able to be removed if bound checked in startsWith ? + current = stb.indexOf('%', current) + 1 + if(current <= 0 || current + key.length > stb.length) break // may be able to be removed if bound checked in startsWith ? if(!stb.startsWith(key, current, false)) continue stb.replace(current - 1, current + key.length, replacement) current = current - 1 + replacement.length } } - - if(foundBackslashPercent) { - // Remove the \% to \ - var current = 0 - while(true) { - current = stb.indexOf("\\%", current) - if(current < 0) break - - stb.replace(current, current + 2, "%") - current++ - } - } } - private fun unformattedMonoline(vararg params: Any?): String { + private fun unformattedMonoline(vararg params: Any): String { val translated = Lang.getTranslated(key) if(params.isEmpty() && this.params.isEmpty()) return translated @@ -92,7 +60,7 @@ open class Message(val key: String, vararg val params: String?, register: Boolea return stb.toString() } - private fun unformattedMultiline(section: ConfigurationSection, vararg params: Any?): String { + private fun unformattedMultiline(section: ConfigurationSection, vararg params: Any): String { val stb = StringBuilder() for(key in section.getKeys(false)) { @@ -106,14 +74,14 @@ open class Message(val key: String, vararg val params: String?, register: Boolea return stb.toString() } - fun unformatted(vararg params: Any?): String { + fun unformatted(vararg params: Any): String { val section = Lang.getSection(key) if(section != null) return unformattedMultiline(section, *params) return unformattedMonoline(*params) } - private fun formattedMultiline(section: ConfigurationSection, vararg params: Any?): MutableList { + private fun formattedMultiline(section: ConfigurationSection, vararg params: Any): List { val result = ArrayList() for(key in section.getKeys(false)) { @@ -125,21 +93,21 @@ open class Message(val key: String, vararg val params: String?, register: Boolea result.add(MiniMessageUtil.mm.deserialize(stb.toString())) } - if(result.isEmpty()) return mutableListOf(Component.text(key)) + 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?): MutableList { + fun formatted(vararg params: Any): List { val section = Lang.getSection(key) if(section != null) return formattedMultiline(section, *params) val translated = unformattedMonoline(*params) - return mutableListOf(MiniMessageUtil.mm.deserialize(translated)) + return listOf(MiniMessageUtil.mm.deserialize(translated)) } - fun formattedConcatenated(vararg params: Any?): Component { + fun formattedConcatenated(vararg params: Any): Component { val formated = formatted(*params) var result = formated.first() @@ -150,11 +118,11 @@ open class Message(val key: String, vararg val params: String?, register: Boolea return result } - fun textHolder(vararg params: Any?): TextHolder { + fun textHolder(vararg params: Any): TextHolder { return ComponentHolder.of(formattedConcatenated(*params)) } - fun legacy(vararg params: Any?): String { + fun legacy(vararg params: Any): String { val formated = formatted(*params) val stb = StringBuilder() @@ -165,7 +133,7 @@ open class Message(val key: String, vararg val params: String?, register: Boolea return stb.toString() } - open fun log(vararg params: Any?) { + open fun log(vararg params: Any) { val texts = formatted(*params) for(component in texts) { @@ -173,14 +141,14 @@ open class Message(val key: String, vararg val params: String?, register: Boolea } } - open fun send(destination: CommandSender, vararg params: Any?) { + open fun send(destination: CommandSender, vararg params: Any) { formatted(*params).send(destination) } } -class WarningMessage(key: String, vararg params: String): Message("warning.$key", *params) { +class WarningMessage(key: String, vararg params: String) : Message("warning.$key", *params) { - override fun log(vararg params: Any?) { + override fun log(vararg params: Any) { val texts = formatted(*params) for(component in texts) { @@ -189,9 +157,9 @@ class WarningMessage(key: String, vararg params: String): Message("warning.$key" } } -class ErrorMessage(key: String, vararg params: String): Message("error.$key", *params) { +class ErrorMessage(key: String, vararg params: String) : Message("error.$key", *params) { - override fun log(vararg params: Any?) { + override fun log(vararg params: Any) { val texts = formatted(*params) for(component in texts) { @@ -199,7 +167,7 @@ class ErrorMessage(key: String, vararg params: String): Message("error.$key", *p } } - fun log(e: Throwable, vararg params: Any?, level: Level = Level.SEVERE, track: Boolean = true) { + fun log(e: Throwable, vararg params: Any, level: Level = Level.SEVERE, track: Boolean = true) { val texts = formatted(*params) for(component in texts) { @@ -208,5 +176,5 @@ class ErrorMessage(key: String, vararg params: String): Message("error.$key", *p } } -class CommandMessage(key: String, vararg params: String): Message("command.$key", *params) -class UIMessage(key: String, vararg params: String): Message("config-ui.$key", *params) \ No newline at end of file +class CommandMessage(key: String, vararg params: String) : Message("command.$key", *params) +class UIMessage(key: String, vararg params: String) : Message("config-ui.$key", *params) \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt index a5734d44..1a876e6e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt @@ -6,12 +6,6 @@ object MsgUI { val SHARED_CONFIG_NO_EDIT_PERM = Message("shared.no-permission") val SHARED_TYPED_CONFIG_TITLE = Message("shared.typed-config-title", "type") - val SHARED_CLICK_TO_CHANGE = Message("shared.click-to-change") - val SHARED_GREEN_GET_ITEM = Message("shared.green-get-item", "name") - val SHARED_YELLOW_GET_ITEM = Message("shared.yellow-get-item", "name") - - val GLOBAL_ITEM_ITEM_LORE_PREFIX = Message("global-item.item-lore-prefix", "value") - val GLOBAL_ITEM_ITEM_LORE_PREFIX_ALONE = Message("global-item.item-lore-prefix-alone", "value") val CONFIRM_ACTION_FAILED = Message("confirm-action.fail") val CONFIRM_ACTION_ARE_YOU_SURE = Message("confirm-action.is-user-sure") @@ -22,145 +16,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_TITLE = Message("unit-repair.title", null, "page", "max_page") - val UNIT_REPAIR_ITEM = Message("unit-repair.item", "name", "unit") + val UNIT_REPAIR_TITLE = Message("unit-repair.title", "unused", "page", "max_page") val UNIT_REPAIR_ELEMENT_TITLE = Message("unit-repair.element.title", "type", "page", "max_page") - val UNIT_REPAIR_NEW_TITLE = Message("unit-repair.new.title", null) - val UNIT_REPAIR_NEW_DESCRIPTION = Message("unit-repair.new.description", null) + val UNIT_REPAIR_NEW_TITLE = Message("unit-repair.new.title") + val UNIT_REPAIR_NEW_DESCRIPTION = Message("unit-repair.new.description") - val UNIT_REPAIR_ELEMENT_VALUE_TITLE = Message("unit-repair.element.value.title", "name", null) - val UNIT_REPAIR_ELEMENT_VALUE_DESCRIPTION = Message("unit-repair.element.value.description", "name", "unit") - - val UNIT_REPAIR_NEW_ELEMENT_TITLE = Message("unit-repair.element.new.title", null) + val UNIT_REPAIR_NEW_ELEMENT_TITLE = Message("unit-repair.element.new.title", "unused") 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", null, "page", "max_page") - - val CUSTOM_RECIPE_ELEMENT_EXACT_COUNT_TITLE = Message("custom-recipe.element.exact-count") - val CUSTOM_RECIPE_ELEMENT_LINEAR_XP_TITLE = Message("custom-recipe.element.linear-xp.title") - val CUSTOM_RECIPE_ELEMENT_LINEAR_XP_NAME = Message("custom-recipe.element.linear-xp.name") - val CUSTOM_RECIPE_ELEMENT_LINEAR_XP_LORE = Message("custom-recipe.element.linear-xp.lore") - val CUSTOM_RECIPE_ELEMENT_COST_LEVEL_XP = Message("custom-recipe.element.recipe-cost.level") - val CUSTOM_RECIPE_ELEMENT_COST_LINEAR_XP = Message("custom-recipe.element.recipe-cost.xp") - - val CUSTOM_RECIPE_ELEMENT_ITEM_LEFT_TITLE = Message("custom-recipe.element.item.left.title") - val CUSTOM_RECIPE_ELEMENT_ITEM_LEFT_DESCRIPTION = Message("custom-recipe.element.item.left.description") - val CUSTOM_RECIPE_ELEMENT_ITEM_RIGHT_TITLE = Message("custom-recipe.element.item.right.title") - val CUSTOM_RECIPE_ELEMENT_ITEM_RIGHT_DESCRIPTION = Message("custom-recipe.element.item.right.description") - val CUSTOM_RECIPE_ELEMENT_ITEM_RESULT_TITLE = Message("custom-recipe.element.item.result.title") - val CUSTOM_RECIPE_ELEMENT_ITEM_RESULT_DESCRIPTION = Message("custom-recipe.element.item.result.description") + val CUSTOM_RECIPE_TITLE = Message("custom-recipe.title", "unused", "page", "max_page") 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", null) - val CUSTOM_RECIPE_ELEMENT_DELETE_BUTTON_NAME = Message("custom-recipe.element.delete.button.name") - val CUSTOM_RECIPE_ELEMENT_DELETE_BUTTON_LORE = Message("custom-recipe.element.delete.button.lore") + val CUSTOM_RECIPE_ELEMENT_DELETE_DESCRIPTION = Message("custom-recipe.element.delete.description", "unused") - val ENCHANTMENT_LEVEL_COST_TITLE = Message("enchant-level-cost.title", null, "page", "max_page") - val ENCHANTMENT_LEVEL_COST_ELEMENT_TITLE = Message("enchant-level-cost.element.title", "name") - val ENCHANTMENT_LEVEL_COST_ELEMENT_DESCRIPTION = Message("enchant-level-cost.element.description", "name") - val ENCHANTMENT_LEVEL_COST_ELEMENT_ITEM_COST = Message("enchant-level-cost.element.item-cost") - val ENCHANTMENT_LEVEL_COST_ELEMENT_BOOK_COST = Message("enchant-level-cost.element.book-cost") + val ENCHANTMENT_LEVEL_COST_TITLE = Message("enchant-level-cost.title", "unused", "page", "max_page") - val ENCHANTMENT_LEVEL_LIMIT_TITLE = Message("enchant-level-limit.title", null, "page", "max_page") - val ENCHANTMENT_LEVEL_LIMIT_ELEMENT_TITLE = Message("enchant-level-limit.element.title", "name") - val ENCHANTMENT_LEVEL_LIMIT_ELEMENT_DESCRIPTION = Message("enchant-level-limit.element.description", "name") + val ENCHANTMENT_LEVEL_LIMIT_TITLE = Message("enchant-level-limit.title", "unused", "page", "max_page") - val ENCHANTMENT_MERGE_LIMIT_TITLE = Message("enchant-merge-limit.title", null, "page", "max_page") - val ENCHANTMENT_MERGE_LIMIT_ELEMENT_TITLE = Message("enchant-merge-limit.element.title", "name") - val ENCHANTMENT_MERGE_LIMIT_ELEMENT_DESCRIPTION = Message("enchant-merge-limit.element.description", "name") + val ENCHANTMENT_MERGE_LIMIT_TITLE = Message("enchant-merge-limit.title", "unused", "page", "max_page") - val ENCHANTMENT_CONFLICT_TITLE = Message("enchant-conflict.title", null, "page", "max_page") + val ENCHANTMENT_CONFLICT_TITLE = Message("enchant-conflict.title", "unused", "page", "max_page") 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", null) - val ENCHANTMENT_CONFLICT_ELEMENT_DELETE_BUTTON_NAME = Message("enchant-conflict.element.delete.button.name") - val ENCHANTMENT_CONFLICT_ELEMENT_DELETE_BUTTON_LORE = Message("enchant-conflict.element.delete.button.lore") - val ENCHANTMENT_CONFLICT_ELEMENT_MIN_BEFORE_COUNT_TITLE = Message("enchant-conflict.element.min-before-count.title") - val ENCHANTMENT_CONFLICT_ELEMENT_MIN_BEFORE_COUNT_DESCRIPTION = Message("enchant-conflict.element.min-before-count.description") - val ENCHANTMENT_CONFLICT_ELEMENT_MIN_BEFORE_COUNT_ITEM = Message("enchant-conflict.element.min-before-count.item") + val ENCHANTMENT_CONFLICT_ELEMENT_DELETE_DESCRIPTION = Message("enchant-conflict.element.delete.description", "unused") - val MATERIAL_GROUP_TITLE = Message("material-group.title", null, "page", "max_page") + val MATERIAL_GROUP_TITLE = Message("material-group.title", "unused", "page", "max_page") 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", null) + val MATERIAL_GROUP_ELEMENT_DELETE_DESCRIPTION = Message("material-group.element.delete.description", "unused") 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.new.confirm.title", "name") - val MATERIAL_SELECT_CONFIRM_DESCRIPTION = Message("material-select.new.confirm.description", "name") - - /* - * ------------------ - * Basic Config Gui - * ------------------ - */ - val BASIC_TITLE = Message("basic-config.title") - - val BASIC_CAP_ANVIL_COST_TITLE = Message("basic-config.cap-anvil-cost.title") - val BASIC_CAP_ANVIL_COST_DESCRIPTION = Message("basic-config.cap-anvil-cost.description") - val BASIC_CAP_ANVIL_COST_ITEM = Message("basic-config.cap-anvil-cost-cost.item") - val BASIC_CAP_ANVIL_COST_DISABLED_TITLE = Message("basic-config.cap-anvil-cost.disabled.title") - val BASIC_CAP_ANVIL_COST_DISABLED_DESCRIPTION = Message("basic-config.cap-anvil-cost.disabled.description") - - val BASIC_MAX_ANVIL_COST_TITLE = Message("basic-config.max-anvil-cost.title") - val BASIC_MAX_ANVIL_COST_DESCRIPTION = Message("basic-config.max-anvil-cost.description") - val BASIC_MAX_ANVIL_COST_ITEM = Message("basic-config.max-anvil-cost.item") - val BASIC_MAX_ANVIL_COST_DISABLED_TITLE = Message("basic-config.max-anvil-cost.disabled.title") - val BASIC_MAX_ANVIL_COST_DISABLED_DESCRIPTION = Message("basic-config.max-anvil-cost.disabled.description") - - val BASIC_REMOVE_COST_LIMIT_TITLE = Message("basic-config.remove-cost-limit.title") - val BASIC_REMOVE_COST_LIMIT_DESCRIPTION = Message("basic-config.remove-cost-limit.description") - val BASIC_REMOVE_COST_LIMIT_ITEM = Message("basic-config.remove-cost-limit.item") - - val BASIC_REPLACE_TOO_EXPENSIVE_TITLE = Message("basic-config.remove-too-expensive.title") - val BASIC_REPLACE_TOO_EXPENSIVE_DESCRIPTION = Message("basic-config.remove-too-expensive.description") - val BASIC_REPLACE_TOO_EXPENSIVE_DESCRIPTION_NO_NMS = Message("basic-config.remove-too-expensive.description-no-nms") - - val BASIC_ITEM_REPAIR_COST_TITLE = Message("basic-config.item-repair-cost.title") - val BASIC_ITEM_REPAIR_COST_DESCRIPTION = Message("basic-config.item-repair-cost.description") - - val BASIC_ITEM_RENAME_COST_TITLE = Message("basic-config.item-rename-cost.title") - val BASIC_ITEM_RENAME_COST_DESCRIPTION = Message("basic-config.item-rename-cost.description") - - val BASIC_UNIT_REPAIR_COST_TITLE = Message("basic-config.unit-repair-cost.title") - val BASIC_UNIT_REPAIR_COST_DESCRIPTION = Message("basic-config.unit-repair-cost.description") - - val BASIC_SACRIFICE_ILLEGAL_COST_TITLE = Message("basic-config.sacrifice-illegal-cost.title") - val BASIC_SACRIFICE_ILLEGAL_COST_DESCRIPTION = Message("basic-config.sacrifice-illegal-cost.description") - - - val BASIC_COLOR_CODE_LIMIT_TITLE = Message("basic-config.color-code.title") - val BASIC_COLOR_CODE_LIMIT_DESCRIPTION = Message("basic-config.color-code.description") - - val BASIC_COLOR_HEX_LIMIT_TITLE = Message("basic-config.color-hex.title") - val BASIC_COLOR_HEX_LIMIT_DESCRIPTION = Message("basic-config.color-hex.description") - - val BASIC_COLOR_PERMISSION_TITLE = Message("basic-config.color-permission.title") - val BASIC_COLOR_PERMISSION_DESCRIPTION = Message("basic-config.color-permission.description") - val BASIC_COLOR_PERMISSION_DISABLED_TITLE = Message("basic-config.color-permission.disabled.title") - val BASIC_COLOR_PERMISSION_DISABLED_DESCRIPTION = Message("basic-config.color-permission.disabled.description") - - val BASIC_COLOR_COST_TITLE = Message("basic-config.color-cost.title") - val BASIC_COLOR_COST_DESCRIPTION = Message("basic-config.color-cost.description") - val BASIC_COLOR_COST_ITEM = Message("basic-config.color-cost.item") - val BASIC_COLOR_COST_DISABLED_TITLE = Message("basic-config.color-cost.disabled.title") - val BASIC_COLOR_COST_DISABLED_DESCRIPTION = Message("basic-config.color-cost.disabled.description") - - val BASIC_WORK_PENALTY_TITLE = Message("basic-config.work-penalty.title") - val BASIC_WORK_PENALTY_ITEM = Message("basic-config.work-penalty.item") - val BASIC_WORK_PENALTY_LORE = Message("basic-config.work-penalty.lore") - val BASIC_WORK_PENALTY_LORE_BREAK = Message("basic-config.work-penalty.lore-break") - val BASIC_WORK_PENALTY_EXPLAIN_INCREASING = Message("basic-config.work-penalty.explanation.increasing") - val BASIC_WORK_PENALTY_EXPLAIN_ADDITIVE = Message("basic-config.work-penalty.explanation.additive") - val BASIC_WORK_PENALTY_EXPLAIN_SHARED = Message("basic-config.work-penalty.explanation.shared") - val BASIC_WORK_PENALTY_EXPLAIN_EXCLUSIVE = Message("basic-config.work-penalty.explanation.exclusive") - - + val MATERIAL_SELECT_CONFIRM_TITLE = Message("material-select.new.confirm.title","name") + val MATERIAL_SELECT_CONFIRM_DESCRIPTION = Message("material-select.new.confirm.description","name") } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 21b4bffc..56f4e689 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -196,9 +196,6 @@ class AnvilResultListener : Listener { result ) ) return - else if(player.gameMode != GameMode.CREATIVE) { - return - } // Finally, we add the item to the player if (slotDestination.type == SlotType.CURSOR) { @@ -350,8 +347,6 @@ class AnvilResultListener : Listener { view.setItem(ANVIL_OUTPUT_SLOT, null) - } else if(player.gameMode != GameMode.CREATIVE) { - return false } // Finally, we add the item to the player diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt index a9171131..261e085a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt @@ -31,7 +31,7 @@ object ComponentUtil { destination.sendMessage(this.serializeLegacy()) } - fun Collection.send(destination: CommandSender) { + fun List.send(destination: CommandSender) { for(component in this) component.send(destination) } @@ -41,25 +41,8 @@ object ComponentUtil { meta.lore = this.map {obj -> obj.serializeLegacy()} } - fun ItemMeta.setMessageName(message: Message, vararg params: Any?) { + fun ItemMeta.setMessageName(message: Message, vararg params: Any) { this.setComponentDisplayName(message.formattedConcatenated(*params)) } - fun List.asComponents(vararg params: Any?): List { - val result = ArrayList() - for(message in this) { - result.addAll(message.formatted(*params)) - } - return result - } - - fun Array.asComponents(vararg params: Any?): List { - val result = ArrayList() - for(message in this) { - result.addAll(message.formatted(*params)) - } - return result - } - - } \ No newline at end of file diff --git a/src/main/resources/lang/en.yml b/src/main/resources/lang/en.yml index 4f90bb34..87527ea1 100644 --- a/src/main/resources/lang/en.yml +++ b/src/main/resources/lang/en.yml @@ -1,7 +1,8 @@ name: English last-updated: 2.1.0 -warning.load: +warning: + load: legacy: old-name: 1: "An old version of this plugin was detected" @@ -13,11 +14,11 @@ warning.load: 1: "If replace too expensive is not working this is likely because of spigot" 2: "As native nms is not supported for spigot starting 26.1" update.available: "An update may be available: %version" - -warning.anvil: + anvil: generic: "[CustomAnvil] Error while handling the anvil." -error.load: +error: + load: legacy.failed: "error trying to check for legacy system" update.check-fail: "error trying to fetch latest update" command-register: "error trying to register commands" @@ -26,15 +27,16 @@ error.load: enchant-system: "error initializing enchantment system" non-default-config: "Plugin has an issue while trying to load non default config... exiting..." -error.reload: + reload: resource: fail: "Resource %path Could not be loaded or reloaded." hard-fail: "Disabling plugin." -error.confirm-action: + confirm-action: generic: "Could not process confirmation supplier." -command.shared: +command: + shared: no-diag-permission: "You do not have permission to diagnostic this server" hover-copy: "Click to copy" unknown-subcmd: "Unknown subcommand %command" @@ -42,13 +44,13 @@ command.shared: warning: missing-subcmd: "Need to specify a subcommand. for example %example1 or %example2" -command.root: + root: warning: unknown-sub: "Invalid subcommand. run `%command help` to see available commands" error: generic: "Error running this command" -command.debug: + debug: description: "Used to toggle debug logs and retrieve them" log-cleared: "Log Cleared" toggled: "Debug toggled to %type" @@ -62,12 +64,12 @@ command.debug: invalid-type: "Invalid debug type \"%type\"" no-log: "No log to show ? make sure you tried with debug log toggled (%command)" -command.diagnostic: + diagnostic: description: "Basic diagnostic of this plugin" had-error: "There was an error running the diagnostic" copy: "Click to copy diagnostic data" -command.config: + config: description: "Used to edit the configuration of the plugin" folia-issue: 1: "It look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia." @@ -82,7 +84,7 @@ command.config: legacy-name: "/ca gui has been moved to /ca config" cannot_configure: "Cannot configure the item in hand" -command.enchant: + enchant: description: "Allows to set enchantment to holden item" warning: missing_parameter: "Missing enchantment parameter" @@ -92,46 +94,38 @@ command.enchant: removed: "%name removed" set: "%name set to level %level" -command.help: + help: description: "Help command" header: "List of available commands:" -command.reload: + reload: description: "Reload the configuration of this plugin" start: "Reloading config..." success: "Config reloaded !" fail: "Config was not able to be reloaded..." hard-fail: "Hard fail, plugin disabled" - -config-ui.shared: +config-ui: + shared: no-permission: "You do not have permission to edit the config" typed-config-title: "%type Config" - click-to-change: "Click Here to change the value" - green-get-item: "%name" - yellow-get-item: "%name" -config-ui.global-item: - item-lore-prefix: "value: %value" - item-lore-prefix-alone: "%value" - -config-ui.confirm-action: + confirm-action: fail: "Action could not be completed." is-user-sure: "Are you sure ?" -config-ui.select-item-type: + select-item-type: place-here: "Place an item here" -config-ui.element-list: + 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..." -config-ui.unit-repair: + unit-repair: title: "Unit Repair Config (%page/%max_page)" - item: "\\%%name repaired by %unit" new: title: "Select unit repair item." description: @@ -139,11 +133,6 @@ config-ui.unit-repair: 2: "You like to be an unit repair item" element: title: "%type Unit repair (%page/%max_page)" - value: - title: "\\%%name Repair" - description: - 1: "Click here to change how many \\% of %name" - 2: "Should get repaired by %unit" new: title: "Select item to be repaired." description: @@ -152,71 +141,23 @@ config-ui.unit-repair: 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." -config-ui.custom-recipe: + custom-recipe: title: "Custom Recipe Config (%page/%max_page)" element: - exact-count: "Exact count ?" - linear-xp: - title: "Remove exact linear xp ?" - name: "Remove exact linear xp ?" - lore: "Not usable if linear cost is 0" - recipe-cost: - level: "recipe Level Cost" - xp: "Recipe Linear Xp Cost" - item: - left: - title: "Recipe Left Item" - description: - 1: "Set the left item of the custom craft" - 2: "■ + □ = □" - right: - title: "Recipe Right Item" - description: - 1: "Set the right item of the custom craft" - 2: "□ + ■ = □" - result: - title: "Recipe Result Item" - description: - 1: "Set the result item of the custom craft" - 2: "□ + □ = ■" delete: title: "Delete %type?" description: "Confirm that you want to delete this recipe." - button: - name: "DELETE RECIPE" - lore: "Caution with this button !" -config-ui.enchant-level-cost: + enchant-level-cost: title: "Enchantment Level Limit (%page/%max_page)" - element: - title: "%name Cost" - description: - 1: "How many level should %name" - 2: "cost when applied by book or by another item." - item-cost: "Item Cost: %cost" - book-cost: "Book Cost: %cost" - -config-ui.enchant-level-limit: + enchant-level-limit: title: "Enchantment Level Limit (%page/%max_page)" - element: - title: "%name Limit" - description: - 1: "Maximum applied level of %name" -config-ui.enchant-merge-limit: + enchant-merge-limit: title: "Enchantment Maximum Merge Level (%page/%max_page)" - element: - title: "%name Merge Limit" - description: - 1: "Maximum merge level for for %name" - 2: "" - 3: "For example, if set to 2, lvl1 + lvl1 of will give a lvl2" - 4: "But lvl2 + lvl2 will not give a lv3." - 5: "Will still not merge above max enchantment level" - 6: "-1 (default) will set the merge limit to enchantment's maximum level" -config-ui.enchant-conflict: + enchant-conflict: title: "Conflict Config (%page/%max_page)" element: selected-enchantments: "%group" # likely need page and max page @@ -224,17 +165,8 @@ config-ui.enchant-conflict: delete: title: "Delete %type?" description: "Confirm that you want to delete this conflict." - button: - name: "DELETE CONFLICT" - lore: "Caution with this button !" - min-before-count: - item: "Minimum Enchantment Count" - title: "Minimum enchantment count" - description: - 1: "Minimum enchantment count set to X mean only X enchantment can be put" - 2: "on an item before the conflict is active." -config-ui.material-group: + material-group: title: "Group Config (%page/%max_page)" element: selected-materials: "%group Materials" @@ -246,134 +178,8 @@ config-ui.material-group: name: "DELETE GROUP" lore: "Caution with this button !" -config-ui.material-select: + material-select: new: confirm: title: "Remove %name" description: "Confirm Remove %name from this list." - -config-ui.basic-config: - title: "Basic Config" - -config-ui.basic-config.cap-anvil-cost: - item: "Cap Anvil Cost" - title: "Cap Anvil Cost ?" - description: - 1: "All anvil cost will be capped to Max Anvil Cost if enabled." - 2: "In other words:" - 3: "For any anvil cost greater than Max Anvil Cost, Cost will be set to Max Anvil Cost." - disabled: - title: "Cap Anvil Cost ?" - description: "This config only work if Limit Repair Cost is disabled." - -config-ui.basic-config.max-anvil-cost: - item: "Max Anvil Cost" - title: "Max Anvil Cost" - description: - 1: "Max cost the Anvil can get to." - 2: "Valid values include 0 to 1000." - 3: "Cost will be displayed as Too Expensive:" - 4: "- If Cost is above 39" - 5: "- And Replace Too Expensive is disabled" - disabled: - title: "Max Anvil Cost" - description: "This config only work if Limit Repair Cost is disabled." - -config-ui.basic-config.remove-cost-limit: - item: "Remove Anvil Cost Limit" - title: "Remove Anvil Cost Limit ?" - description: - 1: "Whether the anvil's cost limit should be removed entirely." - 2: "The anvil will still visually display Too Expensive if Replace Too Expensive is disabled." - 3: "However, the action will be completable if xp requirement is meet." - -config-ui.basic-config.remove-too-expensive: - title: "Replace Too Expensive ?" - description: - 1: "Whenever anvil cost is above 39 should display the true price and not Too Expensive." - 2: "However, when bypassing Too Expensive, anvil price will be displayed as Green." - 3: "Even if cost is displayed as Green:" - 4: "If the player do not have the required xp level, the action will not be completable." - description-no-nms: - 1: "" - 2: "/!\\Caution/!\\ You need ProtocoLib installed and working, or a paper server." - 3: "Currently ProtocoLib is not detected." - -config-ui.basic-config.item-repair-cost: - title: "Item Repair Cost" - description: - 1: "XP Level amount added to the anvil when the item" - 2: "is repaired by another item of the same type." - -config-ui.basic-config.item-rename-cost: - title: "Rename Cost" - description: - 1: "XP Level amount added to the anvil when the item is renamed." - -config-ui.basic-config.unit-repair-cost: - title: "Unit Repair Cost" - description: - 1: "XP Level amount added to the anvil when the item is repaired by an unit." - 2: "For example: a Diamond on a Diamond Sword." - 3: "What's considered unit for what can be edited on the unit repair configuration." - -config-ui.basic-config.sacrifice-illegal-cost: - title: "Sacrifice Illegal Enchant Cost" - description: - 1: "XP Level amount added to the anvil when a sacrifice enchantment" - 2: "conflict With one of the left item enchantment" - -config-ui.basic-config.color-code: - title: "Allow Use Of Color Code ?" - description: - 1: "Whether players can use color code." - 2: "Color code a formatted like &a and is used in the rename field of the anvil." - 3: "Player may need permission to use color code if Player need permission to use color is enabled." - -config-ui.basic-config.color-hex: - title: "Allow Use Of Hexadecimal Color ?" - description: - 1: "Whether players can use hexadecimal color." - 2: "Color code a formatted like #012345 and is used in the rename field of the anvil." - 3: "Player may need permission to use color code if Permission Needed For Color is enabled." - -config-ui.basic-config.color-permission: - title: "Need Permission To Use Color ?" - description: - 1: "Whether players should have permission to be able to use colors." - 2: "Give player ca.color.code Permission to allow use of color code." - 3: "Give player ca.color.hex Permission to allow use of hexadecimal color." - disabled: - title: "Need Permission To Use Color ?" - description: - 1: "This config can do something only if one of the following config is enabled:" - 2: "- Allow Use Of Color Code" - 3: "- Allow Use Of Hexadecimal Color" - -config-ui.basic-config.color-cost: - item: "Cost Of Using Color" - title: "Cost Of Using Color" - description: - 1: "XP level cost when using color code or hexadecimal color using the anvil." - 2: "conflict With one of the left item enchantment" - disabled: - title: "Cost Of Using Color" - description: - 1: "This config can do something only if one of the following config is enabled:" - 2: "- Allow Use Of Color Code" - 3: "- Allow Use Of Hexadecimal Color" - -config-ui.basic-config.work-penalty: - title: "Work Penalty Type" - item: "Work Penalty Type" - lore: - 1: "Work penalty increase the price for every anvil use." - 2: "This config allow you to choose the comportment of work penalty." - lore-break: - 1: "" - 2: "About shared/exclusive penalty:" - explanation: - increasing: "Increasing: will penalty be increased (in item)" - additive: "Additive: will penalty be added to the cost" - shared: "Shared: Vanilla, shared penalty. it will be kept from before the plugin installation." - exclusive: "Exclusive: Custom, per anvil use type penalty. it will be lost after plugin uninstallation" \ No newline at end of file