From 0182506f446ca01322950f669e0a56932d66a09d Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Tue, 25 Apr 2023 13:08:08 +0200 Subject: [PATCH] Fix SkullBuilder not setting serializedProfile in SkullMeta --- inventoryaccess/inventory-access/pom.xml | 12 ++++++++++++ .../inventoryaccess/util/ReflectionRegistry.java | 14 ++++++++++---- .../xenondevs/invui/item/builder/SkullBuilder.java | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/inventoryaccess/inventory-access/pom.xml b/inventoryaccess/inventory-access/pom.xml index 7602bd6..fd1ed26 100644 --- a/inventoryaccess/inventory-access/pom.xml +++ b/inventoryaccess/inventory-access/pom.xml @@ -31,6 +31,18 @@ 1.16.4-R0.1-SNAPSHOT provided + + com.mojang + authlib + 1.5.21 + provided + + + * + * + + + net.kyori adventure-api diff --git a/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/util/ReflectionRegistry.java b/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/util/ReflectionRegistry.java index 020b7fc..df3987d 100644 --- a/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/util/ReflectionRegistry.java +++ b/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/util/ReflectionRegistry.java @@ -1,6 +1,9 @@ package xyz.xenondevs.inventoryaccess.util; +import com.mojang.authlib.GameProfile; + import java.lang.reflect.Field; +import java.lang.reflect.Method; import static xyz.xenondevs.inventoryaccess.util.ReflectionUtils.*; @@ -13,12 +16,15 @@ public class ReflectionRegistry { public static final String BUKKIT_PACKAGE_PATH = "org.bukkit."; // Classes - public static final Class CB_CRAFT_META_SKULL_CLASS = getCBClass("inventory.CraftMetaSkull"); - // Fields - public static final Field CB_CRAFT_META_SKULL_PROFILE_FIELD = getField(CB_CRAFT_META_SKULL_CLASS, true, "profile"); public static final Class PLUGIN_CLASS_LOADER_CLASS = getBukkitClass("plugin.java.PluginClassLoader"); - public static final Field PLUGIN_CLASS_LOADER_PLUGIN_FIELD = getField(PLUGIN_CLASS_LOADER_CLASS, true, "plugin"); + public static final Class CB_CRAFT_META_SKULL_CLASS = getCBClass("inventory.CraftMetaSkull"); public static final Class CB_CRAFT_META_ITEM_CLASS = getCBClass("inventory.CraftMetaItem"); + + // Methods + public static final Method CB_CRAFT_META_SKULL_SET_PROFILE_METHOD = getMethod(CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class); + + // Fields + public static final Field PLUGIN_CLASS_LOADER_PLUGIN_FIELD = getField(PLUGIN_CLASS_LOADER_CLASS, true, "plugin"); public static final Field CB_CRAFT_META_ITEM_DISPLAY_NAME_FIELD = getField(CB_CRAFT_META_ITEM_CLASS, true, "displayName"); public static final Field CB_CRAFT_META_ITEM_LORE_FIELD = getField(CB_CRAFT_META_ITEM_CLASS, true, "lore"); diff --git a/invui-core/src/main/java/xyz/xenondevs/invui/item/builder/SkullBuilder.java b/invui-core/src/main/java/xyz/xenondevs/invui/item/builder/SkullBuilder.java index 0a068ac..6e7ea90 100644 --- a/invui-core/src/main/java/xyz/xenondevs/invui/item/builder/SkullBuilder.java +++ b/invui-core/src/main/java/xyz/xenondevs/invui/item/builder/SkullBuilder.java @@ -68,7 +68,7 @@ public final class SkullBuilder extends AbstractItemBuilder { ItemMeta meta = item.getItemMeta(); if (gameProfile != null) - ReflectionUtils.setFieldValue(ReflectionRegistry.CB_CRAFT_META_SKULL_PROFILE_FIELD, meta, gameProfile); + ReflectionUtils.invokeMethod(ReflectionRegistry.CB_CRAFT_META_SKULL_SET_PROFILE_METHOD, meta, gameProfile); item.setItemMeta(meta);