Skip to content

Commit 7a6d654

Browse files
Start fixing TARDIS television GUIs
1 parent a0b2c68 commit 7a6d654

File tree

7 files changed

+97
-73
lines changed

7 files changed

+97
-73
lines changed

src/main/java/me/eccentric_nz/TARDIS/lazarus/TARDISTelevisionInventory.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.lazarus;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.custommodels.GUIChameleonPoliceBoxes;
2223
import me.eccentric_nz.TARDIS.custommodels.GUIChameleonPresets;
@@ -57,15 +58,16 @@ private ItemStack[] getItemStack() {
5758
if (PlayerHeadCache.DOCTORS.isEmpty()) {
5859
for (Skin doctor : DoctorSkins.DOCTORS) {
5960
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
60-
SkullMeta im = (SkullMeta) is.getItemMeta();
61-
PlayerProfile profile = SkinUtils.getHeadProfile(doctor);
62-
im.setPlayerProfile(profile);
63-
String[] name = doctor.name().split(" - ");
64-
im.displayName(Component.text(name[0]));
65-
im.lore(List.of(Component.text(name[1])));
66-
is.setItemMeta(im);
67-
// cache the item stack
68-
PlayerHeadCache.DOCTORS.add(is);
61+
ItemMeta im = is.getItemMeta();
62+
SkinUtils.getHeadProfile(doctor).thenAccept(playerProfile -> {
63+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
64+
String[] name = doctor.name().split(" - ");
65+
im.displayName(Component.text(name[0]));
66+
im.lore(List.of(Component.text(name[1])));
67+
is.setItemMeta(im);
68+
// cache the item stack
69+
PlayerHeadCache.DOCTORS.add(is);
70+
});
6971
stacks[i] = is;
7072
i++;
7173
}
@@ -80,12 +82,13 @@ private ItemStack[] getItemStack() {
8082
for (Skin companion : CompanionSkins.COMPANIONS) {
8183
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
8284
SkullMeta im = (SkullMeta) is.getItemMeta();
83-
PlayerProfile profile = SkinUtils.getHeadProfile(companion);
84-
im.setPlayerProfile(profile);
85-
im.displayName(Component.text(companion.name()));
86-
is.setItemMeta(im);
87-
// cache the item stack
88-
PlayerHeadCache.COMPANIONS.add(is);
85+
SkinUtils.getHeadProfile(companion).thenAccept(playerProfile -> {
86+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
87+
im.displayName(Component.text(companion.name()));
88+
is.setItemMeta(im);
89+
// cache the item stack
90+
PlayerHeadCache.COMPANIONS.add(is);
91+
});
8992
stacks[i] = is;
9093
i++;
9194
}
@@ -100,12 +103,13 @@ private ItemStack[] getItemStack() {
100103
for (Skin character : CharacterSkins.LAZARUS_CHARACTERS) {
101104
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
102105
SkullMeta im = (SkullMeta) is.getItemMeta();
103-
PlayerProfile profile = SkinUtils.getHeadProfile(character);
104-
im.setPlayerProfile(profile);
105-
im.displayName(Component.text(character.name()));
106-
is.setItemMeta(im);
107-
// cache the item stack
108-
PlayerHeadCache.LAZARUS_CHARACTERS.add(is);
106+
SkinUtils.getHeadProfile(character).thenAccept(playerProfile -> {
107+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
108+
im.displayName(Component.text(character.name()));
109+
is.setItemMeta(im);
110+
// cache the item stack
111+
PlayerHeadCache.LAZARUS_CHARACTERS.add(is);
112+
});
109113
stacks[i] = is;
110114
i++;
111115
}

src/main/java/me/eccentric_nz/TARDIS/skins/SkinUtils.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package me.eccentric_nz.TARDIS.skins;
1818

1919
import com.destroystokyo.paper.profile.PlayerProfile;
20+
import com.destroystokyo.paper.profile.ProfileProperty;
2021
import com.google.gson.Gson;
2122
import com.google.gson.JsonObject;
2223
import com.google.gson.JsonParser;
2324
import com.mojang.authlib.GameProfile;
2425
import com.mojang.authlib.properties.Property;
26+
import com.mojang.authlib.properties.PropertyMap;
27+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2528
import me.eccentric_nz.TARDIS.TARDIS;
2629
import me.eccentric_nz.TARDIS.custommodels.keys.CybermanVariant;
2730
import me.eccentric_nz.TARDIS.custommodels.keys.Features;
@@ -48,25 +51,30 @@
4851
import java.util.Base64;
4952
import java.util.HashMap;
5053
import java.util.UUID;
54+
import java.util.concurrent.CompletableFuture;
5155

5256
public class SkinUtils {
5357

5458
public static final HashMap<UUID, Skin> SKINNED = new HashMap<>();
5559
private static final UUID uuid = UUID.fromString("622bb234-0a3e-46d7-9e1d-ed1f03c76011");
5660

57-
public static PlayerProfile getHeadProfile(Skin skin) {
58-
GameProfile profile = new GameProfile(uuid, "TARDIS_Skin");
59-
profile.properties().removeAll("textures");
60-
profile.properties().put("textures", new Property("textures", skin.value(), skin.signature()));
61-
PlayerProfile playerProfile = new CraftPlayerProfile(profile);
62-
PlayerTextures textures = playerProfile.getTextures();
61+
public static CompletableFuture<PlayerProfile> getHeadProfile(Skin skin) {
62+
// GameProfile profile = new GameProfile(uuid, "TARDIS_Skin");
63+
ResolvableProfile profile = ResolvableProfile.resolvableProfile()
64+
.uuid(uuid)
65+
.addProperty(new ProfileProperty("textures", skin.value(), skin.signature()))
66+
.build();
67+
CompletableFuture<PlayerProfile> futureProfile = profile.resolve();
68+
return futureProfile.thenApply(playerProfile -> {
69+
PlayerTextures textures = playerProfile.getTextures();
6370
// PlayerTextures.SkinModel model = (skin.slim()) ? PlayerTextures.SkinModel.SLIM : PlayerTextures.SkinModel.CLASSIC;
64-
try {
65-
textures.setSkin(URI.create(skin.url()).toURL(), PlayerTextures.SkinModel.CLASSIC);
66-
} catch (MalformedURLException e) {
67-
TARDIS.plugin.debug("Bad URL: " + skin.url());
68-
}
69-
return playerProfile;
71+
try {
72+
textures.setSkin(URI.create(skin.url()).toURL(), PlayerTextures.SkinModel.CLASSIC);
73+
} catch (MalformedURLException e) {
74+
TARDIS.plugin.debug("Bad URL: " + skin.url());
75+
}
76+
return playerProfile;
77+
});
7078
}
7179

7280
public static boolean isAlexSkin(Player player) {
@@ -427,13 +435,15 @@ public static void removeExtras(Player player, Skin skin) {
427435
player.getInventory().setItem(EquipmentSlot.HEAD, null);
428436
player.getAttribute(Attribute.SCALE).setBaseValue(1.0d);
429437
}
430-
case "Mire", "Slitheen", "Rise of the Cyberman", "Cyber Lord", "Moonbase Cyberman", "Invasion Cyberman", "Melanie Bush" -> {
438+
case "Mire", "Slitheen", "Rise of the Cyberman", "Cyber Lord", "Moonbase Cyberman", "Invasion Cyberman",
439+
"Melanie Bush" -> {
431440
// head & both hands
432441
player.getInventory().setItem(EquipmentSlot.HEAD, null);
433442
player.getInventory().setItem(EquipmentSlot.HAND, null);
434443
player.getInventory().setItem(EquipmentSlot.OFF_HAND, null);
435444
}
436-
case "Ace", "Bannakaffalatta", "Brigadier Lethbridge-Stewart", "Black Cyberman", "Tenth Planet Cyberman", "Earthshock Cyberman", "Cybershade", "Dalek Sec", "Hath", "Ice Warrior",
445+
case "Ace", "Bannakaffalatta", "Brigadier Lethbridge-Stewart", "Black Cyberman", "Tenth Planet Cyberman",
446+
"Earthshock Cyberman", "Cybershade", "Dalek Sec", "Hath", "Ice Warrior",
437447
"Impossible Astronaut", "Jo Grant", "Judoon", "Martha Jones", "Omega", "Ood", "Racnoss", "Scarecrow",
438448
"Saturnynian", "Sea Devil", "Silence", "Silurian", "Sontaran", "Strax", "Sutekh", "Sycorax", "Tegan",
439449
"The Beast", "Vampire of Venice", "Weeping Angel", "Zygon", "Nimon", "Roamn Rory", "Heavenly Host" -> {

src/main/java/me/eccentric_nz/TARDIS/skins/tv/TVCharactersInventory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.skins.tv;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.skins.CharacterSkins;
2223
import me.eccentric_nz.TARDIS.skins.Skin;
@@ -47,12 +48,13 @@ private ItemStack[] getItemStack() {
4748
for (Skin character : CharacterSkins.CHARACTERS) {
4849
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
4950
SkullMeta im = (SkullMeta) is.getItemMeta();
50-
PlayerProfile profile = SkinUtils.getHeadProfile(character);
51-
im.setPlayerProfile(profile);
52-
im.displayName(Component.text(character.name()));
53-
is.setItemMeta(im);
54-
// cache the item stack
55-
PlayerHeadCache.CHARACTERS.add(is);
51+
SkinUtils.getHeadProfile(character).thenAccept(playerProfile -> {
52+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
53+
im.displayName(Component.text(character.name()));
54+
is.setItemMeta(im);
55+
// cache the item stack
56+
PlayerHeadCache.CHARACTERS.add(is);
57+
});
5658
stack[i] = is;
5759
i++;
5860
}

src/main/java/me/eccentric_nz/TARDIS/skins/tv/TVCompanionsInventory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.skins.tv;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.skins.CompanionSkins;
2223
import me.eccentric_nz.TARDIS.skins.Skin;
@@ -47,12 +48,13 @@ private ItemStack[] getItemStack() {
4748
for (Skin companion : CompanionSkins.COMPANIONS) {
4849
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
4950
SkullMeta im = (SkullMeta) is.getItemMeta();
50-
PlayerProfile profile = SkinUtils.getHeadProfile(companion);
51-
im.setPlayerProfile(profile);
52-
im.displayName(Component.text(companion.name()));
53-
is.setItemMeta(im);
54-
// cache the item stack
55-
PlayerHeadCache.COMPANIONS.add(is);
51+
SkinUtils.getHeadProfile(companion).thenAccept(playerProfile -> {
52+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
53+
im.displayName(Component.text(companion.name()));
54+
is.setItemMeta(im);
55+
// cache the item stack
56+
PlayerHeadCache.COMPANIONS.add(is);
57+
});
5658
stack[i] = is;
5759
i++;
5860
}

src/main/java/me/eccentric_nz/TARDIS/skins/tv/TVCyberInventory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.skins.tv;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.skins.CyberSkins;
2223
import me.eccentric_nz.TARDIS.skins.Skin;
@@ -46,12 +47,13 @@ private ItemStack[] getItemStack() {
4647
for (Skin variant : CyberSkins.VARIANTS) {
4748
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
4849
SkullMeta im = (SkullMeta) is.getItemMeta();
49-
PlayerProfile profile = SkinUtils.getHeadProfile(variant);
50-
im.setPlayerProfile(profile);
51-
im.displayName(Component.text(variant.name()));
52-
is.setItemMeta(im);
53-
// cache the item stack
54-
PlayerHeadCache.CYBERS.add(is);
50+
SkinUtils.getHeadProfile(variant).thenAccept(playerProfile -> {
51+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
52+
im.displayName(Component.text(variant.name()));
53+
is.setItemMeta(im);
54+
// cache the item stack
55+
PlayerHeadCache.CYBERS.add(is);
56+
});
5557
stack[i] = is;
5658
i++;
5759
}

src/main/java/me/eccentric_nz/TARDIS/skins/tv/TVDoctorsInventory.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.skins.tv;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.skins.DoctorSkins;
2223
import me.eccentric_nz.TARDIS.skins.Skin;
@@ -48,14 +49,15 @@ private ItemStack[] getItemStack() {
4849
for (Skin doctor : DoctorSkins.DOCTORS) {
4950
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
5051
SkullMeta im = (SkullMeta) is.getItemMeta();
51-
PlayerProfile profile = SkinUtils.getHeadProfile(doctor);
52-
im.setPlayerProfile(profile);
53-
String[] name = doctor.name().split(" - ");
54-
im.displayName(Component.text(name[0]));
55-
im.lore(List.of(Component.text(name[1])));
56-
is.setItemMeta(im);
57-
// cache the item stack
58-
PlayerHeadCache.DOCTORS.add(is);
52+
SkinUtils.getHeadProfile(doctor).thenAccept(playerProfile -> {
53+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
54+
String[] name = doctor.name().split(" - ");
55+
im.displayName(Component.text(name[0]));
56+
im.lore(List.of(Component.text(name[1])));
57+
is.setItemMeta(im);
58+
// cache the item stack
59+
PlayerHeadCache.DOCTORS.add(is);
60+
});
5961
stack[i] = is;
6062
i++;
6163
}

src/main/java/me/eccentric_nz/TARDIS/skins/tv/TVMonstersInventory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.skins.tv;
1818

19-
import com.destroystokyo.paper.profile.PlayerProfile;
19+
import io.papermc.paper.datacomponent.DataComponentTypes;
20+
import io.papermc.paper.datacomponent.item.ResolvableProfile;
2021
import me.eccentric_nz.TARDIS.TARDIS;
2122
import me.eccentric_nz.TARDIS.skins.MonsterSkins;
2223
import me.eccentric_nz.TARDIS.skins.Skin;
@@ -46,12 +47,13 @@ private ItemStack[] getItemStack() {
4647
for (Skin monster : MonsterSkins.MONSTERS) {
4748
ItemStack is = ItemStack.of(Material.PLAYER_HEAD, 1);
4849
SkullMeta im = (SkullMeta) is.getItemMeta();
49-
PlayerProfile profile = SkinUtils.getHeadProfile(monster);
50-
im.setPlayerProfile(profile);
51-
im.displayName(Component.text(monster.name()));
52-
is.setItemMeta(im);
53-
// cache the item stack
54-
PlayerHeadCache.MONSTERS.add(is);
50+
SkinUtils.getHeadProfile(monster).thenAccept(playerProfile -> {
51+
is.setData(DataComponentTypes.PROFILE, ResolvableProfile.resolvableProfile(playerProfile));
52+
im.displayName(Component.text(monster.name()));
53+
is.setItemMeta(im);
54+
// cache the item stack
55+
PlayerHeadCache.MONSTERS.add(is);
56+
});
5557
stack[i] = is;
5658
i++;
5759
}

0 commit comments

Comments
 (0)