Skip to content

Commit 5140054

Browse files
Merge pull request #1 from GuizhanCraft/update/1.20.6
fix: use old getter of property for older versions
2 parents 9826839 + b1676fc commit 5140054

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

dough-skins/src/main/java/io/github/bakedlibs/dough/skins/nms/PlayerHeadAdapterPaper.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
import com.destroystokyo.paper.profile.ProfileProperty;
55
import com.mojang.authlib.GameProfile;
66
import com.mojang.authlib.properties.Property;
7+
import io.github.bakedlibs.dough.reflection.ReflectionUtils;
78
import org.bukkit.Bukkit;
89
import org.bukkit.block.Block;
910
import org.bukkit.block.BlockState;
1011
import org.bukkit.block.Skull;
1112

1213
import javax.annotation.ParametersAreNonnullByDefault;
14+
import java.lang.reflect.InvocationTargetException;
15+
import java.lang.reflect.Method;
1316

1417
public 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

Comments
 (0)