Bukkit / Spigot如何获取玩家自定义头像ID

时间:2019-03-04 22:58:17

标签: java bukkit

我正在尝试从任何放置的玩家头骨中获取SkullOwner ID和纹理值,但我找不到任何方法。我得到的最好的东西就是不需要这样的ID的玩家头像的用户名(基本上是指使用{SkullOwner:"PLAYERNAME"}的ID,例如通过执行/give @p skull 1 3 {SkullOwner:"Notch"}获得的ID)

到目前为止,这是我的代码

package me.saltyhelpvampire.spigotmushroom;

import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class SpigotMushroom extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        // Plugin startup logic
        System.out.println("This is a generic message");
        getServer().getPluginManager().registerEvents(this, this);

    }

    @EventHandler
    public void onMushroomheadPlace(BlockPlaceEvent event) {
        Player player = event.getPlayer();
        if (event.getBlock().getType() == Material.SKULL) {
                event.getPlayer().sendMessage("Player placed head");
                BlockState block = event.getBlock().getState();
                if(block instanceof Skull) {
                    Skull skull = (Skull) block;
                    String owner = skull.getOwner();
                    event.getPlayer().sendMessage(owner);
                }

        }
    }
}

1 个答案:

答案 0 :(得分:1)

在Minecraft中,如果放置的头骨仅具有玩家名称作为nbt值,则客户端加载皮肤数据而不是服务器,则必须使用mojang api,在那里您可以将名称转换为UUID,然后获取该UUID的纹理