diff --git a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index 25698ad..8992467 100644 --- a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt @@ -4,9 +4,7 @@ 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 import kotlin.math.ceil import kotlin.math.max import kotlin.math.min @@ -38,13 +36,6 @@ object ItemUtil { } - private fun maxDamage(damageable: Damageable): Int { - val ver = UpdateUtils.currentMinecraftVersion() - if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE - - return MaxDamageCheckerUtil.getMaxDamage(damageable) - } - /** * Set this [ItemStack]s durability from a combination of the * [first] and [second] item's durability values @@ -64,8 +55,8 @@ object ItemUtil { val secondDurability = durability - secondDamage val combinedDurability = firstDurability + secondDurability val newDurability = min(combinedDurability, durability) + val maxDamage = if(it.hasMaxDamage()) it.maxDamage else Int.MAX_VALUE - val maxDamage = maxDamage(it) it.damage = min(durability - newDurability, maxDamage) itemMeta = it return true diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 6a6950c..a76c4a7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.dependency -import com.maddoxh.superEnchants.SuperEnchants import io.delilaheve.CustomAnvil import net.kyori.adventure.text.Component import org.bukkit.Bukkit @@ -118,7 +117,7 @@ object DependencyManager { genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!)) if (pluginManager.isPluginEnabled("SuperEnchants")){ - val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!! as SuperEnchants) + val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!) if(compatibility.registerEnchantments()) genericDependencies.add(compatibility) } @@ -165,11 +164,11 @@ object DependencyManager { ) } - private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) { + private fun logExceptionAndClear(view: AnvilView, e: Exception) { // Just in case to avoid illegal items view.setItem(ANVIL_OUTPUT_SLOT, null) - logException(target, e) + logException(view.player, e) } // Return true if should bypass (either by a dependency or error) @@ -178,7 +177,7 @@ object DependencyManager { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -204,7 +203,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -262,7 +261,7 @@ object DependencyManager { try { return unsafeTryClickAnvilResultBypass(event, view) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(view, e) return true } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 11622f9..8676b4c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -8,17 +8,23 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.plugin.Plugin import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level -class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginDependency(plugin, false) { +class SuperEnchantDependency: GenericPluginDependency { + override val plugin: SuperEnchants lateinit var enchManager: EnchantManager val enchantments = ArrayList() + constructor(plugin: Plugin) : super(plugin) { + this.plugin = plugin as SuperEnchants + } + fun registerEnchantments(): Boolean{ CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...")