update from v1.18.0

This commit is contained in:
alexcrea 2026-07-10 15:50:50 +02:00
parent 13892f73b8
commit 036f480113
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C
7 changed files with 16 additions and 14 deletions

View file

@ -5,7 +5,6 @@ import org.bukkit.Material.ENCHANTED_BOOK
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.Damageable
import xyz.alexcrea.cuanvil.update.UpdateUtils
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
import kotlin.math.ceil
import kotlin.math.max
@ -49,7 +48,6 @@ object ItemUtil {
val secondDurability = maxDamage - secondDamage
val combinedDurability = firstDurability + secondDurability
val newDurability = min(combinedDurability, maxDamage)
val maxDamage = if(it.hasMaxDamage()) it.maxDamage else Int.MAX_VALUE
meta.damage = min(maxDamage - newDurability, maxDamage)
this.itemMeta = meta

View file

@ -116,7 +116,7 @@ class EnchantExecutor : CASubCommand {
}
private fun firstEnchantment(name: String): CAEnchantment? {
val enchants = EnchantmentApi.getListByName(name.lowercase())
val enchants = EnchantmentApi.getByName(name.lowercase())
if (!enchants.isEmpty())
return enchants.iterator().next()

View file

@ -334,7 +334,7 @@ object DependencyManager {
private val prepareAnvilConstructor =
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
fun createFakeEvent(view: InventoryView, result: ItemStack?): PrepareAnvilEvent {
fun createFakeEvent(view: AnvilView, result: ItemStack?): PrepareAnvilEvent {
return prepareAnvilConstructor.newInstance(view, result)
}

View file

@ -1,10 +1,11 @@
package xyz.alexcrea.cuanvil.dependency.gui
import org.bukkit.inventory.InventoryView
import org.bukkit.inventory.view.AnvilView
import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
import java.lang.reflect.Method
@Suppress("UnstableApiUsage")
class GenericExternGuiTester {
companion object {
@ -21,7 +22,7 @@ class GenericExternGuiTester {
var testedClass: String? = null
lateinit var getHandleMethod: Method
private fun getContainerClass(view: InventoryView): Class<Any>? {
private fun getContainerClass(view: AnvilView): Class<Any>? {
if(!testedClass.contentEquals(view.javaClass.name))
return null
@ -64,7 +65,7 @@ class GenericExternGuiTester {
}
// Try if were in another plugin anvil inventory
fun testIfGui(view: InventoryView): Boolean {
fun testIfGui(view: AnvilView): Boolean {
// In case we are in a test environment
if(isInTest()) return false

View file

@ -2,15 +2,17 @@ package xyz.alexcrea.cuanvil.dependency.plugins
import org.bukkit.event.Event
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.inventory.view.AnvilView
import org.bukkit.plugin.Plugin
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_LEFT
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
@Suppress("UnstableApiUsage")
class EnchantedBookDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
override fun testAnvilResult(event: InventoryClickEvent): Boolean {
val view = event.view
val view = event.view as? AnvilView ?: return false
val inv = event.inventory
//TODO use view here (v2)