Skip to content

Commit

Permalink
Fixed skull on 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Sep 22, 2024
1 parent 9814e59 commit 81de46a
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eco-core/core-backend-modern/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion eco-core/core-backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eco-core/core-nms/modern/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion eco-core/core-nms/v1_21/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion eco-core/core-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 6.74.1
version = 6.74.2
kotlin.incremental.useClasspathSnapshot=false

0 comments on commit 81de46a

Please sign in to comment.