简体   繁体   中英

Bukkit/Spigot how to obtain player custom head ID

I am attempting to get the SkullOwner ID and the texture value out of any placed player skull but I can't figure out any method. The best thing I have gotten is merely the username of a player head that didn't require such IDs (basically meaning one that uses {SkullOwner:"PLAYERNAME"} , like for example the one obtained by doing /give @p skull 1 3 {SkullOwner:"Notch"} )

This is my code so far

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);
                }

        }
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM