|
| 1 | +package net.coreprotect.paper; |
| 2 | + |
| 3 | +import java.util.UUID; |
| 4 | + |
| 5 | +import org.bukkit.block.Skull; |
| 6 | + |
| 7 | +import com.destroystokyo.paper.profile.ProfileProperty; |
| 8 | + |
| 9 | +import io.papermc.paper.datacomponent.item.ResolvableProfile; |
| 10 | +import net.coreprotect.config.Config; |
| 11 | +import net.coreprotect.utility.ErrorReporter; |
| 12 | + |
| 13 | +public class Paper_26_0 extends Paper_v1_20 { |
| 14 | + |
| 15 | + @Override |
| 16 | + public String getSkullOwner(Skull skull) { |
| 17 | + ResolvableProfile profile = skull.getProfile(); |
| 18 | + if (profile == null) { |
| 19 | + return null; |
| 20 | + } |
| 21 | + |
| 22 | + UUID uuid = profile.uuid(); |
| 23 | + if (uuid != null) { |
| 24 | + return uuid.toString(); |
| 25 | + } |
| 26 | + |
| 27 | + String owner = profile.name(); |
| 28 | + if (Config.getGlobal().MYSQL && owner != null && owner.length() > 255) { |
| 29 | + return owner.substring(0, 255); |
| 30 | + } |
| 31 | + |
| 32 | + return owner; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void setSkullOwner(Skull skull, String owner) { |
| 37 | + if (owner == null || owner.length() == 0) { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + ResolvableProfile.Builder builder = copyProfile(skull.getProfile(), true); |
| 42 | + if (owner.length() >= 32 && owner.contains("-")) { |
| 43 | + builder.uuid(UUID.fromString(owner)); |
| 44 | + } |
| 45 | + else if (owner.length() <= 16) { |
| 46 | + builder.name(owner); |
| 47 | + } |
| 48 | + else { |
| 49 | + super.setSkullOwner(skull, owner); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + skull.setProfile(builder.build()); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public String getSkullSkin(Skull skull) { |
| 58 | + ResolvableProfile profile = skull.getProfile(); |
| 59 | + if (profile != null) { |
| 60 | + for (ProfileProperty property : profile.properties()) { |
| 61 | + String skin = SkullSkin.getStorageValue(property); |
| 62 | + if (skin != null) { |
| 63 | + return skin; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + return super.getSkullSkin(skull); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void setSkullSkin(Skull skull, String skin) { |
| 73 | + try { |
| 74 | + if (skin == null || skin.length() == 0) { |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + ProfileProperty property = SkullSkin.getTexturesProperty(skin); |
| 79 | + if (property == null) { |
| 80 | + String skinUrl = SkullSkin.getSkinUrl(skin); |
| 81 | + if (skinUrl == null) { |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + property = new ProfileProperty("textures", SkullSkin.getTexturesPropertyValue(skinUrl)); |
| 86 | + } |
| 87 | + |
| 88 | + ResolvableProfile.Builder builder = copyProfile(skull.getProfile(), false); |
| 89 | + builder.addProperty(property); |
| 90 | + skull.setProfile(builder.build()); |
| 91 | + } |
| 92 | + catch (Exception e) { |
| 93 | + ErrorReporter.report(e); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + private ResolvableProfile.Builder copyProfile(ResolvableProfile profile, boolean includeSkin) { |
| 98 | + ResolvableProfile.Builder builder = ResolvableProfile.resolvableProfile(); |
| 99 | + if (profile == null) { |
| 100 | + return builder; |
| 101 | + } |
| 102 | + |
| 103 | + if (profile.uuid() != null) { |
| 104 | + builder.uuid(profile.uuid()); |
| 105 | + } |
| 106 | + if (profile.name() != null) { |
| 107 | + builder.name(profile.name()); |
| 108 | + } |
| 109 | + if (profile.skinPatch() != null) { |
| 110 | + builder.skinPatch(profile.skinPatch()); |
| 111 | + } |
| 112 | + |
| 113 | + for (ProfileProperty property : profile.properties()) { |
| 114 | + if (includeSkin || !SkullSkin.isTexturesProperty(property)) { |
| 115 | + builder.addProperty(property); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + return builder; |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments