mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
remove more nms sub modules
This commit is contained in:
parent
c12e70ca54
commit
a8553debeb
22 changed files with 34 additions and 355 deletions
|
|
@ -17,23 +17,20 @@ import org.bukkit.inventory.view.AnvilView
|
|||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.GuiTesterSelector
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerSelector
|
||||
import xyz.alexcrea.cuanvil.dependency.plugins.*
|
||||
import xyz.alexcrea.cuanvil.dependency.scheduler.TaskScheduler
|
||||
import xyz.alexcrea.cuanvil.dependency.scheduler.FoliaScheduler
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import java.util.logging.Level
|
||||
|
||||
|
||||
@Suppress("unstableApiUsage")
|
||||
object DependencyManager {
|
||||
|
||||
var isFolia: Boolean = false
|
||||
lateinit var scheduler: TaskScheduler
|
||||
lateinit var scheduler: FoliaScheduler
|
||||
lateinit var packetManager: PacketManagerBase
|
||||
private var externGuiTester: ExternGuiTester? = null
|
||||
|
||||
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
|
||||
private var ecoEnchantCompatibility: EcoEnchantDependency? = null
|
||||
|
|
@ -54,11 +51,11 @@ object DependencyManager {
|
|||
if (isFolia) {
|
||||
CustomAnvil.instance.logger.info("Folia detected... Custom Anvil Folia support is experimental. issues are more likely to happens.")
|
||||
}
|
||||
scheduler = FoliaScheduler()
|
||||
|
||||
// Packet Manager
|
||||
val forceProtocolib = ConfigHolder.DEFAULT_CONFIG.config.getBoolean("force_protocolib", false)
|
||||
packetManager = PacketManagerSelector.selectPacketManager(forceProtocolib)
|
||||
externGuiTester = GuiTesterSelector.selectGuiTester
|
||||
|
||||
// Enchantment Squared dependency
|
||||
if (pluginManager.isPluginEnabled("EnchantsSquared")) {
|
||||
|
|
@ -158,7 +155,7 @@ object DependencyManager {
|
|||
var bypass = bypassEvent.isCancelled
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if (!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
if (!bypass && ExternGuiTester.testIfGui(event.view)) bypass = true
|
||||
|
||||
// Test if in an ax player warp rating gui
|
||||
if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(player) == true)) bypass = true
|
||||
|
|
@ -289,7 +286,7 @@ object DependencyManager {
|
|||
}
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if (!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
if (!bypass && ExternGuiTester.testIfGui(event.view)) bypass = true
|
||||
|
||||
// Test if in an ax player warp rating gui
|
||||
if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(event.player) == true)) bypass = true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.gui
|
||||
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView
|
||||
import org.bukkit.inventory.InventoryView
|
||||
|
||||
object ExternGuiTester {
|
||||
|
||||
fun getContainerClass(view: InventoryView): Class<Any>? {
|
||||
if (view !is CraftInventoryView<*, *>) return null
|
||||
val container = view.handle
|
||||
|
||||
return container.javaClass
|
||||
}
|
||||
|
||||
fun testIfGui(view: InventoryView): Boolean {
|
||||
// this mean we are on test
|
||||
//TODO review why needed knowing previous mitigations should works
|
||||
if(view.javaClass.name.endsWith("AnvilViewMock")) return false
|
||||
|
||||
val clazz = getContainerClass(view) ?: return false
|
||||
|
||||
val clazzName = clazz.name
|
||||
//TODO maybe instead of testing non default, better to be testing we are default ?
|
||||
if (expectWesjd(clazzName)) return true
|
||||
if (expectXenondevUI(clazzName)) return true
|
||||
if (expectVanePortal(clazzName)) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun expectWesjd(name: String): Boolean {
|
||||
val spigotVer = GuiTesterSelector.spigotVersionString
|
||||
if(spigotVer == null) return false
|
||||
|
||||
val expectedWesjdGuiPath = "anvilgui.version.Wrapper${spigotVer}"
|
||||
|
||||
return name.contains(expectedWesjdGuiPath)
|
||||
}
|
||||
|
||||
private val XenondevUIPrefix: String
|
||||
get() = "xyz.xenondevs.inventoryaccess."
|
||||
private val XenondevUISufix: String
|
||||
get() = ".AnvilInventoryImpl"
|
||||
|
||||
fun expectXenondevUI(name: String): Boolean {
|
||||
return name.startsWith(XenondevUIPrefix)
|
||||
&& name.endsWith(XenondevUISufix)
|
||||
}
|
||||
|
||||
fun expectVanePortal(name: String): Boolean {
|
||||
val expected = "org.oddlama.vane.core.menu.AnvilMenu\$AnvilContainer"
|
||||
|
||||
return name == expected
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +1,21 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.gui
|
||||
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.version.*
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
|
||||
object GuiTesterSelector {
|
||||
|
||||
val selectGuiTester: ExternGuiTester?
|
||||
val spigotVersionString: String?
|
||||
get() {
|
||||
val versionParts = UpdateUtils.currentMinecraftVersionArray()
|
||||
if (versionParts[0] != 1) return null
|
||||
|
||||
return when (versionParts[1]) {
|
||||
// Can't support 1.16.5 bc 1.16.5 paper userdev do not exist
|
||||
|
||||
21 -> when (versionParts[2]) {
|
||||
0, 1 -> v1_21R1_ExternGuiTester()
|
||||
2, 3 -> v1_21R2_ExternGuiTester()
|
||||
4 -> v1_21R3_ExternGuiTester()
|
||||
5 -> v1_21R4_ExternGuiTester()
|
||||
6, 7, 8 -> v1_21R5_ExternGuiTester()
|
||||
0, 1 -> "1_21_R1"
|
||||
2, 3 -> "1_21_R2"
|
||||
4 -> "1_21_R3"
|
||||
5 -> "1_21_R4"
|
||||
6, 7, 8 -> "1_21_R5"
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import org.bukkit.Bukkit
|
|||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class FoliaScheduler : TaskScheduler {
|
||||
//TODO replace usage of this to in code correct version
|
||||
class FoliaScheduler {
|
||||
|
||||
override fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable, time: Long): Any {
|
||||
if (time < 1) {
|
||||
return Bukkit.getGlobalRegionScheduler().run(
|
||||
plugin
|
||||
|
|
@ -20,8 +21,11 @@ class FoliaScheduler : TaskScheduler {
|
|||
)
|
||||
}
|
||||
|
||||
fun scheduleGlobally(plugin: Plugin, task: Runnable): Any?{
|
||||
return scheduleGlobally(plugin, task, 0L)
|
||||
}
|
||||
|
||||
override fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any? {
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable, time: Long): Any? {
|
||||
if (time < 1) {
|
||||
return entity.scheduler.run(
|
||||
plugin,
|
||||
|
|
@ -36,4 +40,8 @@ class FoliaScheduler : TaskScheduler {
|
|||
time
|
||||
)
|
||||
}
|
||||
|
||||
fun scheduleOnEntity(plugin: Plugin, entity: Entity, task: Runnable): Any?{
|
||||
return scheduleOnEntity(plugin, entity, task, 0L)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue