CryptoMorin / XSeries

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

Fix XSkull#applySkin with name or UUID inputs (#254) #256

Closed Condordito closed 4 months ago

Condordito commented 4 months ago

Additions

Changes

Fixes


Screenshot 2024-05-22 at 11 07 10 AM
CryptoMorin commented 4 months ago

I think we need to make an inner class that makes dynamically configurable requests like ParticleDisplay. For example, we could make the logging optional and propagate the error instead, or add two sync and async methods to allow the user to decide whether they want to keep the request in the same thread or not (in case the item meta is already being built in an async thread from the user)

Or we could just use the XSkull class itself instead of creating a new inner class.

public static Builder of(ItemStack item) { return new Builder(item); }
public static final class Builder {
    private ItemStack item;
    private SkullMeta meta;
    private SkullValue value;
    private GameProfile defaultValue = DEFAULT_PROFILE; // Or maybe a default SkullValue instead.
    private boolean propagateError = false;

    public Builder propogateError() {
        this.propogateError = true;
        return this;
    }

    public Builder fromString(String string) {
        value = /* detect it */;
        return this;
    }

    public Builder fromUsername(String name) {
        // fromUUID, fromBase64 etc
        value = new SkullValue(ValueType.NAME, name);
        return this;
    }

    public SkullMeta apply() {
        return applySkin(meta, value); // should make a separate method for this
    }

    public CompletableFuture<SkullMeta> applyAsync() {
        return CompletableFuture.supplyAsync(this::apply, PROFILE_EXECUTOR);
    }
}

Also, which versions did you test this with? It should support 1.8+

Condordito commented 4 months ago

@CryptoMorin

I made it more configurable and moved it into a separate package. It now logs exceptions using the debug level. So far, I've tested it on 1.8.9, 1.12.2, 1.19.4, and 1.20.4. I still need to document it and check for any additional remaps

CryptoMorin commented 4 months ago

Thank you very much! I'll have to test this a little and see if more changes are needed.