diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 9d37521c..d3cfd8b3 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -17,7 +17,7 @@ These plugins have compatibility handled by custom anvil. seek help on custom an Also use ExcellentEnchant max enchant limit - [EcoEnchant](https://www.spigotmc.org/resources/ecoenchants-%E2%AD%95-250-enchantments-%E2%9C%85-create-custom-enchants-%E2%9C%A8-essentials-cmi-support.79573/) by Auxilor: - Need to use /anvilconfigreload or a server restart to add newly added enchantment. + Need to use /ca reload or a server restart to add newly added enchantment. Use EcoEnchant restriction system but new restriction can be added in custom anvil - [Enchantment²](https://www.spigotmc.org/resources/enchants-squared-the-enchantsplus-rewrite-custom-enchantments-that-act-like-vanilla-ones.86747/) by Athlaeos: diff --git a/build.gradle.kts b/build.gradle.kts index 4436e29e..76ab4c00 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.6" +version = "1.17.7" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 4e08ca20..377b3499 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 45d62c34..31506d2b 100644 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ b/defaultconfigs/1.18/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/defaultconfigs/1.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml index 3c1eb5d0..6963d2e4 100644 --- a/defaultconfigs/1.18/item_groups.yml +++ b/defaultconfigs/1.18/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml index 2902cce4..98fd0bec 100644 --- a/defaultconfigs/1.18/unit_repair_item.yml +++ b/defaultconfigs/1.18/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index 98f9a94d..8b5747b1 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use @@ -154,7 +154,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -293,9 +292,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 @@ -489,5 +485,5 @@ debug_log_verbose: false # Whether to show inside the console or require to run /ca debug get display_debug_in_console: false -configVersion: 1.15.5 +configVersion: 1.17.7 lowMinecraftVersion: 1.21.11 diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index 3d62daeb..18341d36 100644 --- a/defaultconfigs/1.21.11/enchant_conflict.yml +++ b/defaultconfigs/1.21.11/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts @@ -270,7 +270,6 @@ restriction_soul_speed: restriction_sweeping_edge: enchantments: - - minecraft:sweeping - minecraft:sweeping_edge notAffectedGroups: - enchanted_book diff --git a/defaultconfigs/1.21.11/item_groups.yml b/defaultconfigs/1.21.11/item_groups.yml index 9f2a877e..5d24cacf 100644 --- a/defaultconfigs/1.21.11/item_groups.yml +++ b/defaultconfigs/1.21.11/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21.11/unit_repair_item.yml b/defaultconfigs/1.21.11/unit_repair_item.yml index ed981b18..d742a056 100644 --- a/defaultconfigs/1.21.11/unit_repair_item.yml +++ b/defaultconfigs/1.21.11/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -104,7 +104,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 7b3afce1..c7700969 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use @@ -152,7 +152,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -290,9 +289,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index 9205061e..8ab9e3bc 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts @@ -267,7 +267,6 @@ restriction_soul_speed: restriction_sweeping_edge: enchantments: - - minecraft:sweeping - minecraft:sweeping_edge notAffectedGroups: - enchanted_book diff --git a/defaultconfigs/1.21.9/item_groups.yml b/defaultconfigs/1.21.9/item_groups.yml index 2dbd5db6..f7a00bcc 100644 --- a/defaultconfigs/1.21.9/item_groups.yml +++ b/defaultconfigs/1.21.9/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21.9/unit_repair_item.yml b/defaultconfigs/1.21.9/unit_repair_item.yml index 0ce2bce5..122b9657 100644 --- a/defaultconfigs/1.21.9/unit_repair_item.yml +++ b/defaultconfigs/1.21.9/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -98,7 +98,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index cb7e382b..1ef0d102 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use @@ -152,7 +152,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -287,9 +286,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index 45d62c34..d3b5d33c 100644 --- a/defaultconfigs/1.21/enchant_conflict.yml +++ b/defaultconfigs/1.21/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts @@ -157,13 +157,10 @@ restriction_soul_speed: notAffectedGroups: [ enchanted_book, boots ] restriction_sweeping_edge: - enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] + enchantments: [ minecraft:sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue restriction_swift_sneak: - useInFuture: true enchantments: [ minecraft:swift_sneak ] notAffectedGroups: [ enchanted_book, leggings ] diff --git a/defaultconfigs/1.21/item_groups.yml b/defaultconfigs/1.21/item_groups.yml index 3c1eb5d0..6963d2e4 100644 --- a/defaultconfigs/1.21/item_groups.yml +++ b/defaultconfigs/1.21/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21/unit_repair_item.yml b/defaultconfigs/1.21/unit_repair_item.yml index 2902cce4..b7873a12 100644 --- a/defaultconfigs/1.21/unit_repair_item.yml +++ b/defaultconfigs/1.21/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -98,7 +98,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: 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 3bd923bf..2fbc47ad 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 @@ -285,14 +285,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui { */ @Override public int getConfiguredValue() { - return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false); + return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false); } /** * @return The configured value for the enchant setting book value. */ public int getConfiguredBookValue() { - return ConfigOptions.INSTANCE.enchantmentValue(enchantment, true); + return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true); } @Override diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java index 660accb0..c548f228 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java @@ -2,10 +2,7 @@ package xyz.alexcrea.cuanvil.update; import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; -import xyz.alexcrea.cuanvil.update.minecraft.MCUpdate; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_11; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_9; +import xyz.alexcrea.cuanvil.update.minecraft.*; import xyz.alexcrea.cuanvil.update.plugin.*; import javax.annotation.Nonnull; @@ -32,10 +29,12 @@ public class UpdateHandler { new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate, new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate, new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate, - new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate + new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate, + new Version(1, 17, 7), PUpdate_1_17_7::handleUpdate ); private static final List mcUpdateMap = List.of( + new Update_1_20_5(), new Update_1_21(), new Update_1_21_9(), new Update_1_21_11() diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java index 2907fefb..4577b7a5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.update; import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import java.util.ArrayList; @@ -33,4 +34,20 @@ public class UpdateUtils { } + public static boolean removeFromList(FileConfiguration config, String path, String toRemove) { + List groups = new ArrayList<>(config.getStringList(path)); + if (!groups.remove(toRemove)) return false; + + config.set(path, groups); + return true; + } + + public static void mergeSections(ConfigurationSection source, ConfigurationSection target) { + for (String key : source.getKeys(false)) { + if(target.contains(key)) continue; + target.set(key, source.get(key)); + } + } + + } diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java new file mode 100644 index 00000000..53b996a6 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java @@ -0,0 +1,98 @@ +package xyz.alexcrea.cuanvil.update.minecraft; + +import org.bukkit.configuration.file.FileConfiguration; +import org.jetbrains.annotations.NotNull; +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.Version; + +import java.util.HashSet; +import java.util.Set; + +import static xyz.alexcrea.cuanvil.update.UpdateUtils.*; + +public class Update_1_20_5 extends MCUpdate { + + public Update_1_20_5() { + super(new Version(1, 20, 5)); + } + + @Override + protected void doUpdate() { + var tosave = new HashSet(); + updateName(tosave); + + for (ConfigHolder holder : tosave) { + holder.saveToDisk(true); + } + } + + private static String SWEEPING_ENCHANTS = "restriction_sweeping_edge.enchantments"; + + public static void updateName(@NotNull Set tosave) { + var config = ConfigHolder.DEFAULT_CONFIG.getConfig(); + var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); + var conflict = ConfigHolder.CONFLICT_HOLDER.getConfig(); + + // Rename sweeping to sweeping_edge + migrateEnchantLimit(config, "minecraft:sweeping"); + migrateEnchantLimit(config, "sweeping"); + + migrateEnchantValues(config, "minecraft:sweeping"); + migrateEnchantValues(config, "sweeping"); + + if (removeFromList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping")) + addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge"); + if (removeFromList(conflict, SWEEPING_ENCHANTS, "sweeping")) + addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge"); + + // Rename scute to turtle_scute + migrateUnitRepair(unitConfig, "minecraft:scute"); + migrateUnitRepair(unitConfig, "scute"); + + ConfigHolder.ITEM_GROUP_HOLDER.reload(); + + tosave.add(ConfigHolder.DEFAULT_CONFIG); + tosave.add(ConfigHolder.UNIT_REPAIR_HOLDER); + tosave.add(ConfigHolder.CONFLICT_HOLDER); + } + + private static void migrateEnchantLimit(FileConfiguration config, String path) { + var finalPath = "enchant_limits." + path; + if (!config.isInt(finalPath)) return; + var value = config.getInt(finalPath); + + config.set(finalPath, null); + if (!config.contains("enchant_limits.minecraft:sweeping_edge")) return; + if (!config.contains("enchant_limits.sweeping_edge")) return; + + config.set("enchant_limits.minecraft:sweeping_edge", value); + } + + private static void migrateEnchantValues(FileConfiguration config, String path) { + migrateEnchantValues(config, path, "item"); + migrateEnchantValues(config, path, "book"); + } + + private static void migrateEnchantValues(FileConfiguration config, String path, String child) { + var finalPath = "enchant_values." + path + "." + child; + if (config.isInt(finalPath)) return; + var value = config.getInt(finalPath); + + config.set(finalPath, null); + if (!config.contains("enchant_values.minecraft:sweeping_edge." + child)) return; + if (!config.contains("enchant_values.sweeping_edge." + child)) return; + + config.set("enchant_values.minecraft:sweeping_edge." + child, value); + } + + private static void migrateUnitRepair(FileConfiguration config, String path) { + var section = config.getConfigurationSection(path); + if (section == null) return; + + config.set(path, null); + var turtle_scute = config.getConfigurationSection("minecraft:turtle_scute"); + if (turtle_scute == null) config.set("minecraft:turtle_scute", section); + else mergeSections(section, turtle_scute); + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java new file mode 100644 index 00000000..972825dd --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java @@ -0,0 +1,21 @@ +package xyz.alexcrea.cuanvil.update.plugin; + +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; +import xyz.alexcrea.cuanvil.update.minecraft.Update_1_20_5; + +import javax.annotation.Nonnull; +import java.util.Set; + +public class PUpdate_1_17_7 { + + public static void handleUpdate(@Nonnull Set toSave) { + // fix only needed for 1.20.5 and above + Version current = UpdateUtils.currentMinecraftVersion(); + if (new Version(1, 20, 5).greaterThan(current)) return; + + Update_1_20_5.updateName(toSave); + } + +} diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index fc8a53a9..9b0c4cd0 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -86,6 +86,7 @@ object ConfigOptions { // Keys for specific enchantment values private const val KEY_BOOK = "book" + private const val KEY_BOOK_ON_BOOK = "book_on_book" private const val KEY_ITEM = "item" // Debug flag @@ -578,14 +579,15 @@ object ConfigOptions { */ fun enchantmentValue( enchantment: CAEnchantment, - isFromBook: Boolean + isToBook: Boolean, + isFromBook: Boolean, ): Int { // Test namespace - var limit = enchantmentValue(enchantment.key.toString(), isFromBook) + var limit = enchantmentValue(enchantment.key.toString(), isToBook, isFromBook) if (limit != null) return limit // Test legacy (name only) - limit = enchantmentValue(enchantment.enchantmentName, isFromBook) + limit = enchantmentValue(enchantment.enchantmentName, isToBook, isFromBook) if (limit != null) return limit // get default (and test old legacy if present) @@ -599,13 +601,22 @@ object ConfigOptions { */ private fun enchantmentValue( enchantmentName: String, - isFromBook: Boolean + isToBook: Boolean, + isFromBook: Boolean, ): Int? { val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey" - return CustomAnvil.instance - .config - .getInt(path, DEFAULT_ENCHANT_VALUE - 1) + + val config = ConfigHolder.DEFAULT_CONFIG.config + if(isFromBook && isToBook) { + val specialPath = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$KEY_BOOK_ON_BOOK" + + if(config.isInt(specialPath)) + return config.getInt(specialPath) + .takeIf { it >= DEFAULT_ENCHANT_VALUE } + } + + return config.getInt(path, DEFAULT_ENCHANT_VALUE - 1) .takeIf { it >= DEFAULT_ENCHANT_VALUE } } @@ -613,20 +624,9 @@ object ConfigOptions { * Get default value if enchantment do not exist on config */ private fun getDefaultValue( - enchantment: CAEnchantment, // compatibility with 1.20.5. TODO better update system + enchantment: CAEnchantment, isFromBook: Boolean ): Int { - - val enchantmentName = enchantment.key.toString() - if (enchantmentName == "minecraft:sweeping_edge") { - var limit = enchantmentValue("minecraft:sweeping", isFromBook) - if (limit != null) return limit - - // legacy name - limit = enchantmentValue("sweeping", isFromBook) - if (limit != null) return limit - } - val rarity = enchantment.defaultRarity() return if (isFromBook) rarity.bookValue @@ -648,15 +648,6 @@ object ConfigOptions { value = maxBeforeMergeDisabled(legacy) if (value >= 0) return value - if (key == "minecraft:sweeping_edge") { - value = maxBeforeMergeDisabled("minecraft:sweeping") - if (value >= 0) return value - - // legacy name of legacy enchantment name - value = maxBeforeMergeDisabled("sweeping") - if (value >= 0) return value - } - return DEFAULT_MAX_BEFORE_MERGE_DISABLED } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index fba89b71..d26db8c2 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -25,7 +25,7 @@ class EditConfigExecutor: CASubCommand() { sender.sendMessage("§eIt is may come in a future version.") sender.sendMessage("") sender.sendMessage("§eCurrently you need to edit manually the config or copy from another server (spigot or better)") - sender.sendMessage("§eThen /anvilconfigreload after config file is edited") + sender.sendMessage("§eThen /ca reload after config file is edited") return false } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 5b256dd8..39def31f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -39,13 +39,6 @@ class EnchantConflictManager { // Default name for a joining group const val DEFAULT_GROUP_NAME = "joinedGroup" - - // 1.20.5 compatibility TODO better update system - private val SWEEPING_EDGE_ENCHANT = Collections.singletonList( - CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) - ?: CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key) - ) - } lateinit var conflictList: ArrayList @@ -172,14 +165,6 @@ class EnchantConflictManager { } - // Temporary solution for 1.20.5 - when (enchantName) { - "minecraft:sweeping", "sweeping", - "minecraft:sweeping_edge", "sweeping_edge" -> { - return SWEEPING_EDGE_ENCHANT - } - } - return CAEnchantment.getListByName(enchantName) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 9d2f5420..78ea8830 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.group.ConflictType import xyz.alexcrea.cuanvil.util.AnvilTitleUtil import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +import kotlin.math.sqrt object AnvilXpUtil { @@ -35,8 +36,9 @@ object AnvilXpUtil { inventory: AnvilInventory, view: InventoryView, player: Player, - result: AnvilResult) { - if(result.item == null) { + result: AnvilResult + ) { + if (result.item == null) { onNoResult(player, view) return } @@ -246,7 +248,8 @@ object AnvilXpUtil { fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) { // Calculate right value and illegal enchant penalty - val rightIsFormBook = right.isEnchantedBook() + val isToBook = left.isEnchantedBook() + val isFromBook = right.isEnchantedBook() val rightEnchs = EnchantmentApi.getEnchantments(right) val resultEnchs = EnchantmentApi.getEnchantments(result) val resultEnchsKeys = HashMap(resultEnchs) @@ -274,22 +277,21 @@ object AnvilXpUtil { // We know "enchantment.key in resultEnchs" true val resultLevel = resultEnchs[enchantment.key]!! - val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook) + val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook) val value = resultLevel * enchantmentMultiplier CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)") rightValue += value } - if(ConfigOptions.includeLeftEnchantmentForCost) { - val leftIsFormBook = left.isEnchantedBook() + if (ConfigOptions.includeLeftEnchantmentForCost) { val leftEnchs = EnchantmentApi.getEnchantments(left) for (enchantment in leftEnchs) { // Do not process enchantment that are present on the sacrifice - if(rightEnchs.contains(enchantment.key)) continue + if (rightEnchs.contains(enchantment.key)) continue val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0) - val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook) + val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook) val value = resultLevel * enchantmentMultiplier CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)") leftValue += value @@ -312,15 +314,15 @@ object AnvilXpUtil { */ fun calculateLevelForXp(xp: Int): Int { return when { - xp <= 352 -> (Math.sqrt((xp + 9).toDouble()) - 3).toInt() + xp <= 352 -> (sqrt((xp + 9).toDouble()) - 3).toInt() xp <= 1507 -> { val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0) - (81.0 / 10.0 + Math.sqrt(inner)).toInt() + (81.0 / 10.0 + sqrt(inner)).toInt() } else -> { val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0) - (325.0 / 18.0 + Math.sqrt(inner)).toInt() + (325.0 / 18.0 + sqrt(inner)).toInt() } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c8fefb53..0a0c5664 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit most of these config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 45d62c34..31506d2b 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index 8a62f3dc..f2042f03 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/src/main/resources/unit_repair_item.yml b/src/main/resources/unit_repair_item.yml index 2902cce4..98fd0bec 100644 --- a/src/main/resources/unit_repair_item.yml +++ b/src/main/resources/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration diff --git a/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java b/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java index ac3f73ea..a92b1d71 100644 --- a/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java +++ b/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java @@ -49,8 +49,8 @@ public class DefaultConfigTests extends SharedCustomAnvilTest { CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key); Assertions.assertNotNull(enchantment, "Enchantment was somehow not found"); - int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false); - int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, true); + int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false); + int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true); EnchantmentRarity rarity = enchantment.defaultRarity();