From a202df9f0af21daea8cb8cd20e80adc838600e77 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:28:10 +0200 Subject: [PATCH 1/6] add /ca enchant --- README.md | 3 +- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 2 + .../alexcrea/cuanvil/command/CASubCommand.kt | 11 ++ .../cuanvil/command/CustomAnvilCommand.kt | 8 +- .../cuanvil/command/EditConfigExecutor.kt | 12 -- .../cuanvil/command/EnchantExecutor.kt | 113 ++++++++++++++++++ .../cuanvil/command/ReloadExecutor.kt | 1 - src/main/resources/plugin.yml | 3 + 8 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt diff --git a/README.md b/README.md index 9d9e678e..27d08fac 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,8 @@ ca.bypass.level: Allow player to bypass every level limit (no custom limit) # Command permissions ca.command.reload: Allow administrator to reload the plugin's configs -ca.command.diagnostic: Allow adminastator to diagnistic some simple problem with the plugin +ca.command.diagnostic: Get debug information about the plugin and server +ca.command.enchantment: Allows to set enchantment to holden item ca.config.edit: Allow administrator to edit the plugin's config in game # ----------------------------------------------------------------------------- diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index a5cac722..906e023f 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -57,6 +57,8 @@ open class CustomAnvil : JavaPlugin() { // Permission string required to edit the plugin's config const val editConfigPermission = "ca.config.edit" + // Permission string required to edit the plugin's config + const val giveEnchantmentPermission = "ca.command.enchantment" // Command Name to reload the config const val commandReloadName = "anvilconfigreload" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 4c71c68b..60dcdbee 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -4,6 +4,7 @@ import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender +import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry abstract class CASubCommand: CommandExecutor { @@ -43,4 +44,14 @@ abstract class CASubCommand: CommandExecutor { return "no description" } + protected fun allEnchantmentsByName(): Collection { + val names = mutableSetOf() + for (enchantment in CAEnchantmentRegistry.getInstance().values()) { + names.add(enchantment.name) + names.add(enchantment.key.toString()) + } + + return names + } + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 9287a7c7..9b9402c9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -7,7 +7,6 @@ import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter import xyz.alexcrea.cuanvil.util.MetricsUtil -import java.util.ArrayList class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { @@ -18,13 +17,14 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { private val editConfigCommand = EditConfigExecutor() private val helpCommand = HelpExecutor() - private val commands = ImmutableMap.of( + private val commands: ImmutableMap = ImmutableMap.of( "gui", editConfigCommand, "config", editConfigCommand, "reload", ReloadExecutor(), "diagnostic", DiagnosticExecutor(), "debug", DebugToggleExecutor(), "help", helpCommand, + "enchant", EnchantExecutor(), ) init { @@ -95,9 +95,11 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { } //assumed all provided tab completed string are lowercase + val prefix = args[args.size - 1] return result.stream() - .filter { it.startsWith(args[args.size - 1]) } + .filter { it.startsWith(prefix) } .sorted() .toList() } + } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index b11bfb4a..c6bc191b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -7,7 +7,6 @@ import org.bukkit.entity.HumanEntity import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantment -import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui @@ -103,16 +102,6 @@ class EditConfigExecutor : CASubCommand() { // Tab completer // --------------- - private fun allEnchantmentsByName(): Collection { - val names = mutableSetOf() - for (enchantment in CAEnchantmentRegistry.getInstance().values()) { - names.add(enchantment.name) - names.add(enchantment.key.toString()) - } - - return names - } - override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { list.addAll( when (args.size) { @@ -127,7 +116,6 @@ class EditConfigExecutor : CASubCommand() { else -> listOf() } ) - } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt new file mode 100644 index 00000000..dd2957fa --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt @@ -0,0 +1,113 @@ +package xyz.alexcrea.cuanvil.command + +import io.delilaheve.CustomAnvil +import io.delilaheve.util.ConfigOptions +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.bukkit.entity.HumanEntity +import xyz.alexcrea.cuanvil.api.EnchantmentApi +import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir + +class EnchantExecutor : CASubCommand() { + + + override fun allowed(sender: CommandSender): Boolean { + return sender.hasPermission(CustomAnvil.giveEnchantmentPermission) + } + + override fun description(): String { + return "Allows to set enchantment to holden item" + } + + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { + if (sender !is HumanEntity) return true + + if (!allowed(sender)) { + sender.sendMessage("No permission to execute this command") + return true + } + + when (args.size) { + 0 -> { + sender.sendMessage("Missing enchantment parameter") + return true + } + + 1 -> { + sender.sendMessage("Missing level parameter") + return true + } + } + + val enchants = EnchantmentApi.getListByName(args[0].lowercase()) + if (enchants.isEmpty()) { + sender.sendMessage("Enchantment not found: ${args[0]}") + return true + } + + val enchant = enchants.iterator().next() + + val level = args[1].toIntOrNull()?.coerceIn(0, ConfigOptions.ENCHANT_LIMIT) + if (level == null) { + sender.sendMessage("Invalid number: ${args[1]}") + return true + } + + val inHand = sender.inventory.itemInMainHand + if (inHand.isAir) { + sender.sendMessage("Cannot enchant this item") + return true + } + + if (level == 0) { + enchant.removeFrom(inHand) + sender.sendMessage("${enchant.prettyName} removed") + } else { + enchant.addEnchantmentUnsafe(inHand, level) + sender.sendMessage("${enchant.prettyName} set to level $level") + } + + return true + } + + override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { + if (sender !is HumanEntity) return + + list.addAll( + when (args.size) { + 1 -> allEnchantmentsByName() + 2 -> findEnchantmentLevels(sender, args[0]) + + else -> listOf() + } + ) + } + + private fun findEnchantmentLevels( + sender: HumanEntity, + name: String + ): Collection { + val enchants = EnchantmentApi.getListByName(name.lowercase()) + if (enchants.isEmpty()) return listOf() + + val enchant = enchants.iterator().next() + val limit = ConfigOptions.enchantLimit(enchant) + val result = mutableListOf() + + for (i in 1 until limit + 1) { + result.add(i.toString()) + } + + val inHand = sender.inventory.itemInMainHand + if (enchant.isEnchantmentPresent(inHand)) + result.add("0") + + return result + } + +} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index ef23e7d6..cb0d24a9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -3,7 +3,6 @@ package xyz.alexcrea.cuanvil.command import io.delilaheve.CustomAnvil import org.bukkit.Bukkit import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent import xyz.alexcrea.cuanvil.config.ConfigHolder diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dab9997b..d436b10a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -43,6 +43,9 @@ permissions: ca.command.diagnostic: default: op description: Get debug information about the plugin and server + ca.command.enchantment: + default: op + description: Allows to set enchantment to holden item ca.config.edit: default: op description: Allow administrator to edit the plugin's config in game From 4fc037ebcedd07e48890945959bc910bb9cc188f Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:28:41 +0200 Subject: [PATCH 2/6] version bump --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 76ab4c00..3c34895e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.7" +version = "1.18.0" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" From cf768d67bd57bdaaadc4657ddae5c2dbaf46e89b Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:42:14 +0200 Subject: [PATCH 3/6] more proper comment [ci skip] --- .../alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt index a9c7f396..52630454 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt @@ -5,16 +5,11 @@ import io.delilaheve.util.ConfigOptions object AnvilUseTypeUtil { /* - By stupidity of kotlin not allowing static function outside of companion object I need to do another util class only for 1 function: + By kotlin not having static function outside of companion object I need to do another util class only for 1 function: Companion object on enum class seems to get initialized AFTER the enum itself - that mean. if you want to call a static function on the enum class itself YOU CAN'T. you need to do this stupid thing - or you can make a stupid top level function OR object that even worse because of global scope pollution - (btw was gpt ""solution"". fortunately I do not "vibe code" so I do what I know instead of stupid AI solution & code) - I mean, this is still global scope pollution bc of a USELESS class that SHOULD not exist but as a class is better than a random *ss function - - sorry for the rent but this made me frustrated - - Note: I still like a lot of part of kotlin compared to java but this part is one that I hate + that mean. if you want to call a static function on enum construction YOU CAN'T. you need to do this stupid thing, + or you can make a stupid top level function or object that at least as bad as this + I mean, this is still an unnecessary class that should not exist but as a class is better than a random function in my opinion */ /** * Get config path for normal anvil use From e61baba175ac620ddb475e677b42e027781fe636 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 04:10:36 +0200 Subject: [PATCH 4/6] remove use of useInFuture --- defaultconfigs/1.18/enchant_conflict.yml | 7 ---- defaultconfigs/1.21.11/enchant_conflict.yml | 3 -- defaultconfigs/1.21.9/enchant_conflict.yml | 3 -- .../cuanvil/update/UpdateHandler.java | 3 +- .../cuanvil/update/minecraft/Update_1_19.java | 40 +++++++++++++++++++ ...{PUpdate_1_17_7.java => PUpdate_1_18.java} | 9 +++-- .../cuanvil/group/EnchantConflictManager.kt | 15 +------ src/main/resources/enchant_conflict.yml | 7 ---- 8 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_19.java rename src/main/java/xyz/alexcrea/cuanvil/update/plugin/{PUpdate_1_17_7.java => PUpdate_1_18.java} (74%) diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 31506d2b..8e691bb8 100644 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ b/defaultconfigs/1.18/enchant_conflict.yml @@ -160,13 +160,6 @@ restriction_sweeping_edge: enchantments: [ minecraft:sweeping, 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 ] - restriction_thorns: enchantments: [ minecraft:thorns ] notAffectedGroups: [ enchanted_book, armors ] diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index 18341d36..20f735c5 100644 --- a/defaultconfigs/1.21.11/enchant_conflict.yml +++ b/defaultconfigs/1.21.11/enchant_conflict.yml @@ -275,10 +275,7 @@ restriction_sweeping_edge: - 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: diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index 8ab9e3bc..ae9c955a 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -272,10 +272,7 @@ restriction_sweeping_edge: - 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: diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java index c548f228..92418a3a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java @@ -30,10 +30,11 @@ public class UpdateHandler { 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, 17, 7), PUpdate_1_17_7::handleUpdate + new Version(1, 18, 0), PUpdate_1_18::handleUpdate ); private static final List mcUpdateMap = List.of( + new Update_1_19(), new Update_1_20_5(), new Update_1_21(), new Update_1_21_9(), diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_19.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_19.java new file mode 100644 index 00000000..fc598658 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_19.java @@ -0,0 +1,40 @@ +package xyz.alexcrea.cuanvil.update.minecraft; + +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.addAbsentToList; + +public class Update_1_19 extends MCUpdate { + + public Update_1_19() { + super(new Version(1, 19)); + } + + @Override + protected void doUpdate() { + var tosave = new HashSet(); + updateName(tosave); + + for (ConfigHolder holder : tosave) { + holder.saveToDisk(true); + } + } + + public static void updateName(@NotNull Set tosave) { + var conflict = ConfigHolder.CONFLICT_HOLDER.getConfig(); + + addAbsentToList(conflict, "restriction_swift_sneak.enchantments", "minecraft:swift_sneak"); + addAbsentToList(conflict, "restriction_swift_sneak.notAffectedGroups", "leggings", "enchanted_book"); + + ConfigHolder.ITEM_GROUP_HOLDER.reload(); + + tosave.add(ConfigHolder.DEFAULT_CONFIG); + tosave.add(ConfigHolder.CONFLICT_HOLDER); + } + +} 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_18.java similarity index 74% rename from src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java rename to src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_18.java index 972825dd..b52ec7ac 100644 --- 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_18.java @@ -3,19 +3,20 @@ 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_19; 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 class PUpdate_1_18 { 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; + if (new Version(1, 19, 0).greaterThan(current)) return; + Update_1_19.updateName(toSave); + if (new Version(1, 20, 5).greaterThan(current)) return; Update_1_20_5.updateName(toSave); } - } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 39def31f..ee9c718b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -3,7 +3,6 @@ package xyz.alexcrea.cuanvil.group import io.delilaheve.CustomAnvil import org.bukkit.NamespacedKey import org.bukkit.configuration.ConfigurationSection -import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment @@ -33,10 +32,6 @@ class EnchantConflictManager { // Path for the maximum number of enchantment before validating the conflict const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict" - // Path for a flag: if the enchantment will be used in the last supported version - // TODO maybe replace this system by a list of "future" enchantment. - private const val FUTURE_USE_PATH = "useInFuture" - // Default name for a joining group const val DEFAULT_GROUP_NAME = "joinedGroup" } @@ -101,8 +96,6 @@ class EnchantConflictManager { itemManager: ItemGroupManager, conflictName: String ): EnchantConflictGroup { - // Is it planed for the future - val futureUse = section.getBoolean(FUTURE_USE_PATH, false) // Create conflict val conflict = createConflictObject(section, itemManager, conflictName) // Read and add enchantment to conflict @@ -110,17 +103,13 @@ class EnchantConflictManager { for (enchantName in enchantList) { val enchants = getEnchantByIdentifier(enchantName) if (enchants.isEmpty()) { - if (!futureUse) { //TODO future use will be deprecated once the new update system is finished - CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") - } + CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") continue } conflict.addEnchantments(enchants) } if (conflict.getEnchants().isEmpty()) { - if (!futureUse) { //TODO future use will be deprecated once the new update system is finished - CustomAnvil.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not do anything") - } + CustomAnvil.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not do anything") } val conflictsAfterLevel = section.getConfigurationSection(CONFLICT_AFTER_LEVEL_LIST_PATH) diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 31506d2b..8e691bb8 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -160,13 +160,6 @@ restriction_sweeping_edge: enchantments: [ minecraft:sweeping, 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 ] - restriction_thorns: enchantments: [ minecraft:thorns ] notAffectedGroups: [ enchanted_book, armors ] From 403c9900837a2c12786e7fcf562c3ea49647e710 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 04:11:41 +0200 Subject: [PATCH 5/6] migrate configanvil to ca config --- defaultconfigs/1.18/config.yml | 2 +- defaultconfigs/1.18/enchant_conflict.yml | 2 +- defaultconfigs/1.18/item_groups.yml | 2 +- defaultconfigs/1.18/unit_repair_item.yml | 2 +- defaultconfigs/1.21.11/config.yml | 2 +- defaultconfigs/1.21.11/enchant_conflict.yml | 2 +- defaultconfigs/1.21.11/item_groups.yml | 2 +- defaultconfigs/1.21.11/unit_repair_item.yml | 2 +- defaultconfigs/1.21.9/config.yml | 2 +- defaultconfigs/1.21.9/enchant_conflict.yml | 2 +- defaultconfigs/1.21.9/item_groups.yml | 2 +- defaultconfigs/1.21.9/unit_repair_item.yml | 2 +- defaultconfigs/1.21/config.yml | 2 +- defaultconfigs/1.21/enchant_conflict.yml | 2 +- defaultconfigs/1.21/item_groups.yml | 2 +- defaultconfigs/1.21/unit_repair_item.yml | 2 +- src/main/resources/config.yml | 2 +- src/main/resources/enchant_conflict.yml | 2 +- src/main/resources/item_groups.yml | 2 +- src/main/resources/unit_repair_item.yml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 377b3499..7574edd8 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 8e691bb8..047b1b26 100644 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ b/defaultconfigs/1.18/enchant_conflict.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml index 6963d2e4..7956fb61 100644 --- a/defaultconfigs/1.18/item_groups.yml +++ b/defaultconfigs/1.18/item_groups.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml index 98fd0bec..a8bbcbe3 100644 --- a/defaultconfigs/1.18/unit_repair_item.yml +++ b/defaultconfigs/1.18/unit_repair_item.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index 8b5747b1..c3ea6204 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index 20f735c5..bbbeac71 100644 --- a/defaultconfigs/1.21.11/enchant_conflict.yml +++ b/defaultconfigs/1.21.11/enchant_conflict.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/item_groups.yml b/defaultconfigs/1.21.11/item_groups.yml index 5d24cacf..e2ebdb3e 100644 --- a/defaultconfigs/1.21.11/item_groups.yml +++ b/defaultconfigs/1.21.11/item_groups.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/unit_repair_item.yml b/defaultconfigs/1.21.11/unit_repair_item.yml index d742a056..24f8460b 100644 --- a/defaultconfigs/1.21.11/unit_repair_item.yml +++ b/defaultconfigs/1.21.11/unit_repair_item.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index c7700969..614c8df0 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index ae9c955a..c161982e 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/item_groups.yml b/defaultconfigs/1.21.9/item_groups.yml index f7a00bcc..a1af375e 100644 --- a/defaultconfigs/1.21.9/item_groups.yml +++ b/defaultconfigs/1.21.9/item_groups.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/unit_repair_item.yml b/defaultconfigs/1.21.9/unit_repair_item.yml index 122b9657..1f256100 100644 --- a/defaultconfigs/1.21.9/unit_repair_item.yml +++ b/defaultconfigs/1.21.9/unit_repair_item.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index 1ef0d102..a0bcbd86 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index d3b5d33c..1806abd4 100644 --- a/defaultconfigs/1.21/enchant_conflict.yml +++ b/defaultconfigs/1.21/enchant_conflict.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/item_groups.yml b/defaultconfigs/1.21/item_groups.yml index 6963d2e4..7956fb61 100644 --- a/defaultconfigs/1.21/item_groups.yml +++ b/defaultconfigs/1.21/item_groups.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/unit_repair_item.yml b/defaultconfigs/1.21/unit_repair_item.yml index b7873a12..3fafd476 100644 --- a/defaultconfigs/1.21/unit_repair_item.yml +++ b/defaultconfigs/1.21/unit_repair_item.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0a0c5664..6d946d4d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit most of these config. +# It is recommended that you use /ca config to edit most of these config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 8e691bb8..047b1b26 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index f2042f03..dff1b41c 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # diff --git a/src/main/resources/unit_repair_item.yml b/src/main/resources/unit_repair_item.yml index 98fd0bec..a8bbcbe3 100644 --- a/src/main/resources/unit_repair_item.yml +++ b/src/main/resources/unit_repair_item.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /configanvil to edit theses config. +# It is recommended that you use /ca config to edit theses config. # You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # From 16e4f0a9239585d23e21479513c57d62495c8e32 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 04:22:59 +0200 Subject: [PATCH 6/6] fix using durability for max damage --- .../cuanvil/util/MaxDamageCheckerUtil.kt | 5 ++- .../kotlin/io/delilaheve/util/ItemUtil.kt | 37 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt index b3ce0ff6..a05d9425 100644 --- a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt +++ b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt @@ -1,5 +1,6 @@ package xyz.alexcrea.cuanvil.util +import org.bukkit.Material import org.bukkit.inventory.meta.Damageable // I LOVE support of old versions and needing to do modules like that @@ -10,8 +11,8 @@ object MaxDamageCheckerUtil { /** * @return max damage or int max if not set */ - fun getMaxDamage(meta: Damageable): Int { - if(!meta.hasMaxDamage()) return Integer.MAX_VALUE + fun getMaxDamage(type: Material, meta: Damageable): Int { + if(!meta.hasMaxDamage()) return type.maxDurability.toInt() return meta.maxDamage } diff --git a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index bf075231..02c8475e 100644 --- a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt @@ -1,9 +1,9 @@ package io.delilaheve.util +import org.bukkit.Material import org.bukkit.Material.ENCHANTED_BOOK import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable -import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.util.MaterialUtil.customType import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil @@ -21,11 +21,11 @@ object ItemUtil { */ fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK - private fun maxDamage(damageable: Damageable): Int { + private fun maxDamage(type: Material, damageable: Damageable): Int { val ver = UpdateUtils.currentMinecraftVersion() - if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE + if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return type.maxDurability.toInt() - return MaxDamageCheckerUtil.getMaxDamage(damageable) + return MaxDamageCheckerUtil.getMaxDamage(type, damageable) } /** @@ -37,23 +37,22 @@ object ItemUtil { first: ItemStack, second: ItemStack ): Boolean { - (itemMeta as? Damageable)?.let { - val durability = type.maxDurability.toInt() - val firstDamage = (first.itemMeta as? Damageable)?.damage ?: 0 - if (firstDamage == 0) return false + val meta = itemMeta + if(meta !is Damageable) return false - val firstDurability = durability - firstDamage - val secondDamage = (second.itemMeta as? Damageable)?.damage ?: 0 - val secondDurability = durability - secondDamage - val combinedDurability = firstDurability + secondDurability - val newDurability = min(combinedDurability, durability) + val maxDamage = maxDamage(type, meta) + val damage = (first.itemMeta as? Damageable)?.damage ?: 0 + if (damage == 0) return false - val maxDamage = maxDamage(it) - it.damage = min(durability - newDurability, maxDamage) - itemMeta = it - return true - } - return false + val firstDurability = maxDamage - damage + val secondDamage = (second.itemMeta as? Damageable)?.damage ?: 0 + val secondDurability = maxDamage - secondDamage + val combinedDurability = firstDurability + secondDurability + val newDurability = min(combinedDurability, maxDamage) + + meta.damage = min(maxDamage - newDurability, maxDamage) + this.itemMeta = meta + return true } fun ItemStack.unitRepair(