11package me .cael .capes .mixins ;
22
3- import com .google .gson .JsonElement ;
4- import com .google .gson .JsonParser ;
5- import com .google .gson .JsonSyntaxException ;
63import com .mojang .authlib .GameProfile ;
7- import com .mojang .authlib .properties .Property ;
84import me .cael .capes .CapeConfig ;
95import me .cael .capes .Capes ;
106import me .cael .capes .handler .PlayerHandler ;
7+ import me .cael .capes .util .UtilsKt ;
118import net .minecraft .client .network .PlayerListEntry ;
129import net .minecraft .client .util .SkinTextures ;
1310import net .minecraft .util .Identifier ;
1411import org .spongepowered .asm .mixin .Final ;
1512import org .spongepowered .asm .mixin .Mixin ;
1613import org .spongepowered .asm .mixin .Shadow ;
17- import org .spongepowered .asm .mixin .Unique ;
1814import org .spongepowered .asm .mixin .injection .At ;
1915import org .spongepowered .asm .mixin .injection .Inject ;
2016import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
2117
22- import java .nio .charset .StandardCharsets ;
23- import java .util .Base64 ;
24- import java .util .Optional ;
2518import java .util .function .Supplier ;
2619
2720@ Mixin (PlayerListEntry .class )
@@ -30,14 +23,14 @@ public abstract class MixinPlayerListEntry {
3023
3124 @ Inject (method = "texturesSupplier" , at = @ At ("HEAD" ))
3225 private static void loadTextures (GameProfile profile , CallbackInfoReturnable <Supplier <SkinTextures >> cir ) {
33- if (capes$ isValidProfile (profile )) {
26+ if (UtilsKt . isValidProfile (profile )) {
3427 PlayerHandler .Companion .onLoadTexture (profile );
3528 }
3629 }
3730
3831 @ Inject (method = "getSkinTextures" , at = @ At ("TAIL" ), cancellable = true )
3932 private void getCapeTexture (CallbackInfoReturnable <SkinTextures > cir ) {
40- if (!capes$ isValidProfile (profile )) return ;
33+ if (!UtilsKt . isValidProfile (profile )) return ;
4134 PlayerHandler handler = PlayerHandler .Companion .fromProfile (profile );
4235 if (handler .getHasCape ()) {
4336 CapeConfig config = Capes .INSTANCE .getCONFIG ();
@@ -52,25 +45,4 @@ private void getCapeTexture(CallbackInfoReturnable<SkinTextures> cir) {
5245 }
5346 }
5447
55- @ Unique
56- private static boolean capes$isValidProfile (GameProfile profile ) {
57- Optional <Property > property = profile .getProperties ().get ("textures" ).stream ().findFirst ();
58- if (property .isEmpty ()) return false ;
59-
60- String textures = property .get ().value ();
61- String json = new String (Base64 .getDecoder ().decode (textures ), StandardCharsets .UTF_8 );
62- JsonElement root ;
63- try {
64- root = JsonParser .parseString (json );
65- } catch (JsonSyntaxException e ) {
66- return false ;
67- }
68- if (!root .isJsonObject ()) return false ;
69- JsonElement element = root .getAsJsonObject ().get ("profileName" );
70- if (element == null || element .isJsonNull ()) return false ;
71-
72- String profileName = element .getAsString ();
73- return profile .getId ().version () == 4 || (profile .getId ().version () == 2 && profile .getName ().equals (profileName ));
74- }
75-
7648}
0 commit comments