diff --git a/README.md b/README.md index 27d08fac..9d9e678e 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ 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: Get debug information about the plugin and server -ca.command.enchantment: Allows to set enchantment to holden item +ca.command.diagnostic: Allow adminastator to diagnistic some simple problem with the plugin ca.config.edit: Allow administrator to edit the plugin's config in game # ----------------------------------------------------------------------------- diff --git a/build.gradle.kts b/build.gradle.kts index 3c34895e..76ab4c00 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.18.0" +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 7574edd8..377b3499 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 047b1b26..31506d2b 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # @@ -160,6 +160,13 @@ 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.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml index 7956fb61..6963d2e4 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml index a8bbcbe3..98fd0bec 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index c3ea6204..8b5747b1 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index bbbeac71..18341d36 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # @@ -275,7 +275,10 @@ 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.11/item_groups.yml b/defaultconfigs/1.21.11/item_groups.yml index e2ebdb3e..5d24cacf 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 /ca config to edit theses config. +# 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 /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 24f8460b..d742a056 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 614c8df0..c7700969 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index c161982e..8ab9e3bc 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # @@ -272,7 +272,10 @@ 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/item_groups.yml b/defaultconfigs/1.21.9/item_groups.yml index a1af375e..f7a00bcc 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 /ca config to edit theses config. +# 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 /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 1f256100..122b9657 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index a0bcbd86..1ef0d102 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index 1806abd4..d3b5d33c 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/item_groups.yml b/defaultconfigs/1.21/item_groups.yml index 7956fb61..6963d2e4 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/defaultconfigs/1.21/unit_repair_item.yml b/defaultconfigs/1.21/unit_repair_item.yml index 3fafd476..b7873a12 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # 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 a05d9425..b3ce0ff6 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,6 +1,5 @@ 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 @@ -11,8 +10,8 @@ object MaxDamageCheckerUtil { /** * @return max damage or int max if not set */ - fun getMaxDamage(type: Material, meta: Damageable): Int { - if(!meta.hasMaxDamage()) return type.maxDurability.toInt() + fun getMaxDamage(meta: Damageable): Int { + if(!meta.hasMaxDamage()) return Integer.MAX_VALUE return meta.maxDamage } diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java index 92418a3a..c548f228 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java @@ -30,11 +30,10 @@ 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, 18, 0), PUpdate_1_18::handleUpdate + new Version(1, 17, 7), PUpdate_1_17_7::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 deleted file mode 100644 index fc598658..00000000 --- a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_19.java +++ /dev/null @@ -1,40 +0,0 @@ -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_18.java b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java similarity index 74% rename from src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_18.java rename to src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java index b52ec7ac..972825dd 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_18.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java @@ -3,20 +3,19 @@ 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_18 { +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, 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/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 906e023f..a5cac722 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -57,8 +57,6 @@ 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/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index 02c8475e..bf075231 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(type: Material, damageable: Damageable): Int { + private fun maxDamage(damageable: Damageable): Int { val ver = UpdateUtils.currentMinecraftVersion() - if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return type.maxDurability.toInt() + if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE - return MaxDamageCheckerUtil.getMaxDamage(type, damageable) + return MaxDamageCheckerUtil.getMaxDamage(damageable) } /** @@ -37,22 +37,23 @@ object ItemUtil { first: ItemStack, second: ItemStack ): Boolean { - val meta = itemMeta - if(meta !is Damageable) return false + (itemMeta as? Damageable)?.let { + val durability = type.maxDurability.toInt() + val firstDamage = (first.itemMeta as? Damageable)?.damage ?: 0 + if (firstDamage == 0) return false - val maxDamage = maxDamage(type, meta) - val damage = (first.itemMeta as? Damageable)?.damage ?: 0 - if (damage == 0) 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 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 + val maxDamage = maxDamage(it) + it.damage = min(durability - newDurability, maxDamage) + itemMeta = it + return true + } + return false } fun ItemStack.unitRepair( diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 60dcdbee..4c71c68b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -4,7 +4,6 @@ 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 { @@ -44,14 +43,4 @@ 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 9b9402c9..9287a7c7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -7,6 +7,7 @@ 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 { @@ -17,14 +18,13 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { private val editConfigCommand = EditConfigExecutor() private val helpCommand = HelpExecutor() - private val commands: ImmutableMap = ImmutableMap.of( + private val commands = ImmutableMap.of( "gui", editConfigCommand, "config", editConfigCommand, "reload", ReloadExecutor(), "diagnostic", DiagnosticExecutor(), "debug", DebugToggleExecutor(), "help", helpCommand, - "enchant", EnchantExecutor(), ) init { @@ -95,11 +95,9 @@ 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(prefix) } + .filter { it.startsWith(args[args.size - 1]) } .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 c6bc191b..b11bfb4a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -7,6 +7,7 @@ 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 @@ -102,6 +103,16 @@ 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) { @@ -116,6 +127,7 @@ 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 deleted file mode 100644 index dd2957fa..00000000 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt +++ /dev/null @@ -1,113 +0,0 @@ -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 cb0d24a9..ef23e7d6 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -3,6 +3,7 @@ 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/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index ee9c718b..39def31f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -3,6 +3,7 @@ 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 @@ -32,6 +33,10 @@ 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" } @@ -96,6 +101,8 @@ 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 @@ -103,13 +110,17 @@ class EnchantConflictManager { for (enchantName in enchantList) { val enchants = getEnchantByIdentifier(enchantName) if (enchants.isEmpty()) { - CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") + 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") + } continue } conflict.addEnchantments(enchants) } if (conflict.getEnchants().isEmpty()) { - CustomAnvil.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not do anything") + 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") + } } val conflictsAfterLevel = section.getConfigurationSection(CONFLICT_AFTER_LEVEL_LIST_PATH) 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 52630454..a9c7f396 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt @@ -5,11 +5,16 @@ import io.delilaheve.util.ConfigOptions object AnvilUseTypeUtil { /* - By kotlin not having static function outside of companion object I need to do another util class only for 1 function: + By stupidity of kotlin not allowing 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 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 + 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 */ /** * Get config path for normal anvil use diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6d946d4d..0a0c5664 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # -# It is recommended that you use /ca config to edit most of these config. +# 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 /ca reload after you changes ! # diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 047b1b26..31506d2b 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # @@ -160,6 +160,13 @@ 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/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index dff1b41c..f2042f03 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d436b10a..dab9997b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -43,9 +43,6 @@ 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 diff --git a/src/main/resources/unit_repair_item.yml b/src/main/resources/unit_repair_item.yml index a8bbcbe3..98fd0bec 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 /ca config to edit theses config. +# 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 /ca reload after you changes ! #