CryptoMorin / XSeries

Library for cross-version Minecraft Bukkit support and various efficient API methods.
https://www.spigotmc.org/threads/378136/
MIT License
403 stars 126 forks source link

SkullUtils - Issue #225

Closed Creuch closed 1 year ago

Creuch commented 1 year ago

Description I'm trying to make a inventory with custom heads. Everything is working fine, until I make SkullUtils methods async, to don't lag the server. Then the skulls are never set to anything and always are Steve's

Working fine:

            String skullOwner = config.getValue("guis.yml", section.getCurrentPath() + ".skullOwner").replacePlaceholder();
            String skullTexture = config.getValue("guis.yml", section.getCurrentPath() + ".skullTexture");
            if(skullOwner != null) {
                skullMeta = SkullUtils.applySkin(itemMeta, skullOwner);
            }
            if(skullTexture != null) {
                skullMeta = SkullUtils.applySkin(itemMeta, skullTexture);
            }

Doesn't work:

            String skullOwner = config.getValue("guis.yml", section.getCurrentPath() + ".skullOwner").replacePlaceholder();
            String skullTexture = config.getValue("guis.yml", section.getCurrentPath() + ".skullTexture");
            Bukkit.getScheduler().runTaskAsynchronously(instance, new Runnable() {
                @Override
                public void run() {
                    if(skullOwner != null) {
                        skullMeta = SkullUtils.applySkin(itemMeta, skullOwner);
                    }
                    if(skullTexture != null) {
                        skullMeta = SkullUtils.applySkin(itemMeta, skullTexture);
                    }
                    itemStack.setItemMeta(skullMeta);
                }
            });

Version git-Paper-307 (MC: 1.19.2)

CryptoMorin commented 1 year ago

Can I see the strings? Also the skullTexture is overriding skullOwner, or am I missing something? They're used on the same item meta. Or maybe you're using them as an alias.

Creuch commented 1 year ago

Can I see the strings? skullOwner = _Creuch skullTexture = eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdhY2ZmNThjMjExZTQ2ODA2ZDRhYzlhNzczMjBiZjU3MjUwZWQ4YmY3OTMzZWE0M2FjOGVmMmZkNzBkZWZkYyJ9fX0=

Also the skullTexture is overriding skullOwner, or am I missing something? They're used on the same item meta. Or maybe you're using them as an alias. It is, if both are set. If a user wants only skullOwner, then they aren't setting userTexture, so it's null

CryptoMorin commented 1 year ago

It's working fine for me

fun giveSkull(sync: Boolean, value: String, prevSync: Boolean = sync) {
    if (!sync) {
        Bukkit.getScheduler().runTaskAsynchronously(plugin) { -> giveSkull(true, value, false) }
        return
    }
    val item = XMaterial.PLAYER_HEAD.parseItem()!!
    var meta = item.itemMeta as SkullMeta
    meta = SkullUtils.applySkin(meta, value)
    meta.setDisplayName("$prevSync|${Bukkit.isPrimaryThread()} $value")
    item.itemMeta = meta
    player.inventory.addItem(item)
}
giveSkull(true, "_Creuch")
giveSkull(true, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdhY2ZmNThjMjExZTQ2ODA2ZDRhYzlhNzczMjBiZjU3MjUwZWQ4YmY3OTMzZWE0M2FjOGVmMmZkNzBkZWZkYyJ9fX0=")
giveSkull(false, "_Creuch")
giveSkull(false, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdhY2ZmNThjMjExZTQ2ODA2ZDRhYzlhNzczMjBiZjU3MjUwZWQ4YmY3OTMzZWE0M2FjOGVmMmZkNzBkZWZkYyJ9fX0=")

But I must say that the result for _Creuch is not correctly displayed sync and async inside the inventory. It's displayed correctly when placed. I tested this with Essentials /skull too which means whatever it is, it's not a SkullUtils bug.

Creuch commented 1 year ago

Now it is for me too, idk why :/

    public ItemStack asSkull(ItemStack[] is, String owner, boolean async) {
        if(async) Bukkit.getScheduler().runTaskAsynchronously(instance, () -> is[0] = asSkull(is, owner, false));
        SkullMeta sm = (SkullMeta) is[0].getItemMeta();
        sm = SkullUtils.applySkin(sm, owner);
        is[0].setItemMeta(sm);
        return is[0];
    }

Anyway, thanks for the help