Вопрос Как накинуть текстуру на голову при её установке

Destroy

Разработчик
Пользователь
Сообщения
777
Решения
30
Веб-сайт
destroydevs.ru
попробовал сделать так:
Java:
(Class - Utils):
    public static ItemStack item() {
        ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
        SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
        meta.setOwner("polkadot44");
        itemStack.setItemMeta(meta);
        return itemStack;
}

//-----------------------------------------------

for (Location loc : ListUtils.heads) {
    World world = Bukkit.getWorld("world");
    assert world != null;
    world.getBlockAt(loc).setType(Utils.item().getType());
    ListUtils.heads.remove(loc);
}

List<Location> heads = new ArrayList<>();

Установка голов не работает.
 
Последнее редактирование:
Java:
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();

if (skullMeta != null) {
    PlayerProfile playerProfile = null;

    if (this.owner != null) {
        playerProfile = Bukkit.createProfile(this.owner);
    } else if (this.uuid != null) {
        playerProfile = Bukkit.createProfile(this.uuid);
    }

    if (playerProfile == null) {
        return itemStack;
    }

    if (this.textureValue != null) {
        ProfileProperty profileProperty = new ProfileProperty("textures", this.textureValue);

        if (this.textureSignature != null) {
            profileProperty = new ProfileProperty("textures", this.textureValue, this.textureSignature);
        }

        playerProfile.setProperty(profileProperty);
    }
}

skullMeta.setPlayerProfile(playerProfile);
 
Последнее редактирование:
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); if (skullMeta != null) { PlayerProfile playerProfile = null; if (this.owner != null) { playerProfile = Bukkit.createProfile(this.owner); } else if (this.uuid != null) { playerProfile = Bukkit.createProfile(this.uuid); } if (playerProfile == null) { return itemStack; } if (this.textureValue != null) { ProfileProperty profileProperty = new ProfileProperty("textures", this.textureValue); if (this.textureSignature != null) { profileProperty = new ProfileProperty("textures", this.textureValue, this.textureSignature); } playerProfile.setProperty(profileProperty); } } skullMeta.setPlayerProfile(playerProfile);
Я использую Spigot, у меня нет параметра PlayerProfile
Объединено

Решение:
Java:
World world = Bukkit.getWorld("world";
                world.getBlockAt(loc).setType(Material.PLAYER_HEAD);
                Block block = world.getBlockAt(loc);
                Skull skull = (Skull) block.getState();
                skull.setOwner("polkadot44");
                skull.update();
Спасибо всем!
Объединено

Java:
private static void setUrl(String url, Skull skull) {
        GameProfile profile = new GameProfile(UUID.randomUUID(), null);
        profile.getProperties().put("textures", new Property("textures", url));
        Field profileField;
        try {
            profileField = skull.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(skull, profile);
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
            Logger.warn("Ошибка с головами игроков.");
        }
    }
 
Последнее редактирование:
Назад
Сверху Снизу