44import com .destroystokyo .paper .profile .ProfileProperty ;
55import com .mojang .authlib .GameProfile ;
66import com .mojang .authlib .properties .Property ;
7+ import io .github .bakedlibs .dough .reflection .ReflectionUtils ;
78import org .bukkit .Bukkit ;
89import org .bukkit .block .Block ;
910import org .bukkit .block .BlockState ;
1011import org .bukkit .block .Skull ;
1112
1213import javax .annotation .ParametersAreNonnullByDefault ;
14+ import java .lang .reflect .InvocationTargetException ;
15+ import java .lang .reflect .Method ;
1316
1417public class PlayerHeadAdapterPaper implements PlayerHeadAdapter {
1518
1619 @ Override
1720 @ ParametersAreNonnullByDefault
18- public void setGameProfile (Block block , GameProfile profile , boolean sendBlockUpdate ) {
21+ public void setGameProfile (Block block , GameProfile profile , boolean sendBlockUpdate ) throws InvocationTargetException , IllegalAccessException {
1922 BlockState state = block .getState ();
2023 if (!(state instanceof Skull )) return ;
2124
@@ -24,7 +27,17 @@ public void setGameProfile(Block block, GameProfile profile, boolean sendBlockUp
2427 Property property = profile .getProperties ().get ("textures" ).iterator ().next ();
2528
2629 PlayerProfile paperPlayerProfile = Bukkit .createProfile (profile .getId (), profile .getName ());
27- paperPlayerProfile .setProperty (new ProfileProperty (property .name (), property .value (), property .signature ()));
30+
31+ Method getName = ReflectionUtils .getMethod (Property .class , "getName" );
32+ Method getValue = ReflectionUtils .getMethod (Property .class , "getValue" );
33+ Method getSignature = ReflectionUtils .getMethod (Property .class , "getSignature" );
34+
35+ // Old authlib check
36+ if (getName != null && getValue != null && getSignature != null ) {
37+ paperPlayerProfile .setProperty (new ProfileProperty ((String ) getName .invoke (property ), (String ) getValue .invoke (property ), (String ) getSignature .invoke (property )));
38+ } else {
39+ paperPlayerProfile .setProperty (new ProfileProperty (property .name (), property .value (), property .signature ()));
40+ }
2841
2942 skull .setPlayerProfile (paperPlayerProfile );
3043
0 commit comments