Skip to content

Commit

Permalink
SkullMetaPatcher Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste3et committed Sep 29, 2024
1 parent 304c553 commit 4fd0ed8
Showing 1 changed file with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Objects;
import java.util.UUID;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
Expand Down Expand Up @@ -47,28 +48,11 @@ public static ItemStack patch(ItemStack stack, NBTTagCompound compound) {
if(skullCompound.hasKeyOfType("Properties", 10)) {
NBTTagCompound propertiesCompound = skullCompound.getCompound("Properties");
if(propertiesCompound.hasKeyOfType("textures", 9)) {
ItemMeta headMeta = stack.getItemMeta();
NBTTagList textureCompound = propertiesCompound.getList("textures");
NBTTagCompound texturestring = textureCompound.get(0);
String base64String = texturestring.getString("Value");
WrappedGameProfile gameProfile = makeProfile(base64String);
try {

Field field = headMeta.getClass().getDeclaredField("profile");
field.setAccessible(true);

if(field.getType().getSimpleName().contains("ResolvableProfile")) {
Object object = Class.forName("net.minecraft.world.item.component.ResolvableProfile").getConstructor(gameProfile.getHandleType()).newInstance(gameProfile.getHandle());
field.set(headMeta, object);
}else {
field.set(headMeta, gameProfile.getHandle());
}

} catch (Exception e) {
e.printStackTrace();
} finally {
stack.setItemMeta(headMeta);
}
patch(stack, gameProfile);
}
}
}
Expand All @@ -77,6 +61,28 @@ public static ItemStack patch(ItemStack stack, NBTTagCompound compound) {
return stack;
}

public static ItemStack patch(ItemStack stack, WrappedGameProfile gameProfile) {
ItemMeta headMeta = stack.getItemMeta();
try {

Field field = headMeta.getClass().getDeclaredField("profile");
field.setAccessible(true);

if(field.getType().getSimpleName().contains("ResolvableProfile")) {
Object object = Class.forName("net.minecraft.world.item.component.ResolvableProfile").getConstructor(gameProfile.getHandleType()).newInstance(gameProfile.getHandle());
field.set(headMeta, object);
}else {
field.set(headMeta, gameProfile.getHandle());
}

} catch (Exception e) {
e.printStackTrace();
} finally {
stack.setItemMeta(headMeta);
}
return stack;
}

public static boolean shouldPatch() {
return needPatcher;
}
Expand All @@ -90,5 +96,11 @@ public static WrappedGameProfile makeProfile(String b64) {
profile.getProperties().put("textures", new WrappedSignedProperty("textures", b64, "furniture"));
return profile;
}

public static ItemStack createStack(String b64) {
ItemStack stack = new ItemStack(Material.valueOf("PLAYER_HEAD"));
patch(stack, makeProfile(b64));
return stack;
}

}

0 comments on commit 4fd0ed8

Please sign in to comment.