Added support for Mojang API calls in ApiClient
Added Mojang API call to retreive Player profile
This commit is contained in:
7
src/main/java/eu/crushedpixel/replaymod/api/mojang/MojangApiMethods.java
Executable file
7
src/main/java/eu/crushedpixel/replaymod/api/mojang/MojangApiMethods.java
Executable file
@@ -0,0 +1,7 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang;
|
||||
|
||||
public class MojangApiMethods {
|
||||
|
||||
public static final String userprofile = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang;
|
||||
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import eu.crushedpixel.replaymod.api.mojang.holders.Profile;
|
||||
import eu.crushedpixel.replaymod.api.mojang.holders.Properties;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ImageBufferDownload;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SkinDownloader {
|
||||
|
||||
public static ITextureObject getDownloadImageSkin(ResourceLocation resourceLocationIn, UUID uuid) throws IOException, ApiException {
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
ITextureObject object = texturemanager.getTexture(resourceLocationIn);
|
||||
|
||||
try {
|
||||
if(object == null) {
|
||||
Profile profile = ReplayMod.apiClient.getProfileFromUUID(uuid);
|
||||
|
||||
if(profile.getProperties() != null && profile.getProperties().length > 0) {
|
||||
List<Properties> plist = Arrays.asList(profile.getProperties());
|
||||
Collections.reverse(plist);
|
||||
|
||||
for(Properties p : plist) {
|
||||
if(p.getName().equals("textures")) {
|
||||
object = new ThreadDownloadImageData((File) null,
|
||||
p.getTextureValue().getTextures().getSKIN().getUrl(),
|
||||
DefaultPlayerSkin.getDefaultSkin(uuid), new ImageBufferDownload());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
object = new ThreadDownloadImageData((File)null,
|
||||
null,
|
||||
DefaultPlayerSkin.getDefaultSkin(uuid), new ImageBufferDownload());
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang.holders;
|
||||
|
||||
public class Profile {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private Properties[] properties;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Properties[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Properties[] properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang.holders;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.StringUtils;
|
||||
|
||||
public class Properties {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private String signature;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TextureValue getTextureValue() {
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(StringUtils.newStringUtf8(Base64.decodeBase64(value)), TextureValue.class);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang.holders;
|
||||
|
||||
public class TextureValue {
|
||||
private long timestamp;
|
||||
private String profileId;
|
||||
private String profileName;
|
||||
private boolean isPublic;
|
||||
private Textures textures;
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getProfileId() {
|
||||
return profileId;
|
||||
}
|
||||
|
||||
public void setProfileId(String profileId) {
|
||||
this.profileId = profileId;
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void setProfileName(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
public void setIsPublic(boolean isPublic) {
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
public Textures getTextures() {
|
||||
return textures;
|
||||
}
|
||||
|
||||
public void setTextures(Textures textures) {
|
||||
this.textures = textures;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang.holders;
|
||||
|
||||
public class Textures {
|
||||
private UrlHolder SKIN;
|
||||
private UrlHolder CAPE;
|
||||
|
||||
public UrlHolder getSKIN() {
|
||||
return SKIN;
|
||||
}
|
||||
|
||||
public void setSKIN(UrlHolder SKIN) {
|
||||
this.SKIN = SKIN;
|
||||
}
|
||||
|
||||
public UrlHolder getCAPE() {
|
||||
return CAPE;
|
||||
}
|
||||
|
||||
public void setCAPE(UrlHolder CAPE) {
|
||||
this.CAPE = CAPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.crushedpixel.replaymod.api.mojang.holders;
|
||||
|
||||
public class UrlHolder {
|
||||
private String url;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user