try to make it work

This commit is contained in:
alexcrea 2025-12-30 01:20:07 +01:00
parent ff4be622f8
commit 4aa5ec9187
Signed by: alexcrea
GPG key ID: E346CD16413450E3
2 changed files with 0 additions and 76 deletions

View file

@ -1,61 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.gui
import org.bukkit.inventory.InventoryView
import java.lang.reflect.Method
class GenericExternGuiTester: ExternGuiTester {
companion object {
private const val ANVIL_CLASS_NAME = "org.bukkit.craftbukkit.inventory.view.CraftAnvilView"
private const val INV_CLASS_NAME = "org.bukkit.craftbukkit.inventory.CraftInventoryView"
private const val HANDLE_METHOD_NAME = "getHandle"
}
var testExist = false
var inTesting = false
var testedClass: String? = null
lateinit var getHandleMethod: Method
override fun getContainerClass(view: InventoryView): Class<Any>? {
// In case we are in a test environment
if(!testExist) testClassExist()
if(inTesting) return view.javaClass //TEMPORARY
if(!testedClass.contentEquals(view.javaClass.name))
return null
val container = getHandleMethod.invoke(view)
return container.javaClass
}
fun tryFromClass(className: String) {
val clazz = Class.forName(className)
testedClass = className
getHandleMethod = clazz.getMethod(HANDLE_METHOD_NAME)
}
fun testClassExist() {
testExist = true
// We first try to get craft anvil interface,
// but is absent on old version so we try craft inventory view before
try {
tryFromClass(ANVIL_CLASS_NAME)
return
}
catch (_: ClassNotFoundException) {}
catch (_: NoSuchMethodException) {}
try {
tryFromClass(INV_CLASS_NAME)
return
}
catch (_: ClassNotFoundException) {}
catch (_: NoSuchMethodException) {}
inTesting = true
}
}

View file

@ -1,15 +0,0 @@
package xyz.alexcrea.cuanvil.dependency.gui
import xyz.alexcrea.cuanvil.update.UpdateUtils
object GuiTesterSelector {
val selectGuiTester: ExternGuiTester?
get() {
val versionParts = UpdateUtils.currentMinecraftVersionArray()
if (versionParts[0] != 1) return null
return GenericExternGuiTester()
}
}