This commit is contained in:
Ajneb97 2024-09-27 12:01:09 -03:00
parent 5572a0eed3
commit 76e89a4052
2 changed files with 49 additions and 27 deletions

View file

@ -93,36 +93,58 @@ public class ItemUtils {
} }
SkullMeta skullMeta = (SkullMeta) item.getItemMeta(); SkullMeta skullMeta = (SkullMeta) item.getItemMeta();
Field profileField; ServerVersion serverVersion = PlayerKits2.serverVersion;
try { if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R1)){
profileField = skullMeta.getClass().getDeclaredField("profile"); PlayerProfile profile = skullMeta.getOwnerProfile();
profileField.setAccessible(true); if(profile != null){
owner = profile.getName();
GameProfile gameProfile = (GameProfile) profileField.get(skullMeta); if(profile.getUniqueId() != null){
if(gameProfile != null && gameProfile.getProperties() != null) { id = profile.getUniqueId().toString();
PropertyMap propertyMap = gameProfile.getProperties();
owner = gameProfile.getName();
if(gameProfile.getId() != null) {
id = gameProfile.getId().toString();
} }
if(profile.getTextures() != null){
ServerVersion serverVersion = PlayerKits2.serverVersion; PlayerTextures textures = profile.getTextures();
for(Property p : propertyMap.values()) { if(textures != null){
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){ JsonObject skinJsonObject = new JsonObject();
String pName = (String)p.getClass().getMethod("name").invoke(p); skinJsonObject.addProperty("url", textures.getSkin().toString());
if(pName.equals("textures")){ JsonObject texturesJsonObject = new JsonObject();
texture = (String)p.getClass().getMethod("value").invoke(p); texturesJsonObject.add("SKIN", skinJsonObject);
} JsonObject minecraftTexturesJsonObject = new JsonObject();
}else{ minecraftTexturesJsonObject.add("textures", texturesJsonObject);
if(p.getName().equals("textures")) { texture = new String(Base64.getEncoder().encode(minecraftTexturesJsonObject.toString().getBytes()));
texture = p.getValue();
}
} }
} }
} }
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException }else{
| InvocationTargetException | NoSuchMethodException e) { Field profileField;
e.printStackTrace(); 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) { if(texture != null || id != null || owner != null) {

View file

@ -1,5 +1,5 @@
main: pk.ajneb97.PlayerKits2 main: pk.ajneb97.PlayerKits2
version: 1.12.4 version: 1.12.5
name: PlayerKits2 name: PlayerKits2
api-version: 1.13 api-version: 1.13
softdepend: [Vault,PlaceholderAPI] softdepend: [Vault,PlaceholderAPI]