2016-10-18 21:48:07 +08:00
|
|
|
package customskinloader.loader.jsonapi;
|
|
|
|
|
|
2016-11-12 19:33:01 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
2016-10-18 21:48:07 +08:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
|
|
import customskinloader.CustomSkinLoader;
|
|
|
|
|
import customskinloader.config.SkinSiteProfile;
|
|
|
|
|
import customskinloader.loader.JsonAPILoader;
|
|
|
|
|
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
|
|
|
|
import customskinloader.profile.UserProfile;
|
|
|
|
|
import customskinloader.utils.MinecraftUtil;
|
|
|
|
|
|
|
|
|
|
public class CustomSkinAPIPlus implements IJsonAPI {
|
|
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
private static String clientID=null;
|
|
|
|
|
public CustomSkinAPIPlus(){
|
|
|
|
|
File clientIDFile=new File(CustomSkinLoader.DATA_DIR,"CustomSkinAPIPlus-ClientID");
|
|
|
|
|
|
|
|
|
|
if(clientIDFile.isFile())
|
|
|
|
|
try{
|
|
|
|
|
clientID=FileUtils.readFileToString(clientIDFile);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if(clientID==null){
|
|
|
|
|
clientID=UUID.randomUUID().toString();
|
|
|
|
|
try {
|
|
|
|
|
FileUtils.write(clientIDFile, clientID);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String toJsonUrl(String root, String username) {
|
|
|
|
|
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
|
|
|
|
}
|
2016-10-18 21:48:07 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
@Override
|
|
|
|
|
public String getPayload(SkinSiteProfile ssp) {
|
|
|
|
|
if(ssp.privacy==null)
|
|
|
|
|
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
|
|
|
|
return new Gson().toJson(new CustomSkinAPIPlusPayload(ssp.privacy));
|
|
|
|
|
}
|
2016-10-18 21:48:07 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
@Override
|
|
|
|
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
|
|
|
|
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
|
|
|
|
}
|
2016-10-18 21:48:07 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "CustomSKinAPIPlus";
|
|
|
|
|
}
|
2016-10-18 21:48:07 +08:00
|
|
|
|
2018-02-12 12:20:28 +08:00
|
|
|
public static class CustomSkinAPIPlusPayload{
|
|
|
|
|
public String gameVersion;//minecraft version
|
|
|
|
|
public String modVersion;//mod version
|
|
|
|
|
public String serverAddress;//ip:port
|
|
|
|
|
public String clientID;//Minecraft Client ID
|
|
|
|
|
public CustomSkinAPIPlusPayload(CustomSkinAPIPlusPrivacy privacy){
|
|
|
|
|
if(privacy.gameVersion)
|
|
|
|
|
gameVersion=MinecraftUtil.getMinecraftMainVersion();
|
|
|
|
|
if(privacy.modVersion)
|
|
|
|
|
modVersion=CustomSkinLoader.CustomSkinLoader_VERSION;
|
|
|
|
|
if(privacy.serverAddress)
|
|
|
|
|
serverAddress=MinecraftUtil.isLanServer()?null:MinecraftUtil.getStandardServerAddress();
|
|
|
|
|
if(privacy.clientID)
|
|
|
|
|
clientID=CustomSkinAPIPlus.clientID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class CustomSkinAPIPlusPrivacy{
|
|
|
|
|
public boolean gameVersion=true;
|
|
|
|
|
public boolean modVersion=true;
|
|
|
|
|
public boolean serverAddress=true;
|
|
|
|
|
public boolean clientID=true;
|
|
|
|
|
}
|
2016-10-18 21:48:07 +08:00
|
|
|
}
|