From 81de46a1c122a3cd6be06696b5b02d55fd9a73e5 Mon Sep 17 00:00:00 2001 From: Will FP Date: Sun, 22 Sep 2024 16:49:08 +0100 Subject: [PATCH] Fixed skull on 1.21 --- eco-core/core-backend-modern/build.gradle.kts | 2 +- eco-core/core-backend/build.gradle.kts | 2 +- .../eco/internal/spigot/proxy/common/Skull.kt | 2 +- eco-core/core-nms/modern/build.gradle.kts | 2 +- .../spigot/proxy/common/modern/ModernSkull.kt | 55 +++++++++++++++++++ eco-core/core-nms/v1_21/build.gradle.kts | 2 +- .../eco/internal/spigot/proxy/v1_21/Skull.kt | 2 +- eco-core/core-plugin/build.gradle.kts | 2 +- gradle.properties | 2 +- 9 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/ModernSkull.kt diff --git a/eco-core/core-backend-modern/build.gradle.kts b/eco-core/core-backend-modern/build.gradle.kts index 8d6db439d..c134a537c 100644 --- a/eco-core/core-backend-modern/build.gradle.kts +++ b/eco-core/core-backend-modern/build.gradle.kts @@ -3,7 +3,7 @@ version = rootProject.version dependencies { compileOnly(project(":eco-core:core-backend")) - compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT") } tasks { diff --git a/eco-core/core-backend/build.gradle.kts b/eco-core/core-backend/build.gradle.kts index 94614290f..2402c279f 100644 --- a/eco-core/core-backend/build.gradle.kts +++ b/eco-core/core-backend/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { implementation("org.objenesis:objenesis:3.2") compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") - compileOnly("me.clip:placeholderapi:2.11.4") + compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("net.kyori:adventure-text-minimessage:4.10.0") compileOnly("net.kyori:adventure-platform-bukkit:4.1.0") compileOnly("org.yaml:snakeyaml:1.33") diff --git a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/Skull.kt b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/Skull.kt index a0fcc473c..d5f9a2b7a 100644 --- a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/Skull.kt +++ b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/Skull.kt @@ -48,7 +48,7 @@ var SkullMeta.texture: String? * at java.lang.String.checkBoundsBeginEnd(String.java:4604) ~[?:?] * at java.lang.String.substring(String.java:2707) ~[?:?] * at java.lang.String.substring(String.java:2680) ~[?:?] - * at com.willfp.eco.internal.spigot.proxy.v1_19_R1.common.SkullKt.setTexture(Skull.kt:36) + * at com.willfp.eco.internal.spigot.proxy.v1_19_R1.common.SkullKt.setTexture(ModernSkull.kt:36) * if (base64.length < 20) { return diff --git a/eco-core/core-nms/modern/build.gradle.kts b/eco-core/core-nms/modern/build.gradle.kts index 720980855..7a4daf934 100644 --- a/eco-core/core-nms/modern/build.gradle.kts +++ b/eco-core/core-nms/modern/build.gradle.kts @@ -7,7 +7,7 @@ version = rootProject.version dependencies { compileOnly(project(":eco-core:core-nms:common")) - paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") } tasks { diff --git a/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/ModernSkull.kt b/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/ModernSkull.kt new file mode 100644 index 000000000..6955d78ee --- /dev/null +++ b/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/ModernSkull.kt @@ -0,0 +1,55 @@ +package com.willfp.eco.internal.spigot.proxy.common.modern + +import com.mojang.authlib.GameProfile +import com.mojang.authlib.properties.Property +import net.minecraft.world.item.component.ResolvableProfile +import org.bukkit.inventory.meta.SkullMeta +import java.lang.reflect.Field +import java.lang.reflect.Method +import java.util.UUID + +private lateinit var setProfile: Method +private lateinit var profile: Field +private lateinit var value: Field + +var SkullMeta.texture: String? + get() { + if (!::value.isInitialized) { + // Doing it this way because Property was changed to be a record and this is + // a quick hack to get around that + value = Property::class.java.getDeclaredField("value") + value.isAccessible = true + } + + if (!::profile.isInitialized) { + // Assumes instance of CraftMetaSkull; package-private class so can't do manual type check + profile = this.javaClass.getDeclaredField("profile") + profile.isAccessible = true + } + + val profile = profile[this] as ResolvableProfile? ?: return null + val properties = profile.properties ?: return null + val props = properties["textures"] ?: return null + val prop = props.toMutableList().firstOrNull() ?: return null + return value[prop] as String? + } + set(base64) { + if (!::setProfile.isInitialized) { + // Same here; that's why I can't delegate to a lazy initializer + setProfile = this.javaClass.getDeclaredMethod("setProfile", ResolvableProfile::class.java) + setProfile.isAccessible = true + } + + if (base64 == null || base64.length < 20) { + setProfile.invoke(this, null) + } else { + val uuid = UUID( + base64.substring(base64.length - 20).hashCode().toLong(), + base64.substring(base64.length - 10).hashCode().toLong() + ) + val profile = GameProfile(uuid, "eco") + profile.properties.put("textures", Property("textures", base64)) + val resolvable = ResolvableProfile(profile) + setProfile.invoke(this, resolvable) + } + } diff --git a/eco-core/core-nms/v1_21/build.gradle.kts b/eco-core/core-nms/v1_21/build.gradle.kts index 3f488f903..fb696f9d6 100644 --- a/eco-core/core-nms/v1_21/build.gradle.kts +++ b/eco-core/core-nms/v1_21/build.gradle.kts @@ -8,7 +8,7 @@ version = rootProject.version dependencies { implementation(project(":eco-core:core-nms:modern")) implementation(project(":eco-core:core-nms:common")) - paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") implementation("net.kyori:adventure-text-minimessage:4.11.0") { version { diff --git a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/Skull.kt b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/Skull.kt index 6dae8aea4..11bf76a18 100644 --- a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/Skull.kt +++ b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/Skull.kt @@ -1,7 +1,7 @@ package com.willfp.eco.internal.spigot.proxy.v1_21 import com.willfp.eco.internal.spigot.proxy.SkullProxy -import com.willfp.eco.internal.spigot.proxy.common.texture +import com.willfp.eco.internal.spigot.proxy.common.modern.texture import org.bukkit.inventory.meta.SkullMeta class Skull : SkullProxy { diff --git a/eco-core/core-plugin/build.gradle.kts b/eco-core/core-plugin/build.gradle.kts index dec464901..f9b575c23 100644 --- a/eco-core/core-plugin/build.gradle.kts +++ b/eco-core/core-plugin/build.gradle.kts @@ -35,7 +35,7 @@ dependencies { compileOnly("fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT") compileOnly("com.github.jiangdashao:matrix-api-repo:317d4635fd") compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.202") - compileOnly("me.clip:placeholderapi:2.11.4") + compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("com.github.brcdev-minecraft:shopgui-api:3.0.0") compileOnly("com.github.LoneDev6:API-ItemsAdder:2.4.7") compileOnly("com.arcaniax:HeadDatabase-API:1.3.1") diff --git a/gradle.properties b/gradle.properties index 2e485e4c7..8cb3adcdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.74.1 +version = 6.74.2 kotlin.incremental.useClasspathSnapshot=false \ No newline at end of file