Skip to content

Commit

Permalink
Fix skull texture
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed May 30, 2024
1 parent 806c2a4 commit d96ec37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=com.saicone.rtag
version=1.5.3
version=1.5.4-SNAPSHOT
20 changes: 19 additions & 1 deletion rtag-item/src/main/java/com/saicone/rtag/util/SkullTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.InputStream;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Base64;
import java.util.UUID;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class SkullTexture {

private static final MethodHandle getProfile;
private static final MethodHandle setProfile;
private static final MethodHandle getValue;

private static final Cache<String, String> TEXTURE_CACHE = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.HOURS).build();

Expand All @@ -60,6 +62,7 @@ public class SkullTexture {
}
MethodHandle get$profile = null;
MethodHandle set$profile = null;
MethodHandle get$value = null;
try {
EasyLookup.addOBCClass("entity.CraftPlayer");
EasyLookup.addOBCClass("inventory.CraftMetaSkull");
Expand All @@ -72,11 +75,22 @@ public class SkullTexture {
} else {
set$profile = EasyLookup.unreflectSetter("CraftMetaSkull", "profile");
}

String value = "value";
for (Method method : Property.class.getDeclaredMethods()) {
if (method.getName().equals("getValue")) {
// Old name found
value = "getValue";
break;
}
}
get$value = EasyLookup.method(Property.class, value, String.class);
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
getProfile = get$profile;
setProfile = set$profile;
getValue = get$value;
}

SkullTexture() {
Expand Down Expand Up @@ -182,7 +196,11 @@ private static String getPlayerTexture(String key, String name, UUID uuid, Consu
GameProfile profile = ((GameProfile) getProfile.invoke(player));
for (Property texture : profile.getProperties().get("textures")) {
if (texture != null) {
return texture.getValue();
try {
return (String) getValue.invoke(texture);
} catch (Throwable t) {
throw new RuntimeException("Cannot get texture value from Property object");
}
}
}
} catch (Throwable t) {
Expand Down

0 comments on commit d96ec37

Please sign in to comment.