@@ -258,7 +258,7 @@ private void promptForSkinDownload() {
258258 try {
259259 var bytes = t .skin ().join ();
260260 var out = ensureNonexistent (SKINS_DIR .resolve (t .skinKey ()));
261- Skin .Local .writeMetadata (out , Map .of (Skin .Local .CLASSIC_METADATA_KEY , t .classicModel (), "name" , t .name (), "uuid" , t .id (), "download_time" , Instant .now ()));
261+ Skin .LocalSkin .writeMetadata (out , Map .of (Skin .LocalSkin .CLASSIC_METADATA_KEY , t .classicModel (), "name" , t .name (), "uuid" , t .id (), "download_time" , Instant .now ()));
262262 Files .write (out , bytes );
263263 client .execute (this ::loadSkinsList );
264264 Notifications .getInstance ().addStatus ("skins.notification.title" , "skins.notification.import.online.downloaded" , t .name ());
@@ -348,23 +348,23 @@ private void loadSkinsList() {
348348 var profile = cachedProfile ;
349349 int columns = Math .max (2 , (width / 2 - 25 ) / LIST_SKIN_WIDTH );
350350 List <Skin > skins = new ArrayList <>(profile .skins ());
351- var hashes = skins .stream ().map (Asset ::textureKey ).collect (Collectors .toSet ());
352- var defaultSkinHash = Auth . getInstance (). getSkinManager (). getDefaultSkinHash (account );
351+ var hashes = skins .stream ().map (Asset ::sha256 ).collect (Collectors .toSet ());
352+ var defaultSkin = Skin . getDefaultSkin (account );
353353 var local = new ArrayList <>(loadLocalSkins ());
354- var localHashes = local .stream ().collect (Collectors .toMap (Asset ::textureKey , Function .identity (), (skin , skin2 ) -> skin ));
354+ var localHashes = local .stream ().collect (Collectors .toMap (Asset ::sha256 , Function .identity (), (skin , skin2 ) -> skin ));
355355 local .removeIf (s -> !localHashes .containsValue (s ));
356356 skins .replaceAll (s -> {
357357 if (s instanceof MSApi .MCProfile .OnlineSkin online ) {
358- if (localHashes .containsKey (s .textureKey ()) && localHashes .get (s .textureKey ()) instanceof Skin .Local file ) {
359- local .remove (localHashes .remove (s .textureKey ()));
358+ if (localHashes .containsKey (s .sha256 ()) && localHashes .get (s .sha256 ()) instanceof Skin .LocalSkin file ) {
359+ local .remove (localHashes .remove (s .sha256 ()));
360360 return new Skin .Shared (file , online );
361361 }
362362 }
363363 return s ;
364364 });
365365 skins .addAll (local );
366- if (!hashes .contains (defaultSkinHash )) {
367- skins .add (null );
366+ if (!hashes .contains (defaultSkin . sha256 () )) {
367+ skins .add (defaultSkin );
368368 }
369369 populateSkinList (skins , columns );
370370 }
@@ -433,7 +433,7 @@ public void filesDragged(List<Path> packs) {
433433 var target = ensureNonexistent (SKINS_DIR .resolve (p .getFileName ()));
434434 var skin = Auth .getInstance ().getSkinManager ().read (p , false );
435435 if (skin != null ) {
436- Files .write (target , skin .image (). join () );
436+ Files .write (target , skin .image ());
437437 } else {
438438 AxolotlClientCommon .getInstance ().getLogger ().info ("Skipping dragged file {} because it does not seem to be a valid skin!" , p );
439439 Notifications .getInstance ().addStatus ("skins.notification.title" , "skins.notification.not_copied" , p .getFileName ());
@@ -620,31 +620,33 @@ public Entry(int height, SkinWidget widget, @Nullable Text label) {
620620 }, skin .classicVariant () ? slimSprite : wideSprite ));
621621 }
622622 if (asset != null ) {
623- if (asset . isLocal () ) {
623+ if (asset instanceof Asset . Local local ) {
624624 this .actionButtons .add (new SpriteButton (new TranslatableText ("skins.manage.delete" ), btn -> {
625625 btn .active = false ;
626626 client .openScreen (new ConfirmScreen (confirmed -> {
627- client .openScreen (SkinManagementScreen .this );
628627 if (confirmed ) {
629628 try {
630- Files .delete (asset .file ());
631- Skin .Local .deleteMetadata (asset .file ());
632- refreshCurrentList ();
629+ Files .delete (local .file ());
630+ Skin .LocalSkin .deleteMetadata (local .file ());
633631 } catch (IOException e ) {
634632 AxolotlClientCommon .getInstance ().getLogger ().warn ("Failed to delete: " , e );
635633 }
636634 }
635+ client .openScreen (SkinManagementScreen .this );
637636 btn .active = true ;
638637 }, new TranslatableText ("skins.manage.delete.confirm" ), (Text ) (asset .active () ?
639638 new TranslatableText ("skins.manage.delete.confirm.desc_active" ) :
640639 new TranslatableText ("skins.manage.delete.confirm.desc" )
641640 ).br$color (Colors .RED .toInt ())));
642641 }, new Identifier ("axolotlclient" , "textures/gui/sprites/delete.png" )));
643642 }
644- if (asset . supportsDownload () && !asset . isLocal ( )) {
643+ if (asset instanceof Asset . Online online && online . supportsDownload () && !( asset instanceof Asset . Local )) {
645644 this .actionButtons .add (new SpriteButton (new TranslatableText ("skins.manage.download" ), btn -> {
646645 btn .active = false ;
647- download (asset ).thenRun (() -> btn .active = true );
646+ download (asset ).thenRun (() -> {
647+ refreshCurrentList ();
648+ btn .active = true ;
649+ });
648650 }, new Identifier ("axolotlclient" , "textures/gui/sprites/download.png" )));
649651 }
650652 }
@@ -668,13 +670,17 @@ public void renderButton(MatrixStack guiGraphics, int mouseX, int mouseY, float
668670 btn .active = false ;
669671 Consumer <CompletableFuture <MSApi .MCProfile >> consumer = f -> f .thenAcceptAsync (p -> {
670672 cachedProfile = p ;
671- refreshCurrentList ();
673+ if (client .currentScreen == SkinManagementScreen .this ) {
674+ refreshCurrentList ();
675+ } else {
676+ client .openScreen (SkinManagementScreen .this );
677+ }
672678 }).exceptionally (t -> {
673679 AxolotlClientCommon .getInstance ().getLogger ().warn ("Failed to equip asset!" , t );
674680 equipping = false ;
675681 return null ;
676682 });
677- if (asset instanceof Skin && !current .getSkin (). isLocal ( )) {
683+ if (asset instanceof Skin && !( current .getSkin () instanceof Skin . Local )) {
678684 client .openScreen (new ConfirmScreen (confirmed -> {
679685 if (confirmed ) {
680686 consumer .accept (download (current .getSkin ()).thenCompose (a -> widget .equip ()));
@@ -691,18 +697,17 @@ public void renderButton(MatrixStack guiGraphics, int mouseX, int mouseY, float
691697 }
692698
693699 private @ NotNull CompletableFuture <?> download (Asset asset ) {
694- return asset . image (). thenAcceptAsync ( b -> {
700+ return CompletableFuture . runAsync (() -> {
695701 try {
696- var out = SKINS_DIR .resolve (asset .textureKey ());
702+ var out = SKINS_DIR .resolve (asset .sha256 ());
697703 Files .createDirectories (out .getParent ());
698- Files .write (out , b );
704+ Files .write (out , asset . image () );
699705 if (asset instanceof Skin skin ) {
700- Skin .Local .writeMetadata (out , Map .of (Skin .Local .CLASSIC_METADATA_KEY , skin .classicVariant ()));
706+ Skin .LocalSkin .writeMetadata (out , Map .of (Skin .LocalSkin .CLASSIC_METADATA_KEY , skin .classicVariant ()));
701707 }
702708 } catch (IOException e ) {
703709 AxolotlClientCommon .getInstance ().getLogger ().warn ("Failed to download: " , e );
704710 }
705- refreshCurrentList ();
706711 });
707712 }
708713
0 commit comments