1.9-pre4 Support

This commit is contained in:
Alexander Xia committed 2016-02-28 12:04:54 +08:00
1 parent f9a36acf8f
commit ae4eaeb4ba
2 files changed
+213

No files matched your search

+139
View File
@@ -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());
}
}
@@ -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<String> 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<String,MinecraftProfileTexture>)
* @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<String,MinecraftProfileTexture>)
* @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<String>();
models.add("default");
models.add("slim");
}
}