diff --git a/src/main/java/pk/ajneb97/utils/ItemUtils.java b/src/main/java/pk/ajneb97/utils/ItemUtils.java index 934f623..505e51c 100644 --- a/src/main/java/pk/ajneb97/utils/ItemUtils.java +++ b/src/main/java/pk/ajneb97/utils/ItemUtils.java @@ -93,36 +93,58 @@ public class ItemUtils { } SkullMeta skullMeta = (SkullMeta) item.getItemMeta(); - Field profileField; - try { - profileField = skullMeta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - - GameProfile gameProfile = (GameProfile) profileField.get(skullMeta); - if(gameProfile != null && gameProfile.getProperties() != null) { - PropertyMap propertyMap = gameProfile.getProperties(); - owner = gameProfile.getName(); - if(gameProfile.getId() != null) { - id = gameProfile.getId().toString(); + ServerVersion serverVersion = PlayerKits2.serverVersion; + if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R1)){ + PlayerProfile profile = skullMeta.getOwnerProfile(); + if(profile != null){ + owner = profile.getName(); + if(profile.getUniqueId() != null){ + id = profile.getUniqueId().toString(); } - - ServerVersion serverVersion = PlayerKits2.serverVersion; - for(Property p : propertyMap.values()) { - if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){ - String pName = (String)p.getClass().getMethod("name").invoke(p); - if(pName.equals("textures")){ - texture = (String)p.getClass().getMethod("value").invoke(p); - } - }else{ - if(p.getName().equals("textures")) { - texture = p.getValue(); - } + if(profile.getTextures() != null){ + PlayerTextures textures = profile.getTextures(); + if(textures != null){ + JsonObject skinJsonObject = new JsonObject(); + skinJsonObject.addProperty("url", textures.getSkin().toString()); + JsonObject texturesJsonObject = new JsonObject(); + texturesJsonObject.add("SKIN", skinJsonObject); + JsonObject minecraftTexturesJsonObject = new JsonObject(); + minecraftTexturesJsonObject.add("textures", texturesJsonObject); + texture = new String(Base64.getEncoder().encode(minecraftTexturesJsonObject.toString().getBytes())); } } } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException - | InvocationTargetException | NoSuchMethodException e) { - e.printStackTrace(); + }else{ + Field profileField; + try { + profileField = skullMeta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + + GameProfile gameProfile = (GameProfile) profileField.get(skullMeta); + if(gameProfile != null && gameProfile.getProperties() != null) { + PropertyMap propertyMap = gameProfile.getProperties(); + owner = gameProfile.getName(); + if(gameProfile.getId() != null) { + id = gameProfile.getId().toString(); + } + + for(Property p : propertyMap.values()) { + if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){ + String pName = (String)p.getClass().getMethod("name").invoke(p); + if(pName.equals("textures")){ + texture = (String)p.getClass().getMethod("value").invoke(p); + } + }else{ + if(p.getName().equals("textures")) { + texture = p.getValue(); + } + } + } + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException + | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } } if(texture != null || id != null || owner != null) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 639ab0f..4132321 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ main: pk.ajneb97.PlayerKits2 -version: 1.12.4 +version: 1.12.5 name: PlayerKits2 api-version: 1.13 softdepend: [Vault,PlaceholderAPI]