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 a903366..5fd12a3 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 @@ -69,12 +69,13 @@ public class BasicConfigGui extends ValueUpdatableGui { updateGuiValues(); } - private BoolSettingsGui.BoolSettingFactory limitRepairFactory; // L character - private IntSettingsGui.IntSettingFactory repairCostFactory; // C character - private GuiItem notNeededLimitValueItem; + private BoolSettingsGui.BoolSettingFactory capAnvilCostFactory; // L character + private GuiItem noCapRepairItem; + private IntSettingsGui.IntSettingFactory maxAnvilCostFactory; // C character + private GuiItem noMaxCostItem; - private BoolSettingsGui.BoolSettingFactory removeRepairLimit; // R character - private BoolSettingsGui.BoolSettingFactory replaceToExpensive; // T character + private BoolSettingsGui.BoolSettingFactory removeAnvilCostLimit; // R character + private BoolSettingsGui.BoolSettingFactory replaceTooExpensive; // T character private IntSettingsGui.IntSettingFactory itemRepairCost; // I character private IntSettingsGui.IntSettingFactory unitRepairCost; // U character @@ -85,45 +86,61 @@ public class BasicConfigGui extends ValueUpdatableGui { * Prepare basic gui displayed items factory and static items.. */ protected void prepareValues() { - // limit repair item - this.limitRepairFactory = BoolSettingsGui.boolFactory("\u00A78Limit Repair Cost ?", this, - ConfigOptions.LIMIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_LIMIT_REPAIR, - "\u00A77Whether all anvil actions cost should be capped.", - "\u00A77If true, all anvil repairs will max out at the value of \u00A7aLimit Repair Value\u00A77."); - - // repair cost item - IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE; - this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this, - ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, - Arrays.asList( - "\u00A77Value to limit repair costs to when \u00A7aLimit Repair Value\u00A77 is true.", - "\u00A77Valid values include \u00A7e1 \u00A77to \u00A7e39\u00A77: " + - "vanilla would display \u00A7e40+\u00A77 as \u00A7ctoo expensive\u00A77." - ), - range.getFirst(), range.getLast(), - ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE, - 1, 5, 10); - - // repair cost not needed + // cap anvil cost + this.capAnvilCostFactory = BoolSettingsGui.boolFactory("\u00A78Cap Anvil Cost ?", this, + ConfigHolder.DEFAULT_CONFIG, + ConfigOptions.CAP_ANVIL_COST, ConfigOptions.DEFAULT_CAP_ANVIL_COST, + "\u00A77All anvil cost will be capped to \u00A7aMax Anvil Cost\u00A77 if enabled.", + "\u00A77In other words:", + "\u00A77For any anvil cost greater than \u00A7aMax Anvil Cost\u00A77, Cost will be set to \u00A7aMax Anvil Cost\u00A77."); + // cap anvil cost not needed ItemStack item = new ItemStack(Material.BARRIER); ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName("\u00A7cLimit Repair Value"); - meta.setLore(Collections.singletonList("\u00A77This config need \u00A7cLimit Repair Cost\u00A77 enabled.")); + meta.setDisplayName("\u00A7cCap Anvil Cost ?"); + meta.setLore(Collections.singletonList("\u00A77This config only work if \u00A7cLimit Repair Cost\u00A77 is disabled.")); item.setItemMeta(meta); - this.notNeededLimitValueItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); + this.noCapRepairItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); + + + // repair cost item + IntRange range = ConfigOptions.MAX_ANVIL_COST_RANGE; + this.maxAnvilCostFactory = IntSettingsGui.intFactory("\u00A78Max Anvil Cost", this, + ConfigOptions.MAX_ANVIL_COST, ConfigHolder.DEFAULT_CONFIG, + Arrays.asList( + "\u00A77Max cost the Anvil can get to.", + "\u00A77Valid values include \u00A7e1 \u00A77to \u00A7e255\u00A77.", + "\u00A77Cost will be displayed as \u00A7cToo Expensive\u00A77:", + "\u00A77- If Cost is above \u00A7e39", + "\u00A77- And \u00A7eReplace Too Expensive\u00A77 is disabled" + ), + range.getFirst(), range.getLast(), + ConfigOptions.DEFAULT_MAX_ANVIL_COST, + 1, 5, 10); + // max anvil cost not needed + item = new ItemStack(Material.BARRIER); + meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("\u00A7cMax Anvil Cost"); + meta.setLore(Collections.singletonList("\u00A77This config only work if \u00A7cLimit Repair Cost\u00A77 is disabled.")); + item.setItemMeta(meta); + this.noMaxCostItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance); + // remove repair limit item - this.removeRepairLimit = BoolSettingsGui.boolFactory("\u00A78Remove Repair Limit ?", this, - ConfigOptions.REMOVE_REPAIR_LIMIT, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REMOVE_LIMIT, - "\u00A77Whether the anvil's repair limit should be removed entirely.", - "\u00A77The anvil will still visually display \u00A7cto expensive\u00A77.", - "\u00A77However the action will be completable."); + this.removeAnvilCostLimit = BoolSettingsGui.boolFactory("\u00A78Remove Anvil Cost Limit ?", this, + ConfigHolder.DEFAULT_CONFIG, + ConfigOptions.REMOVE_ANVIL_COST_LIMIT, ConfigOptions.DEFAULT_REMOVE_ANVIL_COST_LIMIT, + "\u00A77Whether the anvil's cost limit should be removed entirely.", + "\u00A77The anvil will still visually display \u00A7cToo Expensive\u00A77 if \u00A7eReplace Too Expensive\u00A77 is disabled.", + "\u00A77However, the action will be completable if xp requirement is meet."); - // replace to expensive item - this.replaceToExpensive = BoolSettingsGui.boolFactory("\u00A78Replace To Expensive ?", this, - ConfigOptions.REPLACE_TO_EXPENSIVE, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REPLACE_TO_EXPENSIVE, + // replace too expensive item + this.replaceTooExpensive = BoolSettingsGui.boolFactory("\u00A78Replace Too Expensive ?", this, + ConfigHolder.DEFAULT_CONFIG, + ConfigOptions.REPLACE_TOO_EXPENSIVE, ConfigOptions.DEFAULT_REPLACE_TOO_EXPENSIVE, getReplaceToExpensiveLore()); // item repair cost @@ -178,9 +195,10 @@ public class BasicConfigGui extends ValueUpdatableGui { @NotNull private String[] getReplaceToExpensiveLore() { ArrayList lore = new ArrayList<>(); - lore.add("\u00A77Whenever anvil cost is above \u00A7e39\u00A77 should display the true price and not \u00A7cto expensive\u00A77."); - lore.add("\u00A77However, when cost is above \u00A7e39\u00A77, anvil price will be displayed as \u00A7aGreen\u00A77,"); - lore.add("\u00A77even if player do not have the required xp level. But the action will not be completable."); + lore.add("\u00A77Whenever anvil cost is above \u00A7e39\u00A77 should display the true price and not \u00A7cToo Expensive\u00A77."); + lore.add("\u00A77However, when bypassing \u00A7cToo Expensive\u00A77, anvil price will be displayed as \u00A7aGreen\u00A77."); + lore.add("\u00A77Even if cost is displayed as \u00A7aGreen\u00A77:"); + lore.add("\u00A77If the player do not have the required xp level, the action will not be completable."); if(!this.packetManager.isProtocoLibInstalled()){ lore.add(""); @@ -193,25 +211,26 @@ public class BasicConfigGui extends ValueUpdatableGui { @Override public void updateGuiValues() { - // limit repair item - GuiItem limitRepairItem = this.limitRepairFactory.getItem(); - pane.bindItem('L', limitRepairItem); - - // rename cost item - GuiItem limitRepairValueItem; - if (this.limitRepairFactory.getConfiguredValue()) { - limitRepairValueItem = this.repairCostFactory.getItem(Material.EXPERIENCE_BOTTLE); + // limit and cap anvil cost item + GuiItem capAnvilCostItem; + GuiItem maxAnvilCostItem; + if (!this.removeAnvilCostLimit.getConfiguredValue()) { + capAnvilCostItem = this.capAnvilCostFactory.getItem("Cap Anvil Cost"); + maxAnvilCostItem = this.maxAnvilCostFactory.getItem(Material.EXPERIENCE_BOTTLE, "Max Anvil Cost"); } else { - limitRepairValueItem = this.notNeededLimitValueItem; + capAnvilCostItem = this.noCapRepairItem; + maxAnvilCostItem = this.noMaxCostItem; } - pane.bindItem('C', limitRepairValueItem); + + pane.bindItem('L', capAnvilCostItem); + pane.bindItem('C', maxAnvilCostItem); // remove repair limit item - GuiItem removeRepairLimitItem = this.removeRepairLimit.getItem(); + GuiItem removeRepairLimitItem = this.removeAnvilCostLimit.getItem("Remove Anvil Cost Limit"); pane.bindItem('R', removeRepairLimitItem); - // replace to expensive item - GuiItem replaceToExpensiveItem = this.replaceToExpensive.getItem(); + // replace too expensive item + GuiItem replaceToExpensiveItem = this.replaceTooExpensive.getItem(); pane.bindItem('T', replaceToExpensiveItem); 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 1e85c90..dc3d2d9 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 @@ -51,7 +51,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui displayLore, int scale, boolean asPercentage, boolean nullOnZero, double min, double max, double defaultVal, double... steps) { return new DoubleSettingFactory( title, parent, - configPath, config, + config, + configPath, displayLore, scale, asPercentage, nullOnZero, min, max, defaultVal, steps); @@ -408,8 +410,8 @@ public class DoubleSettingGui extends AbstractSettingGui { * * @param title The title of the gui. * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param configPath Configuration path of this setting. * @param displayLore Gui display item lore. * @param scale The scale of the decimal. * @param asPercentage If we should display the value as a %. @@ -424,7 +426,8 @@ public class DoubleSettingGui extends AbstractSettingGui { */ protected DoubleSettingFactory( @NotNull String title, @NotNull ValueUpdatableGui parent, - @NotNull String configPath, @NotNull ConfigHolder config, + @NotNull ConfigHolder config, + @NotNull String configPath, @Nullable List displayLore, int scale, boolean asPercentage, boolean nullOnZero, double min, double max, double defaultVal, double... steps) { 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 50df43b..0e3c3f8 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 @@ -243,8 +243,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui { * * @param title The title of the gui. * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. * @param config Configuration holder of this setting. + * @param configPath Configuration path of this setting. * @param displayLore Gui display item lore. * @param min Minimum value of this setting. * @param max Maximum value of this setting. @@ -258,7 +258,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { */ public static EnchantCostSettingFactory enchantCostFactory( @NotNull String title, @NotNull ValueUpdatableGui parent, - @NotNull String configPath, @NotNull ConfigHolder config, + @NotNull ConfigHolder config, @NotNull String configPath, @Nullable List displayLore, int min, int max, int defaultItemVal, int defaultBookVal, int... steps) { diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index 9af67c8..12e6550 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -522,8 +522,11 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener { ignoreRules: Boolean = false ) { // Test repair cost limit - val finalAnvilCost = if (ConfigOptions.limitRepairCost && !ignoreRules) { - min(anvilCost, ConfigOptions.limitRepairValue) + val finalAnvilCost = if ( + !ignoreRules && + !ConfigOptions.doRemoveCostLimit && + ConfigOptions.doCapCost) { + min(anvilCost, ConfigOptions.maxAnvilCost) } else { anvilCost } @@ -535,22 +538,26 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener { .server .scheduler .runTask(CustomAnvil.instance, Runnable { - if (ConfigOptions.removeRepairLimit || ignoreRules) { - inventory.maximumRepairCost = Int.MAX_VALUE - } else{ - inventory.maximumRepairCost = 40 // minecraft default - } - inventory.repairCost = finalAnvilCost + inventory.maximumRepairCost = + if (ConfigOptions.doRemoveCostLimit || ignoreRules) + { Int.MAX_VALUE } + else + { ConfigOptions.maxAnvilCost + 1 } + inventory.repairCost = finalAnvilCost event.view.setProperty(REPAIR_COST, finalAnvilCost) val player = event.view.player if(player is Player){ if(player.gameMode != GameMode.CREATIVE ){ - packetManager.setInstantBuild(player, (ConfigOptions.replaceToExpensive) && (finalAnvilCost >= 40)) - } - player.updateInventory() + val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) && + (finalAnvilCost >= 40) && + finalAnvilCost < inventory.maximumRepairCost + packetManager.setInstantBuild(player, bypassToExpensive) + } + + player.updateInventory() } }) } diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index e74df1f..89fe04b 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -10,17 +10,17 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder */ object ConfigOptions { - // Path for limiting repair cost - const val LIMIT_REPAIR_COST = "limit_repair_cost" + // Path for limiting anvil cost + const val CAP_ANVIL_COST = "limit_repair_cost" - // Path for repair value limit - const val LIMIT_REPAIR_VALUE = "limit_repair_value" + // Path for max anvil cost value + const val MAX_ANVIL_COST = "limit_repair_value" - // Path for removing repair cost limits - const val REMOVE_REPAIR_LIMIT = "remove_repair_limit" + // Path for removing anvil cost limits + const val REMOVE_ANVIL_COST_LIMIT = "remove_repair_limit" - // Path for removing repair cost limits - const val REPLACE_TO_EXPENSIVE = "replace_to_expensive" + // Path for removing too expensive when unused + const val REPLACE_TOO_EXPENSIVE = "replace_too_expensive" // Path for level cost on item repair const val ITEM_REPAIR_COST = "item_repair_cost" @@ -58,16 +58,16 @@ object ConfigOptions { // Default value for limiting repair cost - const val DEFAULT_LIMIT_REPAIR = false + const val DEFAULT_CAP_ANVIL_COST = false // Default value for repair cost limit - const val DEFAULT_LIMIT_REPAIR_VALUE = 39 + const val DEFAULT_MAX_ANVIL_COST = 39 // Default for removing repair cost limits - const val DEFAULT_REMOVE_LIMIT = false + const val DEFAULT_REMOVE_ANVIL_COST_LIMIT = false // Default for removing repair cost limits - const val DEFAULT_REPLACE_TO_EXPENSIVE = false + const val DEFAULT_REPLACE_TOO_EXPENSIVE = false // Default value for level cost on item repair const val DEFAULT_ITEM_REPAIR_COST = 2 @@ -94,7 +94,7 @@ object ConfigOptions { // Valid range for repair cost limit @JvmField - val REPAIR_LIMIT_RANGE = 1..255 + val MAX_ANVIL_COST_RANGE = 1..255 // Valid range for repair cost @JvmField @@ -117,45 +117,45 @@ object ConfigOptions { private const val DEFAULT_ENCHANT_VALUE = 0 /** - * Whether to limit repair costs to the vanilla limit + * Whether to cap anvil costs */ - val limitRepairCost: Boolean + val doCapCost: Boolean get() { return ConfigHolder.DEFAULT_CONFIG .config - .getBoolean(LIMIT_REPAIR_COST, DEFAULT_LIMIT_REPAIR) + .getBoolean(CAP_ANVIL_COST, DEFAULT_CAP_ANVIL_COST) } /** - * Value to limit repair costs to + * Value to limit anvil costs to */ - val limitRepairValue: Int + val maxAnvilCost: Int get() { return ConfigHolder.DEFAULT_CONFIG .config - .getInt(LIMIT_REPAIR_VALUE, DEFAULT_LIMIT_REPAIR_VALUE) - .takeIf { it in REPAIR_LIMIT_RANGE } - ?: DEFAULT_LIMIT_REPAIR_VALUE + .getInt(MAX_ANVIL_COST, DEFAULT_MAX_ANVIL_COST) + .takeIf { it in MAX_ANVIL_COST_RANGE } + ?: DEFAULT_MAX_ANVIL_COST + } + + /** + * Whether to remove anvil cost limit + */ + val doRemoveCostLimit: Boolean + get() { + return ConfigHolder.DEFAULT_CONFIG + .config + .getBoolean(REMOVE_ANVIL_COST_LIMIT, DEFAULT_REMOVE_ANVIL_COST_LIMIT) } /** * Whether to remove repair cost limit */ - val removeRepairLimit: Boolean + val doReplaceTooExpensive: Boolean get() { return ConfigHolder.DEFAULT_CONFIG .config - .getBoolean(REMOVE_REPAIR_LIMIT, DEFAULT_REMOVE_LIMIT) - } - - /** - * Whether to remove repair cost limit - */ - val replaceToExpensive: Boolean - get() { - return ConfigHolder.DEFAULT_CONFIG - .config - .getBoolean(REPLACE_TO_EXPENSIVE, DEFAULT_REPLACE_TO_EXPENSIVE) + .getBoolean(REPLACE_TOO_EXPENSIVE, DEFAULT_REPLACE_TOO_EXPENSIVE) } /** @@ -315,13 +315,14 @@ object ConfigOptions { fun getBasicConfigKeys(): Array { return arrayOf( DEFAULT_LIMIT_PATH, - LIMIT_REPAIR_COST, - LIMIT_REPAIR_VALUE, + CAP_ANVIL_COST, + MAX_ANVIL_COST, + REPLACE_TOO_EXPENSIVE, ITEM_REPAIR_COST, UNIT_REPAIR_COST, ITEM_RENAME_COST, SACRIFICE_ILLEGAL_COST, - REMOVE_REPAIR_LIMIT + REMOVE_ANVIL_COST_LIMIT ) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt index 46f7cf5..3d080f1 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt @@ -7,7 +7,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder object MetricsUtil { - private const val baseConfigHash = -1592940914 + private const val baseConfigHash = 1000387384 private const val enchantLimitsConfigHash = -275034280 private const val enchantValuesConfigHash = -17048020 private const val enchantConflictConfigHash = 546475833 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b79f5d5..703867f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,27 +1,31 @@ -# Whether all anvil actions cost should be capped +# All anvil cost will be capped to limit_repair_value if enabled. # -# If true, all anvil repairs will max out at the value of limit_repair_value +# In other words: +# For any anvil cost greater than limit_repair_value, Cost will be set to limit_repair_value. limit_repair_cost: false -# Value to limit repair costs to when limit_repair_cost is true +# Max cost value the Anvil can get to. # -# Valid values include 1 to 255 (anvil will display cost above 39 as "too expensive" if "replace_to_expensive" is false) +# Valid values include 1 to 255. +# Cost will be displayed as "Too Expensive": +# - If Cost is above 39 +# - And replace_too_expensive is disabled (false) limit_repair_value: 39 -# Whether the anvil's repair limit should be removed entirely +# Whether the anvil's cost limit should be removed entirely. # -# The anvil will still visually display "too expensive" if "replace_to_expensive" is false. +# The anvil will still visually display "Too Expensive" if "replace_too_expensive" is disabled # However, the action will be completable if xp requirement is meet. remove_repair_limit: false -# Whenever anvil cost is above 39 should display the true price and not "to expensive". +# Whenever anvil cost is above 39 should display the true price and not "Too Expensive". # -# However, when cost is above 39, anvil price will be displayed as green, -# even if player do not have the required xp level. -# But the action will not be completable. +# However, when bypassing "Too Expensive", anvil price will be displayed as Green. +# If the action is not completable, the cost will still be displayed as "Too expensive". +# That mean you also need to change other settings like remove_repair_limit or limit_repair_cost. # # Require ProtocoLib. -replace_to_expensive: false +replace_too_expensive: false # XP Level amount added to the anvil when the item is repaired by another item of the same type # @@ -239,4 +243,4 @@ debug_log: false # Whether to show verbose debug logging debug_log_verbose: false -configVersion: 1.4.4 +configVersion: 1.4.5