2424
2525import  com .cryptomorin .xseries .profiles .gameprofile .MojangGameProfile ;
2626import  com .cryptomorin .xseries .profiles .gameprofile .XGameProfile ;
27+ import  com .cryptomorin .xseries .profiles .gameprofile .property .XProperty ;
2728import  com .cryptomorin .xseries .profiles .objects .transformer .ProfileTransformer ;
2829import  com .cryptomorin .xseries .reflection .XReflection ;
29- import  com .google .common .collect .ImmutableMultimap ;
30- import  com .google .common .collect .ListMultimap ;
31- import  com .google .common .collect .MultimapBuilder ;
3230import  com .google .gson .Gson ;
3331import  com .google .gson .GsonBuilder ;
3432import  com .google .gson .JsonObject ;
3836import  com .mojang .authlib .properties .PropertyMap ;
3937import  org .bukkit .Bukkit ;
4038import  org .jetbrains .annotations .ApiStatus ;
39+ import  org .jetbrains .annotations .Contract ;
4140import  org .jetbrains .annotations .NotNull ;
4241import  org .jetbrains .annotations .Nullable ;
4342
44- import  java .lang .reflect .Field ;
4543import  java .nio .charset .StandardCharsets ;
4644import  java .util .Base64 ;
4745import  java .util .Objects ;
@@ -63,7 +61,7 @@ public final class PlayerProfiles {
6361     * It's not needed to change it every time, but it should be changed 
6462     * if the XSeries internals are changed. 
6563     */ 
66-     private  static  final  Property  XSERIES_GAMEPROFILE_SIGNATURE  = new   Property (XSERIES_SIG , XReflection .XSERIES_VERSION );
64+     private  static  final  Property  XSERIES_GAMEPROFILE_SIGNATURE  = XProperty . create (XSERIES_SIG , XReflection .XSERIES_VERSION ). object ( );
6765    private  static  final  String  TEXTURES_PROPERTY  = "textures" ;
6866
6967    public  static  final  GameProfile  NIL  = createGameProfile (PlayerUUIDs .IDENTITY_UUID , XSERIES_SIG ).object ();
@@ -159,8 +157,7 @@ public static boolean hasTextures(MojangGameProfile profile) {
159157    public  static  MojangGameProfile  profileFromHashAndBase64 (String  hash , String  base64 ) {
160158        java .util .UUID  uuid  = java .util .UUID .nameUUIDFromBytes (hash .getBytes (StandardCharsets .UTF_8 ));
161159        MojangGameProfile  profile  = PlayerProfiles .createNamelessGameProfile (uuid );
162-         PlayerProfiles .setTexturesProperty (profile , base64 );
163-         return  profile ;
160+         return  PlayerProfiles .setTexturesProperty (profile , base64 );
164161    }
165162
166163    @ SuppressWarnings ("deprecation" )
@@ -180,7 +177,7 @@ public static void removeTimestamp(MojangGameProfile profile) {
180177     * Tries to unwrap a {@link GameProfile} from a {@link net.minecraft.world.item.component.ResolvableProfile}. 
181178     */ 
182179    @ Nullable 
183-     public  static  GameProfile  unwrapProfile (@ Nullable  Object  profile ) throws  Throwable  {
180+     public  static  GameProfile  fromResolvableProfile (@ Nullable  Object  profile ) throws  Throwable  {
184181        if  (profile  == null ) return  null ;
185182        if  (!(profile  instanceof  GameProfile ) && ProfilesCore .ResolvableProfile_gameProfile  != null ) {
186183            // Unwrap from ResolvableProfile 
@@ -190,7 +187,7 @@ public static GameProfile unwrapProfile(@Nullable Object profile) throws Throwab
190187    }
191188
192189    @ Nullable 
193-     public  static  Object  wrapProfile (@ Nullable  MojangGameProfile  profile ) throws  Throwable  {
190+     public  static  Object  toResolvableProfile (@ Nullable  MojangGameProfile  profile ) throws  Throwable  {
194191        if  (profile  == null ) return  null ;
195192        if  (ProfilesCore .ResolvableProfile$bukkitSupports ) {
196193            return  ProfilesCore .ResolvableProfile$constructor .invoke (profile .object ());
@@ -223,9 +220,9 @@ public static GameProfile sanitizeProfile(GameProfile gameProfile) {
223220        return  clone .object ();
224221    }
225222
226-     public   static   void   setTexturesProperty ( MojangGameProfile   profile ,  String   texture ) { 
227-          profile . removeProperty ( TEXTURES_PROPERTY ); 
228-         profile .addProperty ( TEXTURES_PROPERTY , texture );
223+     @ Contract ( pure  =  true ) 
224+     public   static   MojangGameProfile   setTexturesProperty ( MojangGameProfile  profile ,  String   texture ) { 
225+         return   profile .copy ( x  ->  x . setProperty ( TEXTURES_PROPERTY , texture ) );
229226    }
230227
231228    /** 
@@ -234,6 +231,7 @@ public static void setTexturesProperty(MojangGameProfile profile, String texture
234231     * @param str The string to encode. 
235232     * @return The Base64 encoded string. 
236233     */ 
234+     @ Contract (pure  = true )
237235    public  static  String  encodeBase64 (String  str ) {
238236        return  Base64 .getEncoder ().encodeToString (str .getBytes (StandardCharsets .UTF_8 ));
239237    }
@@ -245,6 +243,7 @@ public static String encodeBase64(String str) {
245243     * @return the decoded Base64 string if it is a valid Base64 string, or null if not. 
246244     */ 
247245    @ Nullable 
246+     @ Contract (pure  = true )
248247    public  static  String  decodeBase64 (String  base64 ) {
249248        Objects .requireNonNull (base64 , "Cannot decode null string" );
250249        try  {
@@ -255,10 +254,12 @@ public static String decodeBase64(String base64) {
255254        }
256255    }
257256
257+     @ Contract (pure  = true )
258258    public  static  MojangGameProfile  createGameProfile (UUID  uuid , String  username ) {
259259        return  signXSeries (XGameProfile .create (uuid , username ));
260260    }
261261
262+     @ Contract (pure  = true )
262263    public  static  MojangGameProfile  createGameProfile (UUID  uuid , String  username , PropertyMap  properties ) {
263264        return  signXSeries (XGameProfile .create (uuid , username , properties ));
264265    }
@@ -268,27 +269,15 @@ public static MojangGameProfile createGameProfile(UUID uuid, String username, Pr
268269     * purposes, specially since we're directly messing with the server's internal cache 
269270     * it should be there in case something goes wrong. 
270271     */ 
272+     @ Contract (pure  = true )
271273    public  static  MojangGameProfile  signXSeries (MojangGameProfile  profile ) {
272274        // Just as an indicator that this is not a vanilla-created profile. 
273-         PropertyMap  properties  = profile .properties ();
274275        // I don't think a single profile is being signed multiple times. 
275276        // Even if it was, it might be helpful? 
276-         // properties.asMap().remove(DEFAULT_PROFILE_NAME); // Remove previous versions if any. 
277-         try  {
278-             Field  props  = PropertyMap .class .getDeclaredField ("properties" );
279-             props .setAccessible (true );
280-             ListMultimap <String , Property > newProps  = MultimapBuilder .hashKeys ().arrayListValues ().build ();
281-             newProps .putAll (properties );
282-             newProps .put (XSERIES_SIG , XSERIES_GAMEPROFILE_SIGNATURE );
283-             props .set (properties , ImmutableMultimap .copyOf (newProps ));
284- 
285-             // properties.put(XSERIES_SIG, XSERIES_GAMEPROFILE_SIGNATURE); 
286-         } catch  (NoSuchFieldException  | IllegalAccessException  e ) {
287-             throw  new  RuntimeException (e );
288-         }
289-         return  profile ;
277+         return  profile .copy (x  -> x .setProperty (XSERIES_SIG , XSERIES_GAMEPROFILE_SIGNATURE ));
290278    }
291279
280+     @ Contract (pure  = true )
292281    public  static  MojangGameProfile  createNamelessGameProfile (UUID  id ) {
293282        return  createGameProfile (id , XSERIES_SIG );
294283    }
0 commit comments