Skip to content

Commit

Permalink
fix: skulls not working on offline mode servers
Browse files Browse the repository at this point in the history
XSkull tries to fetch the skin most of the time.
The core introduced a the SkullItemCreator class which
should make life easier for us
  • Loading branch information
SpraxDev committed Jul 19, 2024
1 parent 2ccdb41 commit 1f66573
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 81 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/craftaro/skyblock/gui/coop/GuiCoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.core.utils.TextUtils;
Expand All @@ -15,8 +16,6 @@
import com.craftaro.skyblock.playerdata.PlayerDataManager;
import com.craftaro.skyblock.sound.SoundManager;
import com.craftaro.skyblock.utils.player.OfflinePlayer;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -154,7 +153,14 @@ public void paint() {
targetPlayerTexture = new String[]{null, null};
}
}
ItemStack phead = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();

ItemStack phead;
if (targetPlayerTexture.length >= 1 && targetPlayerTexture[0] != null) {
phead = SkullItemCreator.byTextureValue(targetPlayerTexture[0]);
} else {
phead = SkullItemCreator.byUuid(uuid);
}

ItemMeta pheadmeta = phead.getItemMeta();
if (pheadmeta != null) {
pheadmeta.setDisplayName(TextUtils.formatText(this.languageLoad.getString("Menu.Coop.Item.Coop.Displayname")
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/craftaro/skyblock/gui/wip/GuiBans.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.core.utils.TextUtils;
Expand All @@ -10,8 +11,6 @@
import com.craftaro.skyblock.playerdata.PlayerDataManager;
import com.craftaro.skyblock.sound.SoundManager;
import com.craftaro.skyblock.utils.player.OfflinePlayer;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -118,7 +117,13 @@ public void paint() { // TODO Item to add ban
}
}

ItemStack is = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();
ItemStack is;
if (targetPlayerTexture.length >= 1 && targetPlayerTexture[0] != null) {
is = SkullItemCreator.byTextureValue(targetPlayerTexture[0]);
} else {
is = SkullItemCreator.byUuid(uuid);
}

ItemMeta im = is.getItemMeta();
if (im != null) {
im.setDisplayName(this.languageLoad.getString("Menu.Bans.Item.Ban.Displayname")
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/craftaro/skyblock/menus/Bans.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.menus;

import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.skyblock.SkyBlock;
Expand All @@ -14,9 +15,6 @@
import com.craftaro.skyblock.sound.SoundManager;
import com.craftaro.skyblock.utils.item.nInventoryUtil;
import com.craftaro.skyblock.utils.player.OfflinePlayer;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -166,13 +164,13 @@ public void open(Player player) {
int playerMenuPage = playerData.getPage(MenuType.BANS), nextEndIndex = islandBans.size() - playerMenuPage * 36;

if (playerMenuPage != 1) {
ItemStack Lhead = XSkull.createItem().profile(new Profileable.StringProfileable("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Lhead = SkullItemCreator.byTextureHash("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
nInv.addItem(nInv.createItem(Lhead,
configLoad.getString("Menu.Bans.Item.Previous.Displayname"), null, null, null, null), 1);
}

if (!(nextEndIndex == 0 || nextEndIndex < 0)) {
ItemStack Rhead = XSkull.createItem().profile(new Profileable.StringProfileable("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Rhead = SkullItemCreator.byTextureHash("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
nInv.addItem(nInv.createItem(Rhead,
configLoad.getString("Menu.Bans.Item.Next.Displayname"), null, null, null, null), 7);
}
Expand Down Expand Up @@ -209,7 +207,14 @@ public void open(Player player) {
targetPlayerTexture = new String[]{null, null};
}
}
ItemStack phead = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();

ItemStack phead;
if (targetPlayerTexture.length >= 1 && targetPlayerTexture[0] != null) {
phead = SkullItemCreator.byTextureValue(targetPlayerTexture[0]);
} else {
phead = SkullItemCreator.byUuid(targetPlayerUUID);
}

nInv.addItem(
nInv.createItem(phead,
plugin.formatText(
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/com/craftaro/skyblock/menus/Information.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.craftaro.skyblock.menus;

import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.skyblock.SkyBlock;
Expand All @@ -15,17 +16,13 @@
import com.craftaro.skyblock.utils.item.nInventoryUtil;
import com.craftaro.skyblock.utils.player.OfflinePlayer;
import com.craftaro.skyblock.visit.Visit;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -344,14 +341,14 @@ public void open(Player player) {
nextEndIndex = displayedMembers.size() - playerMenuPage * 36;

if (playerMenuPage != 1) {
ItemStack Lhead = XSkull.createItem().profile(new Profileable.StringProfileable("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Lhead = SkullItemCreator.byTextureHash("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
nInv.addItem(nInv.createItem(Lhead,
configLoad.getString("Menu.Information.Members.Item.Previous.Displayname"), null, null,
null, null), 1);
}

if (!(nextEndIndex == 0 || nextEndIndex < 0)) {
ItemStack Rhead = XSkull.createItem().profile(new Profileable.StringProfileable("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Rhead = SkullItemCreator.byTextureHash("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
nInv.addItem(nInv.createItem(Rhead,
configLoad.getString("Menu.Information.Members.Item.Next.Displayname"), null, null,
null, null), 7);
Expand Down Expand Up @@ -389,7 +386,14 @@ public void open(Player player) {
} else {
islandRole = configLoad.getString("Menu.Information.Members.Item.Member.Word.Owner");
}
ItemStack phead = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();

ItemStack phead;
if (playerTexture.length >= 1 && playerTexture[0] != null) {
phead = SkullItemCreator.byTextureValue(playerTexture[0]);
} else {
phead = SkullItemCreator.byUuid(playerUUID);
}

nInv.addItem(
nInv.createItem(phead,
configLoad.getString("Menu.Information.Members.Item.Member.Displayname")
Expand Down Expand Up @@ -485,14 +489,14 @@ public void open(Player player) {
nextEndIndex = displayedVisitors.size() - playerMenuPage * 36;

if (playerMenuPage != 1) {
ItemStack Lhead = XSkull.createItem().profile(new Profileable.StringProfileable("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Lhead = SkullItemCreator.byTextureHash("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
nInv.addItem(nInv.createItem(Lhead,
configLoad.getString("Menu.Information.Visitors.Item.Previous.Displayname"), null, null,
null, null), 1);
}

if (!(nextEndIndex == 0 || nextEndIndex < 0)) {
ItemStack Rhead = XSkull.createItem().profile(new Profileable.StringProfileable("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Rhead = SkullItemCreator.byTextureHash("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
nInv.addItem(nInv.createItem(Rhead,
configLoad.getString("Menu.Information.Visitors.Item.Next.Displayname"), null, null,
null, null), 7);
Expand Down Expand Up @@ -522,7 +526,15 @@ public void open(Player player) {
playerData = plugin.getPlayerDataManager().getPlayerData(targetPlayer.getUniqueId());
playerTexture = playerData.getTexture();
}
ItemStack phead = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();


ItemStack phead;
if (playerTexture.length >= 1 && playerTexture[0] != null) {
phead = SkullItemCreator.byTextureValue(playerTexture[0]);
} else {
phead = SkullItemCreator.byUuid(playerUUID);
}

nInv.addItem(
nInv.createItem(phead,
configLoad.getString("Menu.Information.Visitors.Item.Visitor.Displayname")
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/craftaro/skyblock/menus/Leaderboard.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.craftaro.skyblock.menus;

import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.skyblock.SkyBlock;
import com.craftaro.skyblock.placeholder.Placeholder;
import com.craftaro.skyblock.playerdata.PlayerDataManager;
Expand All @@ -10,9 +11,6 @@
import com.craftaro.skyblock.visit.Visit;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -289,7 +287,14 @@ public void open(Player player) {
}
}

ItemStack phead = XSkull.createItem().profile(new Profileable.OfflinePlayerProfileable(targetPlayer)).apply();

ItemStack phead;
if (playerTexture.length >= 1 && playerTexture[0] != null) {
phead = SkullItemCreator.byTextureValue(playerTexture[0]);
} else {
phead = SkullItemCreator.byUuid(visit.getOwnerUUID());
}

nInv.addItem(
nInv.createItem(phead,
configLoad.getString("Menu.Leaderboard.Leaderboard.Item.Island.Displayname")
Expand All @@ -312,7 +317,7 @@ public void open(Player player) {

for (int i = 0; i < itemSlots.length; i++) {
if (!nInv.getItems().containsKey(itemSlots[i])) {
ItemStack qhead = XSkull.createItem().profile(new Profileable.StringProfileable("d34e063cafb467a5c8de43ec78619399f369f4a52434da8017a983cdd92516a0", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack qhead = SkullItemCreator.byTextureHash("d34e063cafb467a5c8de43ec78619399f369f4a52434da8017a983cdd92516a0");
nInv.addItem(nInv.createItem(qhead,
configLoad.getString("Menu.Leaderboard.Leaderboard.Item.Empty.Displayname")
.replace("%position", "" + (i + 1)),
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/craftaro/skyblock/menus/Levelling.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.core.utils.ItemUtils;
Expand All @@ -22,9 +23,6 @@
import com.craftaro.skyblock.sound.SoundManager;
import com.craftaro.skyblock.utils.NumberUtil;
import com.craftaro.skyblock.utils.item.nInventoryUtil;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -34,7 +32,6 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -227,13 +224,13 @@ public void open(Player player) {
nInv.addItem(nInv.createItem(XMaterial.BLACK_STAINED_GLASS_PANE.parseItem(), configLoad.getString("Menu.Levelling.Item.Barrier.Displayname"), null, null, null, null), 9, 10, 11, 12, 13, 14, 15, 16, 17);

if (playerMenuPage != 1) {
ItemStack Lhead = XSkull.createItem().profile(new Profileable.StringProfileable("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Lhead = SkullItemCreator.byTextureHash("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
nInv.addItem(nInv.createItem(Lhead,
configLoad.getString("Menu.Levelling.Item.Previous.Displayname"), null, null, null, null), 1);
}

if (!(nextEndIndex == 0 || nextEndIndex < 0)) {
ItemStack Rhead = XSkull.createItem().profile(new Profileable.StringProfileable("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Rhead = SkullItemCreator.byTextureHash("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
nInv.addItem(nInv.createItem(Rhead,
configLoad.getString("Menu.Levelling.Item.Next.Displayname"), null, null, null, null), 7);
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/craftaro/skyblock/menus/Members.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.craftaro.skyblock.menus;

import com.craftaro.core.utils.SkullItemCreator;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
import com.craftaro.skyblock.SkyBlock;
Expand All @@ -16,9 +17,6 @@
import com.craftaro.skyblock.utils.StringUtil;
import com.craftaro.skyblock.utils.item.nInventoryUtil;
import com.craftaro.skyblock.utils.player.OfflinePlayer;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.builder.XSkull;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.craftaro.third_party.com.cryptomorin.xseries.profiles.objects.Profileable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -27,7 +25,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.io.File;
import java.text.ParseException;
Expand Down Expand Up @@ -354,13 +351,13 @@ public void open(Player player, Members.Type type, Members.Sort sort) {
9, 10, 11, 12, 13, 14, 15, 16, 17);

if (playerMenuPage != 1) {
ItemStack Lhead = XSkull.createItem().profile(new Profileable.StringProfileable("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Lhead = SkullItemCreator.byTextureHash("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
nInv.addItem(nInv.createItem(Lhead,
configLoad.getString("Menu.Members.Item.Previous.Displayname"), null, null, null, null), 1);
}

if (!(nextEndIndex == 0 || nextEndIndex < 0)) {
ItemStack Rhead = XSkull.createItem().profile(new Profileable.StringProfileable("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b", ProfileInputType.TEXTURE_HASH)).apply();
ItemStack Rhead = SkullItemCreator.byTextureHash("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
nInv.addItem(nInv.createItem(Rhead,
configLoad.getString("Menu.Members.Item.Next.Displayname"), null, null, null, null), 7);
}
Expand Down Expand Up @@ -563,7 +560,7 @@ public void open(Player player, Members.Type type, Members.Sort sort) {
}
}

ItemStack phead = XSkull.createItem().profile(new Profileable.UsernameProfileable(playerName)).apply();
ItemStack phead = SkullItemCreator.byUsername(playerName);
nInv.addItem(
nInv.createItem(phead,
configLoad.getString("Menu.Members.Item.Member.Displayname").replace("%player",
Expand Down
Loading

0 comments on commit 1f66573

Please sign in to comment.