Add the ability to use skulls from headDB

This commit is contained in:
zontreck 2025-04-09 20:23:00 -07:00
parent 58aaba2ae7
commit 80d7b7f56c

View file

@ -1,6 +1,9 @@
package dev.zontreck.ase.guis;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import org.bukkit.Bukkit;
@ -11,6 +14,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.profile.PlayerTextures;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import dev.zontreck.ase.AriasServerEssentials;
import net.kyori.adventure.text.Component;
@ -26,6 +34,8 @@ public class PrimitiveItem {
public boolean isGUIButton;
public boolean isSkull = false;
public String skullOwner = "";
public String skullURL = "";
public String skullNickname = "";
public List<PrimitiveAction> actions = new ArrayList<>();
public PrimitiveAction shiftClickAction = new PrimitiveAction(PrimitiveAction.NONE);
@ -67,10 +77,26 @@ public class PrimitiveItem {
true);
}
if (isSkull) {
if (isSkull && skullURL.isEmpty()) {
SkullMeta skullMeta = (SkullMeta) meta;
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(skullOwner));
meta = skullMeta;
} else if (isSkull && !skullURL.isEmpty()) {
if (skullNickname.length() > 16)
skullNickname = skullNickname.substring(0, 14);
skullNickname = skullNickname.trim();
PlayerProfile profile = Bukkit.createProfile(skullNickname);
PlayerTextures texts = profile.getTextures();
try {
texts.setSkin(URI.create(skullURL).toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
profile.setTextures(texts);
SkullMeta skullMeta = (SkullMeta) meta;
skullMeta.setPlayerProfile(profile);
meta = skullMeta;
}
item.setItemMeta(meta);
@ -99,4 +125,18 @@ public class PrimitiveItem {
itemType = Material.PLAYER_HEAD;
}
public void customSkull(String encodedTexture, String skullNickname) {
String base64Texture = new String(Base64.getDecoder().decode(encodedTexture));
JsonElement obj = JsonParser.parseString(base64Texture);
JsonElement textures = obj.getAsJsonObject().get("textures");
JsonElement skin = textures.getAsJsonObject().get("SKIN");
JsonElement url = skin.getAsJsonObject().get("url");
isSkull = true;
skullOwner = skullNickname; // Use a known good player name as the initial source.
itemType = Material.PLAYER_HEAD;
skullURL = url.getAsString();
this.skullNickname = skullNickname;
}
}