Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.94 KB | None | 0 0
  1. package net.minecraft.client.resources;
  2.  
  3. import com.google.common.cache.CacheBuilder;
  4. import com.google.common.cache.CacheLoader;
  5. import com.google.common.cache.LoadingCache;
  6. import com.google.common.collect.Maps;
  7. import com.mojang.authlib.GameProfile;
  8. import com.mojang.authlib.minecraft.InsecureTextureException;
  9. import com.mojang.authlib.minecraft.MinecraftProfileTexture;
  10. import com.mojang.authlib.minecraft.MinecraftSessionService;
  11. import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
  12. import java.awt.image.BufferedImage;
  13. import java.io.File;
  14. import java.net.URI;
  15. import java.net.URISyntaxException;
  16. import java.net.URL;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import java.util.concurrent.ExecutorService;
  20. import java.util.concurrent.LinkedBlockingQueue;
  21. import java.util.concurrent.ThreadPoolExecutor;
  22. import java.util.concurrent.TimeUnit;
  23. import net.minecraft.client.Minecraft;
  24. import net.minecraft.client.renderer.IImageBuffer;
  25. import net.minecraft.client.renderer.ImageBufferDownload;
  26. import net.minecraft.client.renderer.ThreadDownloadImageData;
  27. import net.minecraft.client.renderer.texture.ITextureObject;
  28. import net.minecraft.client.renderer.texture.TextureManager;
  29. import net.minecraft.ryc.RYCApi;
  30. import net.minecraft.ryc.response.UserResponse;
  31. import net.minecraft.util.ResourceLocation;
  32.  
  33. import javax.imageio.ImageIO;
  34.  
  35. public class SkinManager
  36. {
  37.     public static final ResourceLocation field_152793_a = new ResourceLocation("textures/entity/steve.png");
  38.     private static final ExecutorService field_152794_b = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
  39.     private final TextureManager field_152795_c;
  40.     private final File field_152796_d;
  41.     private final MinecraftSessionService field_152797_e;
  42.     private final LoadingCache field_152798_f;
  43.     private static final String __OBFID = "CL_00001830";
  44.  
  45.     public SkinManager(TextureManager p_i1044_1_, File p_i1044_2_, MinecraftSessionService p_i1044_3_)
  46.     {
  47.         this.field_152795_c = p_i1044_1_;
  48.         this.field_152796_d = p_i1044_2_;
  49.         this.field_152797_e = p_i1044_3_;
  50.         this.field_152798_f = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).build(new CacheLoader()
  51.         {
  52.             private static final String __OBFID = "CL_00001829";
  53.             public Map func_152786_a(GameProfile p_152786_1_)
  54.             {
  55.                 return Minecraft.getMinecraft().func_152347_ac().getTextures(p_152786_1_, false);
  56.             }
  57.             public Object load(Object p_load_1_)
  58.             {
  59.                 return this.func_152786_a((GameProfile)p_load_1_);
  60.             }
  61.         });
  62.     }
  63.  
  64.     public ResourceLocation func_152792_a(MinecraftProfileTexture p_152792_1_, Type p_152792_2_)
  65.     {
  66.         return this.func_152789_a(p_152792_1_, p_152792_2_, (SkinManager.SkinAvailableCallback)null);
  67.     }
  68.  
  69.     public ResourceLocation func_152789_a(MinecraftProfileTexture p_152789_1_, final Type p_152789_2_, final SkinManager.SkinAvailableCallback p_152789_3_)
  70.     {
  71.         final ResourceLocation var4 = new ResourceLocation("skins/" + p_152789_1_.getHash());
  72.         ITextureObject var5 = this.field_152795_c.getTexture(var4);
  73.  
  74.         if (var5 != null)
  75.         {
  76.             if (p_152789_3_ != null)
  77.             {
  78.                 p_152789_3_.func_152121_a(p_152789_2_, var4);
  79.             }
  80.         }
  81.         else
  82.         {
  83.             File var6 = new File(this.field_152796_d, p_152789_1_.getHash().substring(0, 2));
  84.             File var7 = new File(var6, p_152789_1_.getHash());
  85.             final ImageBufferDownload var8 = p_152789_2_ == Type.SKIN ? new ImageBufferDownload() : null;
  86.             ThreadDownloadImageData var9 = new ThreadDownloadImageData(var7, p_152789_1_.getUrl(), field_152793_a, new IImageBuffer()
  87.             {
  88.                 private static final String __OBFID = "CL_00001828";
  89.                 public BufferedImage parseUserSkin(BufferedImage p_78432_1_)
  90.                 {
  91.                     if (var8 != null)
  92.                     {
  93.                         p_78432_1_ = var8.parseUserSkin(p_78432_1_);
  94.                     }
  95.  
  96.                     return p_78432_1_;
  97.                 }
  98.                 public void func_152634_a()
  99.                 {
  100.                     if (var8 != null)
  101.                     {
  102.                         var8.func_152634_a();
  103.                     }
  104.  
  105.                     if (p_152789_3_ != null)
  106.                     {
  107.                         p_152789_3_.func_152121_a(p_152789_2_, var4);
  108.                     }
  109.                 }
  110.             });
  111.             this.field_152795_c.loadTexture(var4, var9);
  112.         }
  113.  
  114.         return var4;
  115.     }
  116.  
  117.     public void func_152790_a(final GameProfile p_152790_1_, final SkinManager.SkinAvailableCallback p_152790_2_, final boolean p_152790_3_)
  118.     {
  119.         System.out.println("DEBUG SKIN MANAGER : " + p_152790_1_.getName());
  120.         field_152794_b.submit(new Runnable()
  121.         {
  122.             private static final String __OBFID = "CL_00001827";
  123.             public void run()
  124.             {
  125.                 System.out.println("DEBUG SKIN MANAGER2 : " + p_152790_1_.getName());
  126.                 final HashMap var1 = Maps.newHashMap();
  127.  
  128.                 try
  129.                 {
  130.                     var1.putAll(SkinManager.this.field_152797_e.getTextures(p_152790_1_, p_152790_3_));
  131.                 }
  132.                 catch (InsecureTextureException var3)
  133.                 {
  134.                     ;
  135.                 }
  136.  
  137.                 if (var1.isEmpty() && p_152790_1_.getId().equals(Minecraft.getMinecraft().getSession().func_148256_e().getId()))
  138.                 {
  139.                     var1.putAll(SkinManager.this.field_152797_e.getTextures(SkinManager.this.field_152797_e.fillProfileProperties(p_152790_1_, false), false));
  140.                 }
  141.  
  142.  
  143.  
  144.                 Minecraft.getMinecraft().func_152344_a(new Runnable()
  145.                 {
  146.                     private static final String __OBFID = "CL_00001826";
  147.                     public void run()
  148.                     {
  149.                         System.out.println("DEBUG SKIN MANAGER3 : " + p_152790_1_.getName());
  150.                         if (var1.containsKey(Type.SKIN))
  151.                         {
  152.                             SkinManager.this.func_152789_a((MinecraftProfileTexture)var1.get(Type.SKIN), Type.SKIN, p_152790_2_);
  153.                         }
  154.  
  155.                         if (var1.containsKey(Type.CAPE))
  156.                         {
  157.                             SkinManager.this.func_152789_a((MinecraftProfileTexture)var1.get(Type.CAPE), Type.CAPE, p_152790_2_);
  158.                         }
  159.                     }
  160.                 });
  161.             }
  162.         });
  163.     }
  164.  
  165.     public void loadSkin(GameProfile profile, final SkinManager.SkinAvailableCallback p_152790_2_) {
  166.         //Map var1 = SkinManager.this.field_152797_e.getTextures(profile, false);
  167.         MinecraftProfileTexture skin = new MinecraftProfileTexture(RYCApi.getSkinUrl(profile.getName()), new HashMap<String, String>());
  168.         MinecraftProfileTexture cape = new MinecraftProfileTexture(RYCApi.getCapeUrl(profile.getName()), new HashMap<String, String>());
  169.         final ResourceLocation var4 = new ResourceLocation("skins/" + skin.getHash());
  170.         ITextureObject var5 = this.field_152795_c.getTexture(var4);
  171.         final ResourceLocation var4Cape = new ResourceLocation("skins/" + cape.getHash());
  172.         ITextureObject var5Cape = this.field_152795_c.getTexture(var4Cape);
  173.         UserResponse user;
  174.  
  175.         if(profile.getName().equals(Minecraft.getMinecraft().getSession().getUsername()))
  176.             user = Minecraft.getMinecraft().getUser();
  177.         else
  178.             user = RYCApi.getUserInfo(profile.getName());
  179.  
  180.         if(user == null)
  181.             return;
  182.  
  183.         if (var5 != null) {
  184.             if (p_152790_2_ != null)
  185.             {
  186.                 p_152790_2_.func_152121_a(Type.SKIN, var4);
  187.             }
  188.         } else {
  189.             if(user.hasSkin())
  190.                 SkinManager.this.func_152789_a(skin, Type.SKIN, p_152790_2_);
  191.             else {
  192.                 BufferedImage skinImg = RYCApi.getSkinImage(profile.getName());
  193.                 if(skinImg != null && skinImg.getWidth() <= 64 && skinImg.getHeight() <= 64) {
  194.                     SkinManager.this.func_152789_a(skin, Type.SKIN, p_152790_2_);
  195.                     skinImg.flush();
  196.             }
  197.             }
  198.         }
  199.  
  200.         if (var5Cape != null) {
  201.             if (p_152790_2_ != null)
  202.             {
  203.                 p_152790_2_.func_152121_a(Type.CAPE, var4Cape);
  204.             }
  205.         } else {
  206.             if(user.hasCape())
  207.                 SkinManager.this.func_152789_a(cape, Type.CAPE, p_152790_2_);
  208.         }
  209.     }
  210.  
  211.     public Map func_152788_a(GameProfile p_152788_1_)
  212.     {
  213.         return (Map)this.field_152798_f.getUnchecked(p_152788_1_);
  214.     }
  215.  
  216.     public interface SkinAvailableCallback
  217.     {
  218.         void func_152121_a(Type p_152121_1_, ResourceLocation p_152121_2_);
  219.     }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement