diff --git a/src/main/java/net/knarcraft/knargui/item/PlayerHeadGUIItemFactory.java b/src/main/java/net/knarcraft/knargui/item/PlayerHeadGUIItemFactory.java
index 7611151..116f23f 100644
--- a/src/main/java/net/knarcraft/knargui/item/PlayerHeadGUIItemFactory.java
+++ b/src/main/java/net/knarcraft/knargui/item/PlayerHeadGUIItemFactory.java
@@ -7,7 +7,12 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Base64;
import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* An item factory for generating player head-based icons
@@ -15,6 +20,9 @@ import java.util.UUID;
@SuppressWarnings("unused")
public class PlayerHeadGUIItemFactory extends AbstractGUIItemFactory
The id of the texture to use
+ * @returnThe factory. Used for chaining commands
+ */ + public PlayerHeadGUIItemFactory useSkin(String textureId) { + //Get the texture id from a Base64 encoded JSON string + if (!textureId.isBlank() && textureId.length() % 4 == 0) { + String decoded = new String(Base64.getDecoder().decode(textureId)); + Matcher matcher = texturePattern.matcher(decoded); + if (matcher.find()) { + textureId = matcher.group(1); + } + } + + try { + return useSkin(new URL(textureBaseURL + textureId)); + } catch (MalformedURLException exception) { + throw new IllegalArgumentException("Texture id resulted in invalid URL"); + } + } + + /** + * Uses the head skin from the given URL + * + * @param urlThe URL to use
+ * @returnThe factory. Used for chaining commands
+ */ + public PlayerHeadGUIItemFactory useSkin(URL url) { + PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID()); + profile.getTextures().setSkin(url); + return changeItemMeta(SkullMeta.class, (meta) -> meta.setOwnerProfile(profile)); + } + }