mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
progress on merge
This commit is contained in:
parent
529e781a72
commit
9b723650e0
11 changed files with 15 additions and 159 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ object AnvilLoreEditUtil {
|
|||
|
||||
lore.addAll(outLines)
|
||||
|
||||
meta.setComponentLore(lore)
|
||||
meta.lore(lore)
|
||||
result.itemMeta = meta
|
||||
|
||||
if (result == first) return null
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue