Skip to content

Commit

Permalink
Require skull texture lookup on paper servers (SkriptLang#7152)
Browse files Browse the repository at this point in the history
* require skull texture lookup on paper servers

* 1.19.4+
  • Loading branch information
sovdeeth authored and Burbulinis committed Dec 3, 2024
1 parent ff3c850 commit 64ed155
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.util.slot.Slot;
import com.destroystokyo.paper.profile.PlayerProfile;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -49,6 +50,8 @@ public class ItemUtils {
// Introduced in Paper 1.21
public static final boolean HAS_RESET = Skript.methodExists(Damageable.class, "resetDamage");
public static final boolean CAN_CREATE_PLAYER_PROFILE = Skript.methodExists(Bukkit.class, "createPlayerProfile", UUID.class, String.class);
// paper does not do texture lookups by default
public static final boolean REQUIRES_TEXTURE_LOOKUP = Skript.classExists("com.destroystokyo.paper.profile.PlayerProfile") && Skript.isRunningMinecraft(1, 19, 4);

/**
* Gets damage/durability of an item, or 0 if it does not have damage.
Expand Down Expand Up @@ -165,7 +168,12 @@ public static void setHeadOwner(ItemType skull, OfflinePlayer player) {

SkullMeta skullMeta = (SkullMeta) meta;

if (player.getName() != null) {
if (REQUIRES_TEXTURE_LOOKUP) {
PlayerProfile profile = player.getPlayerProfile();
if (!profile.hasTextures())
profile.complete(true); // BLOCKING MOJANG API CALL
skullMeta.setPlayerProfile(profile);
} else if (player.getName() != null) {
skullMeta.setOwningPlayer(player);
} else if (CAN_CREATE_PLAYER_PROFILE) {
//noinspection deprecation
Expand Down

0 comments on commit 64ed155

Please sign in to comment.