Skip to content

Commit

Permalink
Fix skull texture on newer spigot builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Sep 11, 2024
1 parent 18a0e41 commit 540b4e1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ subprojects {
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
compileOnly 'it.unimi.dsi:fastutil:8.5.12'
compileOnly('com.mojang:datafixerupper:4.1.27') { transitive = false }

Expand Down
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.6
version=1.5.7-SNAPSHOT
2 changes: 1 addition & 1 deletion rtag-block/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
}
2 changes: 1 addition & 1 deletion rtag-entity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
}
2 changes: 1 addition & 1 deletion rtag-item/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repositories {
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
compileOnly 'com.mojang:authlib:1.5.26' // 3.11.50
compileOnly('com.mojang:datafixerupper:4.1.27') { transitive = false }
}
23 changes: 20 additions & 3 deletions rtag-item/src/main/java/com/saicone/rtag/util/SkullTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,42 @@ public class SkullTexture {

private static final ItemStack PLAYER_HEAD;

private static final MethodHandle newResolvableProfile;
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();

static {
if (ServerInstance.MAJOR_VERSION >= 13) {
if (ServerInstance.Release.FLAT) {
PLAYER_HEAD = new ItemStack(Material.PLAYER_HEAD);
} else {
PLAYER_HEAD = new ItemStack(Material.getMaterial("SKULL_ITEM"), 1, (short) 3);
}
MethodHandle new$ResolvableProfile = null;
MethodHandle get$profile = null;
MethodHandle set$profile = null;
MethodHandle get$value = null;
try {
EasyLookup.addOBCClass("entity.CraftPlayer");
EasyLookup.addOBCClass("inventory.CraftMetaSkull");
if (ServerInstance.Release.COMPONENT) {
EasyLookup.addNMSClass("world.item.component.ResolvableProfile");
}

get$profile = EasyLookup.method("CraftPlayer", "getProfile", GameProfile.class);
// Unreflect reason:
// Private method/field
if (ServerInstance.MAJOR_VERSION >= 15) {
set$profile = EasyLookup.unreflectMethod("CraftMetaSkull", "setProfile", GameProfile.class);
for (Method method : EasyLookup.classOf("CraftMetaSkull").getDeclaredMethods()) {
if (method.getName().equals("setProfile") && method.getParameters().length == 1) {
if (method.getParameters()[0].getType().getSimpleName().equals("ResolvableProfile")) {
new$ResolvableProfile = EasyLookup.constructor("ResolvableProfile", GameProfile.class);
}
set$profile = EasyLookup.unreflectMethod(method);
}
}
} else {
set$profile = EasyLookup.unreflectSetter("CraftMetaSkull", "profile");
}
Expand All @@ -88,6 +100,7 @@ public class SkullTexture {
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
newResolvableProfile = new$ResolvableProfile;
getProfile = get$profile;
setProfile = set$profile;
getValue = get$value;
Expand Down Expand Up @@ -140,7 +153,11 @@ public static ItemStack setTexture(ItemStack head, String texture) throws Illega
throw new IllegalArgumentException("The provided item isn't a player head");
}
try {
setProfile.invoke(meta, profile);
if (newResolvableProfile != null) {
setProfile.invoke(meta, newResolvableProfile.invoke(profile));
} else {
setProfile.invoke(meta, profile);
}
} catch (Throwable t) {
t.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion rtag-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation project(':rtag-entity')
implementation project(':rtag-item')

compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
}

jar.dependsOn (shadowJar)
Expand Down

0 comments on commit 540b4e1

Please sign in to comment.