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
1
nms/v1_21R6/.gitignore
vendored
1
nms/v1_21R6/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
.lastDeploymentsId
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
group = rootProject.group
|
||||
version = rootProject.version
|
||||
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":nms:nms-common"))
|
||||
|
||||
// Used for nms
|
||||
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
// Set target version
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = "21"
|
||||
targetCompatibility = "21"
|
||||
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.gui.version
|
||||
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView
|
||||
import org.bukkit.inventory.InventoryView
|
||||
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
|
||||
|
||||
class v1_21R6_ExternGuiTester: ExternGuiTester {
|
||||
override val wesjdAnvilGuiName = "Wrapper1_21_R6"
|
||||
|
||||
var tested = false;
|
||||
var possible = false;
|
||||
|
||||
override fun getContainerClass(view: InventoryView): Class<Any>? {
|
||||
// In case we are in a test environment
|
||||
if(!tested) testClassExist()
|
||||
if(!possible) return null
|
||||
|
||||
if(view !is CraftInventoryView<*, *>) return null
|
||||
val container = view.handle
|
||||
|
||||
return container.javaClass
|
||||
}
|
||||
|
||||
fun testClassExist(){
|
||||
tested = true;
|
||||
try {
|
||||
Class.forName("org.bukkit.craftbukkit.inventory.CraftInventoryView")
|
||||
possible = true
|
||||
} catch (e: ClassNotFoundException){
|
||||
possible = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.packet.versions
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket
|
||||
import net.minecraft.world.entity.player.Abilities
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer
|
||||
import org.bukkit.entity.Player
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase
|
||||
|
||||
class V1_21R6_PacketManager : PacketManagerBase(), PacketManager {
|
||||
override val canSetInstantBuild: Boolean
|
||||
get() = true
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
val nmsPlayer = (player as CraftPlayer).handle
|
||||
val playerAbilities = nmsPlayer.abilities
|
||||
val sendedAbilities: Abilities
|
||||
if (playerAbilities.instabuild == instantBuild) {
|
||||
sendedAbilities = playerAbilities
|
||||
} else {
|
||||
sendedAbilities = Abilities()
|
||||
sendedAbilities.invulnerable = playerAbilities.invulnerable
|
||||
sendedAbilities.flying = playerAbilities.flying
|
||||
sendedAbilities.mayfly = playerAbilities.mayfly
|
||||
sendedAbilities.instabuild = instantBuild
|
||||
sendedAbilities.mayBuild = playerAbilities.mayBuild
|
||||
sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed
|
||||
sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed
|
||||
}
|
||||
val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities)
|
||||
nmsPlayer.connection.send(packet)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.util
|
||||
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
|
|
@ -27,42 +26,19 @@ object PlatformUtil {
|
|||
}
|
||||
}
|
||||
|
||||
val isPaper = hasClass("com.destroystokyo.paper.PaperConfig") ||
|
||||
hasClass("io.papermc.paper.configuration.Configuration")
|
||||
|
||||
val isFolia = hasClass("io.papermc.paper.threadedregions.RegionizedServer")
|
||||
|
||||
private val legacy_mm = LegacyComponentSerializer.legacySection()
|
||||
val isMockbukkit = hasClass("org.mockbukkit.mockbukkit.exception.UnimplementedOperationException")
|
||||
|
||||
// Lore
|
||||
fun ItemMeta.componentLore(): MutableList<Component> {
|
||||
val lore: List<Component>?
|
||||
if(isPaper){
|
||||
lore = this.lore()
|
||||
} else {
|
||||
val legacyLores = this.lore ?: return ArrayList()
|
||||
|
||||
lore = ArrayList(legacyLores.size)
|
||||
for (legacyLore in legacyLores) {
|
||||
lore.add(legacy_mm.deserialize(legacyLore))
|
||||
}
|
||||
}
|
||||
|
||||
val lore = this.lore()
|
||||
return lore ?: ArrayList()
|
||||
}
|
||||
|
||||
fun ItemMeta.setComponentLore(lore: List<Component?>) {
|
||||
if(isPaper){
|
||||
this.lore(lore)
|
||||
} else {
|
||||
val legacyLore = ArrayList<String?>(lore.size)
|
||||
for (component in lore) {
|
||||
legacyLore.add(if(component == null) null
|
||||
else legacy_mm.serialize(component))
|
||||
}
|
||||
|
||||
this.lore = legacyLore
|
||||
}
|
||||
this.lore(lore)
|
||||
}
|
||||
|
||||
// Display name
|
||||
|
|
@ -70,32 +46,19 @@ object PlatformUtil {
|
|||
|
||||
fun ItemMeta.componentDisplayName(): Component? {
|
||||
if(useCustomName){
|
||||
if(!this.hasCustomName()) return null
|
||||
if(!this.hasCustomName()) return null //TODO check if I can use customName
|
||||
return this.customName()
|
||||
}else if(isPaper){
|
||||
}else {
|
||||
if(!this.hasDisplayName()) return null
|
||||
return this.displayName()
|
||||
} else {
|
||||
if(!this.hasDisplayName()) return null
|
||||
|
||||
val legacy = this.displayName
|
||||
return legacy_mm.deserialize(legacy)
|
||||
}
|
||||
}
|
||||
|
||||
fun ItemMeta.setComponentDisplayName(component: Component?) {
|
||||
if(useCustomName){
|
||||
this.customName(component)
|
||||
}else if(isPaper){
|
||||
}else {
|
||||
this.displayName(component)
|
||||
} else {
|
||||
if(component == null){
|
||||
this.setDisplayName(null)
|
||||
return
|
||||
}
|
||||
|
||||
val legacy = legacy_mm.serialize(component)
|
||||
this.setDisplayName(legacy)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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