From ae4eaeb4ba9c407bbc0a497b030cc9ede112c910 Mon Sep 17 00:00:00 2001 From: Alexander Xia Date: Sun, 28 Feb 2016 12:04:54 +0800 Subject: [PATCH] 1.9-pre4 Support --- 1.9-pre4/bwn.java | 139 ++++++++++++++++++++ 1.9-pre4/customskinloader/ModelManager.java | 74 +++++++++++ 2 files changed, 213 insertions(+) create mode 100644 1.9-pre4/bwn.java create mode 100644 1.9-pre4/customskinloader/ModelManager.java diff --git a/1.9-pre4/bwn.java b/1.9-pre4/bwn.java new file mode 100644 index 0000000..adcdf3d --- /dev/null +++ b/1.9-pre4/bwn.java @@ -0,0 +1,139 @@ +import com.google.common.cache.*; +import com.google.common.collect.Maps; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.*; +import com.mojang.authlib.properties.PropertyMap; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.*; +import java.util.concurrent.*; + +public class bwn +{ + public static interface a + { + + public abstract void a(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type type, kk kk1, MinecraftProfileTexture minecraftprofiletexture); + } + + + private static final ExecutorService a; + private final bvi b; + private final File c; + private final MinecraftSessionService d; + private final LoadingCache e; + + public bwn(bvi textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) + { + b = textureManagerInstance; + c = skinCacheDirectory; + d = sessionService; + e = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).build(new CacheLoader() { + + public Map a(GameProfile gameProfile) + throws Exception + { + return bcf.z().X().getTextures(gameProfile, false); + } + + public Object load(Object obj) + throws Exception + { + return a((GameProfile)obj); + } + }); + } + + public kk a(MinecraftProfileTexture profileTexture, com.mojang.authlib.minecraft.MinecraftProfileTexture.Type textureType) + { + return a(profileTexture, textureType, ((a) (null))); + } + + public kk a(MinecraftProfileTexture profileTexture, com.mojang.authlib.minecraft.MinecraftProfileTexture.Type textureType, a skinAvailableCallback) + { + kk resourceLocation = new kk((new StringBuilder()).append("skins/").append(profileTexture.getHash()).toString()); + bvj textureObject = b.b(resourceLocation); + if (textureObject != null) + { + if (skinAvailableCallback != null) + skinAvailableCallback.a(textureType, resourceLocation, profileTexture); + } else + { + File cacheDir = new File(c, profileTexture.getHash().length() <= 2 ? "xx" : profileTexture.getHash().substring(0, 2)); + File cacheFile = new File(cacheDir, profileTexture.getHash()); + bnj imageBuffer = textureType != com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.SKIN ? null : ((bnj) (new bnp())); + buy threadDownloadImageData = new buy(cacheFile, profileTexture.getUrl(), bvw.a(), new bnj() { + + public BufferedImage a(BufferedImage image) + { + if (imageBuffer != null) + image = imageBuffer.a(image); + return image; + } + + public void a() + { + if (imageBuffer != null) + imageBuffer.a(); + if (b != null) + skinAvailableCallback.a(textureType, resourceLocation, profileTexture); + } + + }); + b.a(resourceLocation, threadDownloadImageData); + } + return resourceLocation; + } + + public void a(GameProfile profile, a skinAvailableCallback, boolean requireSecure) + { + a.submit(new Runnable() { + + public void run() + { + Map map = Maps.newHashMap(); + try + { + map.putAll(bwn.this.d.getTextures(profile, requireSecure)); + } + catch (InsecureTextureException insecureTextureException) { } + /* + if (map.isEmpty() && profile.getId().equals(bcf.z().K().e().getId())) + { + profile.getProperties().clear(); + profile.getProperties().putAll(bcf.z().L()); + map.putAll(bwn.this.d.getTextures(profile, false)); + }*/ + //CustomSkinLoader Begin + map.clear(); + map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile.getName(), map)); + //CustomSkinLoader End + bcf.z().a(new Runnable() { + + public void run() + { + if (map.containsKey(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.SKIN)) + bwn.this.a((MinecraftProfileTexture)map.get(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.SKIN), com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.SKIN, skinAvailableCallback); + if (map.containsKey(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.CAPE)) + bwn.this.a((MinecraftProfileTexture)map.get(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.CAPE), com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.CAPE, skinAvailableCallback); + } + }); + } + }); + } + + public Map a(GameProfile profile) + { + return (Map)e.getUnchecked(profile); + } + + static MinecraftSessionService a(bwn skinManagerInstance) + { + return skinManagerInstance.d; + } + + static + { + a = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue()); + } +} diff --git a/1.9-pre4/customskinloader/ModelManager.java b/1.9-pre4/customskinloader/ModelManager.java new file mode 100644 index 0000000..91ecb40 --- /dev/null +++ b/1.9-pre4/customskinloader/ModelManager.java @@ -0,0 +1,74 @@ +package customskinloader; + +import java.util.ArrayList; +import java.util.Map; + +import com.google.common.collect.Maps; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; + +/** + * Model Manager for 1.8 and higher. + * A manager to check if model is available. + * It is the only class in package 'customskinloader' which has differences in different Minecraft version. + * @since 13.1 + */ +public class ModelManager { + private static ArrayList models=null; + + /** + * Check if model is available. + * @param model - default/slim + * @since 13.1 + */ + public static boolean checkModel(String model){ + if(models==null) + refreshModels(); + return models.contains(model); + } + + /** + * Parse hashMapProfile to UserProfile + * @param profile - hashMapProfile (HashMap) + * @return profile - UserProfile instance + * @since 13.1 + */ + public static UserProfile toUserProfile(Map profile){ + UserProfile userProfile=new UserProfile(); + MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN); + userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException + userProfile.model= skin==null?null:skin.getMetadata("model"); + if(userProfile.model==null||userProfile.model.equals("")) + userProfile.model="default"; + MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE); + userProfile.capeUrl= cape==null?null:cape.getUrl(); + return userProfile; + } + + /** + * Parse UserProfile to hashMapProfile + * @param profile - UserProfile instance + * @return profile - hashMapProfile (HashMap) + * @since 13.1 + */ + public static Map fromUserProfile(UserProfile profile){ + Map map=Maps.newHashMap(); + if(profile.skinUrl!=null){ + Map metadata=null; + if(profile.model!=null&&profile.model.equals("slim")){ + metadata = Maps.newHashMap(); + metadata.put("model", "slim"); + } + map.put(Type.SKIN, new MinecraftProfileTexture(profile.skinUrl,metadata)); + } + if(profile.capeUrl!=null) + map.put(Type.CAPE, new MinecraftProfileTexture(profile.capeUrl,null)); + return map; + } + + private static void refreshModels(){ + models=new ArrayList(); + models.add("default"); + models.add("slim"); + } +}