Skip to content

Commit 40d8442

Browse files
author
TheProgramSrc
committed
Changelog:
* Working on SimpleItem code improvements
1 parent 7f99ea9 commit 40d8442

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>4.1.2-BETA_2</version>
9+
<version>4.1.2-BETA_3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/items/SimpleItem.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,16 @@ public SimpleItem setOwningPlayer(OfflinePlayer offlinePlayer){
200200
* @return this SimpleItem
201201
*/
202202
public SimpleItem setSkin(SkinTexture skinTexture){
203+
if(skinTexture == null)
204+
return this;
205+
if(skinTexture.getUrl() == null || skinTexture.getUrl().equals("null"))
206+
return this;
207+
if(!(this.item.getItemMeta() instanceof SkullMeta))
208+
return this;
203209
SkullMeta meta = ((SkullMeta)this.item.getItemMeta());
204210
if(meta != null){
205-
GameProfile gameProfile = new GameProfile(UUID.nameUUIDFromBytes("Steve".getBytes()), "");
206-
byte[] skinBytes = Base64.encodeBase64(("{textures:{SKIN:{url:\"" + skinTexture.getUrl() + "\"}}}").getBytes());
211+
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
212+
byte[] skinBytes = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", skinTexture.getUrl()).getBytes());
207213
gameProfile.getProperties().put("textures", new Property("textures", new String(skinBytes)));
208214

209215
try {
@@ -226,22 +232,7 @@ public SimpleItem setSkin(SkinTexture skinTexture){
226232
* @return this SimpleItem
227233
*/
228234
public SimpleItem setSkin(String textureURL){
229-
SkullMeta meta = ((SkullMeta)this.item.getItemMeta());
230-
if(meta != null){
231-
GameProfile gameProfile = new GameProfile(UUID.nameUUIDFromBytes("Steve".getBytes()), "");
232-
byte[] skinBytes = Base64.encodeBase64(("{textures:{SKIN:{url:\"" + textureURL + "\"}}}").getBytes());
233-
gameProfile.getProperties().put("textures", new Property("textures", new String(skinBytes)));
234-
235-
try {
236-
Field profile = meta.getClass().getDeclaredField("profile");
237-
profile.setAccessible(true);
238-
profile.set(meta, gameProfile);
239-
}catch (IllegalAccessException | NoSuchFieldException e) {
240-
e.printStackTrace();
241-
}
242-
this.item.setItemMeta(meta);
243-
}
244-
return this;
235+
return setSkin(SpigotPlugin.i.getSkinManager().getSkin(textureURL));
245236
}
246237

247238
/**

0 commit comments

Comments
 (0)