Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix skull on 1.21.1 #250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
@@ -0,0 +1,33 @@
package eu.decentsoftware.holograms.api.utils.items;

import com.mojang.authlib.GameProfile;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

class SkullProfile {
public static Constructor<?> gameProfileField;

static {
try {
Class<?> resolvableProfileClass = Class.forName("net.minecraft.world.item.component.ResolvableProfile");
Class<?> gameProfileClass = Class.forName("com.mojang.authlib.GameProfile");

Constructor<?> constructor = resolvableProfileClass.getDeclaredConstructor(gameProfileClass);
constructor.setAccessible(true);
gameProfileField = constructor;

} catch (Exception e) {
e.printStackTrace();
gameProfileField = null;
}
}

public static Object getObject(GameProfile profile) {
try {
return gameProfileField.newInstance(profile);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,17 @@ public static void setSkullTexture(@NonNull ItemStack itemStack, @NonNull String
PROFILE_FIELD = meta.getClass().getDeclaredField("profile");
PROFILE_FIELD.setAccessible(true);
}
PROFILE_FIELD.set(meta, profile);

// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java?at=8d52226914ce4b99f35be3d6954f35616d92476d
// SPIGOT-7882, #1467: Fix conversion of name in Profile Component to empty if it is missing
try {
PROFILE_FIELD.set(meta, profile);
} catch (Throwable ignored) {
PROFILE_FIELD.set(
meta,
SkullProfile.getObject(profile)
);
}
}
}
itemStack.setItemMeta(meta);
Expand Down