Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;

public final class CustomGameProfile extends GameProfile {
public final class CustomGameProfile {

/**
* The player name for this profile.
Expand All @@ -33,9 +33,10 @@ public final class CustomGameProfile extends GameProfile {

private final URL skinUrl;
private final String texture;

CustomGameProfile(@Nonnull UUID uuid, @Nullable String texture, @Nonnull URL url) {
super(uuid, PLAYER_NAME);
private final GameProfile delegate;

public CustomGameProfile(@Nonnull UUID uuid, @Nullable String texture, @Nonnull URL url) {
this.delegate = new GameProfile(uuid, PLAYER_NAME);
this.skinUrl = url;
this.texture = texture;

Expand All @@ -44,24 +45,22 @@ public final class CustomGameProfile extends GameProfile {
}
}

void apply(@Nonnull SkullMeta meta) throws NoSuchFieldException, IllegalAccessException, UnknownServerVersionException {
// setOwnerProfile was added in 1.18, but getOwningPlayer throws a NullPointerException since 1.20.2
public void apply(@Nonnull SkullMeta meta) throws NoSuchFieldException, IllegalAccessException, UnknownServerVersionException {
if (MinecraftVersion.get().isAtLeast(MinecraftVersion.parse("1.20"))) {
PlayerProfile playerProfile = Bukkit.createPlayerProfile(this.getId(), PLAYER_NAME);
PlayerProfile playerProfile = Bukkit.createPlayerProfile(this.delegate.getId(), PLAYER_NAME);
PlayerTextures playerTextures = playerProfile.getTextures();
playerTextures.setSkin(this.skinUrl);
playerProfile.setTextures(playerTextures);
meta.setOwnerProfile(playerProfile);
} else {
// Forces SkullMeta to properly deserialize and serialize the profile
ReflectionUtils.setFieldValue(meta, "profile", this);
// Force SkullMeta to use our wrapped GameProfile
ReflectionUtils.setFieldValue(meta, "profile", this.delegate);

meta.setOwningPlayer(meta.getOwningPlayer());

// Now override the texture again
ReflectionUtils.setFieldValue(meta, "profile", this);
// Override the texture again
ReflectionUtils.setFieldValue(meta, "profile", this.delegate);
}

}

/**
Expand All @@ -73,4 +72,8 @@ void apply(@Nonnull SkullMeta meta) throws NoSuchFieldException, IllegalAccessEx
public String getBase64Texture() {
return this.texture;
}

public GameProfile getHandle() {
return this.delegate;
}
}