progress on merge

This commit is contained in:
alexcrea 2025-12-29 21:25:21 +01:00
parent 529e781a72
commit 9b723650e0
Signed by: alexcrea
GPG key ID: E346CD16413450E3
11 changed files with 15 additions and 159 deletions

View file

@ -107,15 +107,6 @@ object DependencyManager {
}
private fun testIsMockbukkit(): Boolean {
try {
Class.forName("org.mockbukkit.mockbukkit.exception.UnimplementedOperationException")
return true
} catch (e: ClassNotFoundException) {
return false
}
}
fun handleCompatibilityConfig() {
enchantmentSquaredCompatibility?.registerPluginConfiguration()

View file

@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.api.MaterialGroupApi
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment
import xyz.alexcrea.cuanvil.enchant.wrapped.CAIncompatibleAllEnchant
import xyz.alexcrea.cuanvil.group.IncludeGroup
@ -39,7 +40,7 @@ object DataPackDependency {
}
fun handleDatapackConfigs() {
if (DependencyManager.isMockbukkit) return
if (PlatformUtil.isMockbukkit) return
val enabledDatapack = enabledDatapacks
for (packName in enabledDatapack) {

View file

@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.dependency.gui
import org.bukkit.craftbukkit.inventory.CraftInventoryView
import org.bukkit.inventory.InventoryView
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
object ExternGuiTester {
@ -14,7 +15,7 @@ object ExternGuiTester {
}
fun testIfGui(view: InventoryView): Boolean {
if (DependencyManager.isMockbukkit) return false
if (PlatformUtil.isMockbukkit) return false
val clazz = getContainerClass(view) ?: return false
val clazzName = clazz.name

View file

@ -3,6 +3,9 @@ package xyz.alexcrea.cuanvil.dependency.packet
import org.bukkit.Bukkit
object PacketManagerSelector {
//TODO
fun selectPacketManager(forceProtocolib: Boolean): PacketManagerBase {
// Try to find version
return if (forceProtocolib)

View file

@ -0,0 +1,65 @@
package xyz.alexcrea.cuanvil.dependency.util
import net.kyori.adventure.text.Component
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
// Mostly made for paper, spigot and folia support
@Suppress("DEPRECATION")
object PlatformUtil {
private fun hasClass(className: String): Boolean {
try {
Class.forName(className)
return true
} catch (_: ClassNotFoundException) {
return false
}
}
private fun hasMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>): Boolean {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
return true
} catch (_: NoSuchMethodException) {
return false
}
}
val isFolia = hasClass("io.papermc.paper.threadedregions.RegionizedServer")
val isMockbukkit = hasClass("org.mockbukkit.mockbukkit.exception.UnimplementedOperationException")
// Lore
fun ItemMeta.componentLore(): MutableList<Component> {
val lore = this.lore()
return lore ?: ArrayList()
}
fun ItemMeta.setComponentLore(lore: List<Component?>) {
this.lore(lore)
}
// Display name
private val useCustomName = hasMethod(ItemStack::class.java, "customName")
fun ItemMeta.componentDisplayName(): Component? {
if(useCustomName){
if(!this.hasCustomName()) return null //TODO check if I can use customName
return this.customName()
}else {
if(!this.hasDisplayName()) return null
return this.displayName()
}
}
fun ItemMeta.setComponentDisplayName(component: Component?) {
if(useCustomName){
this.customName(component)
}else {
this.displayName(component)
}
}
}

View file

@ -47,7 +47,7 @@ object AnvilLoreEditUtil {
lore.addAll(outLines)
meta.setComponentLore(lore)
meta.lore(lore)
result.itemMeta = meta
if (result == first) return null

View file

@ -19,8 +19,7 @@ object MiniMessageUtil {
)
.build()
val mm = if (PlatformUtil.isPaper) MiniMessage.miniMessage()
else color_only_mm
val mm = MiniMessage.miniMessage()
val legacy_mm = LegacyComponentSerializer.legacySection()
val plain_text_mm = PlainTextComponentSerializer.plainText()