Files
MCCustomSkinLoader/Common/customskinloader/profile/ModelManager0.java
T

78 lines
2.3 KiB
Java
Raw Normal View History

2016-07-31 22:00:46 +08:00
package customskinloader.profile;
2016-02-27 18:04:25 +08:00
import java.util.ArrayList;
2016-02-27 21:43:46 +08:00
import java.util.Map;
2016-02-27 18:04:25 +08:00
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
*/
2016-03-13 00:17:11 +08:00
public class ModelManager0 {
2016-02-27 18:04:25 +08:00
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
*/
2016-02-27 21:43:46 +08:00
public static UserProfile toUserProfile(Map profile){
2016-02-27 18:04:25 +08:00
UserProfile userProfile=new UserProfile();
2016-04-03 16:29:00 +08:00
if(profile==null)
return userProfile;
2016-02-27 18:04:25 +08:00
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
*/
2016-02-27 21:43:46 +08:00
public static Map fromUserProfile(UserProfile profile){
Map map=Maps.newHashMap();
2016-04-03 01:14:33 +08:00
if(profile==null)
return map;
2016-02-27 18:04:25 +08:00
if(profile.skinUrl!=null){
2016-02-27 21:43:46 +08:00
Map metadata=null;
2016-02-27 18:04:25 +08:00
if(profile.model!=null&&profile.model.equals("slim")){
metadata = Maps.newHashMap();
metadata.put("model", "slim");
}
2016-02-27 21:43:46 +08:00
map.put(Type.SKIN, new MinecraftProfileTexture(profile.skinUrl,metadata));
2016-02-27 18:04:25 +08:00
}
if(profile.capeUrl!=null)
2016-02-27 21:43:46 +08:00
map.put(Type.CAPE, new MinecraftProfileTexture(profile.capeUrl,null));
return map;
2016-02-27 18:04:25 +08:00
}
private static void refreshModels(){
models=new ArrayList<String>();
models.add("default");
models.add("slim");
}
}