0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【令和最新版】Spigotでプレイヤーの頭のテクスチャを直接指定する【Kotlin】

Posted at

結論

【拡張関数】ItemStack.kt

import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.SkullMeta

fun ItemStack.setHeadTexture(textureValue: URL) {
    //なくてもいいよ
    require(this.type == Material.PLAYER_HEAD) { "PLAYER_HEAD以外では使用できません" }

    val meta = this.itemMeta as SkullMeta
    val dummyProfile = Bukkit.createPlayerProfile(UUID.randomUUID())

    val texture = dummyProfile.textures
    texture.skin = (textureValue)

    dummyProfile.setTextures(texture)

    meta.ownerProfile = dummyProfile
    this.itemMeta = meta
}

textureValueにはhttp://textures.minecraft.net/texture/...のURL(base64エンコードされてる奴)を入れればok
従来のGameProfileいじるやつはauthlibが必要だったりちょっとだけリフレクション使ったり面倒だったのでいい感じ?

Javaのコードが欲しい人へ

ChatGPTにお願いしてください

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?