2016-07-31 22:00:46 +08:00
|
|
|
package customskinloader.profile;
|
2016-02-27 18:04:25 +08:00
|
|
|
|
2016-09-24 19:08:01 +08:00
|
|
|
import java.util.HashMap;
|
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;
|
2022-12-07 19:38:24 +08:00
|
|
|
import customskinloader.fake.FakeMinecraftProfileTexture;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2016-02-27 18:04:25 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2016-02-27 18:04:25 +08:00
|
|
|
* @since 13.1
|
|
|
|
|
*/
|
2016-03-13 00:17:11 +08:00
|
|
|
public class ModelManager0 {
|
2020-02-22 03:05:38 +08:00
|
|
|
public enum Model {
|
2018-02-12 12:20:28 +08:00
|
|
|
SKIN_DEFAULT,
|
|
|
|
|
SKIN_SLIM,
|
|
|
|
|
CAPE,
|
|
|
|
|
ELYTRA
|
|
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
|
|
|
|
private static HashMap<String, Model> models = new HashMap<String, Model>();
|
2022-12-07 19:38:24 +08:00
|
|
|
private static MinecraftProfileTexture.Type typeElytra = null;
|
2020-02-22 03:05:38 +08:00
|
|
|
|
|
|
|
|
static {
|
2022-12-07 19:38:24 +08:00
|
|
|
for (MinecraftProfileTexture.Type type : MinecraftProfileTexture.Type.values()) {
|
2020-02-22 03:05:38 +08:00
|
|
|
if (type.ordinal() == 2)//ELYTRA
|
|
|
|
|
typeElytra = type;
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
|
|
|
|
models.put("default", Model.SKIN_DEFAULT);
|
|
|
|
|
models.put("slim", Model.SKIN_SLIM);
|
|
|
|
|
models.put("cape", Model.CAPE);
|
2020-02-22 03:05:38 +08:00
|
|
|
if (typeElytra != null) {
|
2018-02-12 12:20:28 +08:00
|
|
|
models.put("elytra", Model.ELYTRA);
|
2020-02-22 03:05:38 +08:00
|
|
|
models.put("elytron", Model.ELYTRA);
|
|
|
|
|
}
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Get enum for the model.
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @param model - string model
|
|
|
|
|
* @since 14.5
|
|
|
|
|
*/
|
2020-02-22 03:05:38 +08:00
|
|
|
public static Model getEnumModel(String model) {
|
2018-02-12 12:20:28 +08:00
|
|
|
return models.get(model);
|
|
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Check if model is skin.
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @since 14.5
|
2020-02-22 03:05:38 +08:00
|
|
|
*/
|
|
|
|
|
public static boolean isSkin(Model model) {
|
|
|
|
|
return model == Model.SKIN_DEFAULT || model == Model.SKIN_SLIM;
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Check if elytra is supported.
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @since 14.5
|
|
|
|
|
*/
|
2020-02-22 03:05:38 +08:00
|
|
|
public static boolean isElytraSupported() {
|
|
|
|
|
return typeElytra != null;
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Parse hashMapProfile to UserProfile
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
|
|
|
|
* @return profile - UserProfile instance
|
|
|
|
|
* @since 13.1
|
|
|
|
|
*/
|
2022-12-07 19:38:24 +08:00
|
|
|
public static UserProfile toUserProfile(Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> profile) {
|
2020-02-22 03:05:38 +08:00
|
|
|
UserProfile userProfile = new UserProfile();
|
|
|
|
|
if (profile == null)
|
2018-02-12 12:20:28 +08:00
|
|
|
return userProfile;
|
2022-12-07 19:38:24 +08:00
|
|
|
MinecraftProfileTexture skin = profile.get(MinecraftProfileTexture.Type.SKIN);
|
2020-02-22 03:05:38 +08:00
|
|
|
userProfile.skinUrl = skin == null ? null : skin.getUrl();//Avoid NullPointerException
|
|
|
|
|
userProfile.model = skin == null ? null : skin.getMetadata("model");
|
|
|
|
|
if (StringUtils.isEmpty(userProfile.model))
|
|
|
|
|
userProfile.model = "default";
|
|
|
|
|
|
2022-12-07 19:38:24 +08:00
|
|
|
MinecraftProfileTexture cape = profile.get(MinecraftProfileTexture.Type.CAPE);
|
2020-02-22 03:05:38 +08:00
|
|
|
userProfile.capeUrl = cape == null ? null : cape.getUrl();
|
2018-02-12 12:20:28 +08:00
|
|
|
return userProfile;
|
|
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Parse UserProfile to hashMapProfile
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @param profile - UserProfile instance
|
|
|
|
|
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
|
|
|
|
* @since 13.1
|
|
|
|
|
*/
|
2022-12-07 19:38:24 +08:00
|
|
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> fromUserProfile(UserProfile profile) {
|
|
|
|
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
2020-02-22 03:05:38 +08:00
|
|
|
if (profile == null)
|
2018-02-12 12:20:28 +08:00
|
|
|
return map;
|
2020-02-22 03:05:38 +08:00
|
|
|
if (profile.skinUrl != null) {
|
|
|
|
|
Map<String, String> metadata = null;
|
|
|
|
|
if ("slim".equals(profile.model) || "auto".equals(profile.model)) {
|
2018-02-12 12:20:28 +08:00
|
|
|
metadata = Maps.newHashMap();
|
2018-05-18 21:06:28 +08:00
|
|
|
metadata.put("model", profile.model);
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2022-12-07 19:38:24 +08:00
|
|
|
map.put(MinecraftProfileTexture.Type.SKIN, getProfileTexture(profile.skinUrl, metadata));
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
if (profile.capeUrl != null)
|
2022-12-07 19:38:24 +08:00
|
|
|
map.put(MinecraftProfileTexture.Type.CAPE, getProfileTexture(profile.capeUrl, null));
|
2020-02-22 03:05:38 +08:00
|
|
|
if (typeElytra != null && profile.elytraUrl != null)
|
|
|
|
|
map.put(typeElytra, getProfileTexture(profile.elytraUrl, null));
|
2018-02-12 12:20:28 +08:00
|
|
|
return map;
|
|
|
|
|
}
|
2020-02-22 03:05:38 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
/**
|
|
|
|
|
* Parse url to MinecraftProfileTexture
|
2020-02-22 03:05:38 +08:00
|
|
|
*
|
2018-02-12 12:20:28 +08:00
|
|
|
* @param url - textureUrl
|
2020-02-22 03:05:38 +08:00
|
|
|
* @param metadata - metadata
|
2018-02-12 12:20:28 +08:00
|
|
|
* @return MinecraftProfileTexture
|
|
|
|
|
* @since 14.5
|
|
|
|
|
*/
|
2020-02-22 03:05:38 +08:00
|
|
|
public static MinecraftProfileTexture getProfileTexture(String url, Map<String, String> metadata) {
|
2022-12-07 19:38:24 +08:00
|
|
|
return new FakeMinecraftProfileTexture(url, metadata);
|
2018-02-12 12:20:28 +08:00
|
|
|
}
|
2016-02-27 18:04:25 +08:00
|
|
|
}
|