Skip to content

Commit

Permalink
fix: playerHead profile field
Browse files Browse the repository at this point in the history
  • Loading branch information
LupusVirtute committed Sep 28, 2022
1 parent 8841847 commit 0b6d4e4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.spacemc</groupId>
<artifactId>SpaceUtils</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<packaging>jar</packaging>

<name>SpaceUtils</name>
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/org/spacemc/utils/item/ItemBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -414,53 +414,13 @@ class ItemBuilder {

val profile: PlayerProfile = Bukkit.createProfileExact(UUID.randomUUID(), "Skull")
profile.properties.add(ProfileProperty("textures", String(encodedData)))
var profileField: Field? = null
try {
profileField = meta.javaClass.getDeclaredField("profile")
profileField.isAccessible = true
profileField.set(meta, profile)
} catch (e: Exception) {
e.printStackTrace()
}

meta.playerProfile = profile
this.item.itemMeta = meta

return this
}

fun customTexture(texture: String): ItemBuilder {
var texture = texture
texture = "http://textures.minecraft.net/texture/$texture"
if (texture.isEmpty()) {
return this
}
val skullMeta: SkullMeta = this.meta() as SkullMeta
val profile = Bukkit.createProfile(UUID.randomUUID(), null)
val encodedData: ByteArray =
Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", texture).toByteArray())
profile.properties.add(ProfileProperty("textures", String(encodedData)))
var profileField: Field? = null
try {
profileField = skullMeta.javaClass.getDeclaredField("profile")
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: SecurityException) {
e.printStackTrace()
}
assert(profileField != null)
profileField!!.isAccessible = true
try {
profileField[skullMeta] = profile
} catch (e: IllegalArgumentException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}
make().setItemMeta(skullMeta)
return this
}

/**
* Returns the [ItemMeta] of the [ItemStack]
*
Expand Down

0 comments on commit 0b6d4e4

Please sign in to comment.