Skip to content

Commit d52a9ad

Browse files
committed
feat: texture from base64
1 parent 5b4d34f commit d52a9ad

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/kotlin/cc/modlabs/kpaper/inventory/ItemBuilder.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import java.lang.reflect.Field
3131
import java.net.URL
3232
import java.util.*
3333
import java.util.concurrent.TimeUnit
34+
import kotlin.text.take
3435

3536

3637
/**
@@ -276,14 +277,20 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
276277
fun texture(texture: String): ItemBuilder {
277278
if (itemStack.type != Material.PLAYER_HEAD) return this
278279
val url = "https://textures.minecraft.net/texture/$texture"
279-
val profile = GameProfile(UUID.randomUUID(), "head${texture.take(6)}")
280280
val encodedData =
281281
Base64.getEncoder()
282282
.encode(
283283
String.format("{textures:{SKIN:{url:\"%s\"}}}", url)
284284
.toByteArray()
285285
)
286-
profile.properties.put("textures", Property("textures", String(encodedData)))
286+
287+
return textureFromBase64(String(encodedData))
288+
}
289+
290+
fun textureFromBase64(base64: String): ItemBuilder {
291+
if (itemStack.type != Material.PLAYER_HEAD) return this
292+
val profile = GameProfile(UUID.randomUUID(), "head${base64.take(6)}")
293+
profile.properties.put("textures", Property("textures", base64))
287294
try {
288295
val skullMeta = itemStack.itemMeta as SkullMeta
289296
val profileField: Field = skullMeta.javaClass.getDeclaredField("profile")

0 commit comments

Comments
 (0)