Paper icon indicating copy to clipboard operation
Paper copied to clipboard

GameProfile now requires both the id and name, but OfflinePlayer doesn't allow you to specify both.

Open CC007 opened this issue 1 year ago • 6 comments

Expected behavior

Being able to create a GameProfile object with either the id or the name and therefore the following code working:

meta.setOwningPlayer(Bukkit.getOfflinePlayer(NOTCH_UUID)); // meta is a SkullMeta object,

See authlib v4.0.43:

public GameProfile(final UUID id, final String name) {
    this.properties = new PropertyMap();
    if (id == null && StringUtils.isBlank((CharSequence)name)) {
        throw new IllegalArgumentException("Name and ID cannot both be blank");
    }
    this.id = id;
    this.name = name;
}

Observed/Actual behavior

Being forced to provide both the id AND the name:

In PurpurMC: 275263138-9f46b60a-e11e-43a6-9e8a-195d7db6d3ab

In PaperMC: 275341831-44ab0989-95b7-4d94-908c-a12a37dd39fd

See authlib 5.0.47:

public GameProfile(final UUID id, final String name) {
    this.properties = new PropertyMap();
    this.id = Objects.requireNonNull(id, "Profile ID must not be null");
    this.name = Objects.requireNonNull(name, "Profile name must not be null");
}

Also, there is no method to create an OfflinePlayer where you specify both the id and name, so setOwningPlayer will fail when providing it with an OfflinePlayer.

Steps/models to reproduce

Code that triggered this issue:

private void initSkullMeta(@NonNull ItemStack playerHeadItemStack, @NonNull Head head) {
    final var headSkullMeta = Optional.ofNullable((SkullMeta) playerHeadItemStack.getItemMeta());
    headSkullMeta.ifPresentOrElse(meta -> {
        meta.setOwningPlayer(Bukkit.getOfflinePlayer(NOTCH_UUID)); // <- exception thrown here
        // set other meta fields. Not relevant to this bug
        playerHeadItemStack.setItemMeta(meta);
    }, () -> {
        log.warn("Couldn't find player skull meta.");
    });
}

Plugin and Datapack List

Plugins HeadsPluginAPI HeadsInventory HeadSweeper

Nothing else was added.

Paper version

PaperMC 1.20.2 (build 240)

Sidenote: Also occurs in PurpurMC 1.20.2 (build 2074 and 2078)

Other

Issue found by a user of HeadsPluginAPI on a PurpurMC server. I'm tracking the issue in https://github.com/CC007/HeadsPluginAPI/issues/31

It was also reported the issue to PurpurMC: https://github.com/PurpurMC/Purpur/issues/1445, but after reproducing the issue in PaperMC, I was asked to make an issue here.

CC007 avatar Oct 15 '23 17:10 CC007

This seems to be related to #9770 view latest comment and Lulus comment about the related issues

notTamion avatar Oct 16 '23 19:10 notTamion

OfflinePlayer and PlayerProfile both indeed use GameProfile, which is where the breaking change is.

That pull request only fixes PlayerProfile though, not OfflinePlayer.

CC007 avatar Oct 16 '23 23:10 CC007

I am replying so I am subscribed to this bug report; sorry for the useless post.

/ rush order for fix <3 /

mrfloris avatar Nov 04 '23 03:11 mrfloris

I am replying so I am subscribed to this bug report; sorry for the useless post.

/ rush order for fix <3 /

There's a notifications section on this page where you can hit subscribe/unsubscribe

CC007 avatar Nov 04 '23 15:11 CC007

When using Bukkit.getOfflinePlayer("Notch") instead of Bukkit.getOfflinePlayer(NOTCH_UUID), it seems that there's no issue, so that's a decent workaround, but it would be nice if this also worked with the uuid, since that's the recommended way to get an offline player.

CC007 avatar Nov 04 '23 15:11 CC007

Does anyone have an update for this issue?

MrButtersDEV avatar Feb 01 '24 04:02 MrButtersDEV