diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 442af0a..f629c2f 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -52,8 +52,8 @@ open class CustomAnvil : JavaPlugin() { // Command Name to reload the config const val commandReloadName = "anvilconfigreload" - // Test command name - const val commandTestName = "customanvilconfig" + // Config command name + const val commandConfigName = "customanvilconfig" // Current plugin instance lateinit var instance: CustomAnvil @@ -208,7 +208,7 @@ open class CustomAnvil : JavaPlugin() { var command = getCommand(commandReloadName) command?.setExecutor(ReloadExecutor()) - command = getCommand(commandTestName) + command = getCommand(commandConfigName) command?.setExecutor(EditConfigExecutor()) } diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index 87e4bae..dcf59df 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil import org.bukkit.entity.HumanEntity import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.config.ConfigHolder +import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.group.ConflictType import kotlin.math.max @@ -33,6 +34,10 @@ object EnchantmentUtil { val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission) val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission) + // TODO add custom anvil maximum enchant count per item and globally too + var maxEnchantCount = DependencyManager.ecoEnchantCompatibility?.getEcoLevelLimit() + if(maxEnchantCount == null || maxEnchantCount < 0) maxEnchantCount = Int.MAX_VALUE; + other.forEach { (enchantment, level) -> if(!enchantment.isAllowed(player)) return@forEach @@ -45,6 +50,9 @@ object EnchantmentUtil { // Enchantment not yet in result list if (!containsKey(enchantment)) { + // Do not allow new enchantment if above maximum + if(this.size <= maxEnchantCount) return@forEach + // Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions this[enchantment] = cappedLevel if(bypassFuse){ diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt index 22fce5e..079d570 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoEnchantDependency.kt @@ -1,7 +1,9 @@ package xyz.alexcrea.cuanvil.dependency.plugins +import com.willfp.eco.core.EcoPlugin import com.willfp.ecoenchants.enchant.EcoEnchant import com.willfp.ecoenchants.enchant.EcoEnchants +import com.willfp.ecoenchants.mechanics.infiniteIfNegative import io.delilaheve.CustomAnvil import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.plugin.Plugin @@ -32,6 +34,10 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) { } + public fun getEcoLevelLimit(): Int { + return (ecoEnchantPlugin as EcoPlugin).configYml.getInt("anvil.enchant-limit").infiniteIfNegative() + } + fun disableAnvilListener() { PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin) }