use eco enchant enchant limit

This commit is contained in:
alexcrea 2025-07-16 18:08:49 +02:00
parent dea86ab9ce
commit 00adf05d2b
Signed by: alexcrea
GPG key ID: E346CD16413450E3
3 changed files with 17 additions and 3 deletions

View file

@ -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())
}

View file

@ -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){

View file

@ -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)
}