Remove ItemUtils#setSkullGameProfile

Because both Paper 1.14.4 and 1.15.0 are not up-to-date with the changes of Spigot 1.14.4 (CraftMetaSkull#setProfile exists on Spigot 1.14.4, but not Paper 1.14.4 and 1.15.0), it does not make sense to put this behind inventory-access revisions. Instead, the SkullBuilder will now just check every time whether CraftMetaSkull#setProfile exists.
This commit is contained in:
NichtStudioCode 2023-10-12 16:02:35 +02:00
parent be09c8621c
commit 785854f4a8
20 changed files with 23 additions and 179 deletions

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r1; package xyz.xenondevs.inventoryaccess.r1;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools; import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.NBTTagCompound;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Field CRAFT_META_SKULL_GAME_PROFILE_FIELD = ReflectionUtils.getField(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "profile"
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.setFieldValue(CRAFT_META_SKULL_GAME_PROFILE_FIELD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r12; package xyz.xenondevs.inventoryaccess.r12;
import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtIo;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r13; package xyz.xenondevs.inventoryaccess.r13;
import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtIo;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -94,9 +94,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r15; package xyz.xenondevs.inventoryaccess.r15;
import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtIo;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r16; package xyz.xenondevs.inventoryaccess.r16;
import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtIo;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -94,9 +94,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r2; package xyz.xenondevs.inventoryaccess.r2;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools; import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.NBTTagCompound;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Field CRAFT_META_SKULL_GAME_PROFILE_FIELD = ReflectionUtils.getField(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "profile"
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.setFieldValue(CRAFT_META_SKULL_GAME_PROFILE_FIELD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.r3; package xyz.xenondevs.inventoryaccess.r3;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools; import net.minecraft.server.v1_14_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.NBTTagCompound;
@ -13,16 +12,11 @@ import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +88,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,10 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -94,9 +94,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -19,10 +19,6 @@ import java.util.stream.Collectors;
class ItemUtilsImpl implements ItemUtils { class ItemUtilsImpl implements ItemUtils {
private static final Method CRAFT_META_SKULL_SET_PROFILE_METHOD = ReflectionUtils.getMethod(
ReflectionRegistry.CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class
);
@Override @Override
public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) { public byte[] serializeItemStack(org.bukkit.inventory.@NotNull ItemStack itemStack, boolean compressed) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
@ -94,9 +90,4 @@ class ItemUtilsImpl implements ItemUtils {
); );
} }
@Override
public void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile) {
ReflectionUtils.invokeMethod(CRAFT_META_SKULL_SET_PROFILE_METHOD, itemMeta, gameProfile);
}
} }

@ -1,6 +1,5 @@
package xyz.xenondevs.inventoryaccess.abstraction.util; package xyz.xenondevs.inventoryaccess.abstraction.util;
import com.mojang.authlib.GameProfile;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -68,12 +67,4 @@ public interface ItemUtils {
*/ */
void setLore(@NotNull ItemMeta itemMeta, @NotNull List<@NotNull ComponentWrapper> lore); void setLore(@NotNull ItemMeta itemMeta, @NotNull List<@NotNull ComponentWrapper> lore);
/**
* Sets the game profile of a player skull, thereby changing its owner and texture.
*
* @param itemMeta The {@link ItemMeta} of the skull
* @param gameProfile The game profile to apply to the skull
*/
void setSkullGameProfile(@NotNull ItemMeta itemMeta, @NotNull GameProfile gameProfile);
} }

@ -1,5 +1,6 @@
package xyz.xenondevs.inventoryaccess.util; package xyz.xenondevs.inventoryaccess.util;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -19,11 +20,13 @@ public class ReflectionRegistry {
// Methods // Methods
public static final Method PAPER_PLUGIN_CLASS_LOADER_GET_LOADED_JAVA_PLUGIN_METHOD; public static final Method PAPER_PLUGIN_CLASS_LOADER_GET_LOADED_JAVA_PLUGIN_METHOD;
public static final Method CB_CRAFT_META_SKULL_SET_PROFILE_METHOD = getMethodOrNull(CB_CRAFT_META_SKULL_CLASS, true, "setProfile", GameProfile.class); // since spigot 1.14.4 or paper 1.15.1
// Fields // Fields
public static final Field PLUGIN_CLASS_LOADER_PLUGIN_FIELD = getField(PLUGIN_CLASS_LOADER_CLASS, true, "plugin"); 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_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"); public static final Field CB_CRAFT_META_ITEM_LORE_FIELD = getField(CB_CRAFT_META_ITEM_CLASS, true, "lore");
public static final Field CB_CRAFT_META_SKULL_PROFILE_FIELD = getField(CB_CRAFT_META_SKULL_CLASS, true, "profile");
static { static {
Method getPlugin = getMethodOrNull(PAPER_PLUGIN_CLASS_LOADER_CLASS, false, "getLoadedJavaPlugin"); Method getPlugin = getMethodOrNull(PAPER_PLUGIN_CLASS_LOADER_CLASS, false, "getLoadedJavaPlugin");

@ -14,7 +14,8 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.inventoryaccess.InventoryAccess; import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
import xyz.xenondevs.invui.util.MojangApiUtils; import xyz.xenondevs.invui.util.MojangApiUtils;
import java.io.Serializable; import java.io.Serializable;
@ -66,8 +67,13 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
ItemStack item = super.get(lang); ItemStack item = super.get(lang);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (gameProfile != null) if (gameProfile != null) {
InventoryAccess.getItemUtils().setSkullGameProfile(meta, gameProfile); if (ReflectionRegistry.CB_CRAFT_META_SKULL_SET_PROFILE_METHOD != null) {
ReflectionUtils.invokeMethod(ReflectionRegistry.CB_CRAFT_META_SKULL_SET_PROFILE_METHOD, meta, gameProfile);
} else {
ReflectionUtils.setFieldValue(ReflectionRegistry.CB_CRAFT_META_SKULL_PROFILE_FIELD, meta, gameProfile);
}
}
item.setItemMeta(meta); item.setItemMeta(meta);