mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Revert "Revert "Fix legacy skin changing issue. The ETag is now included in the hash.""
This reverts commit 74c1e6f
This commit is contained in:
parent
5ab8126b70
commit
e8217aa9c0
3 changed files with 28 additions and 10 deletions
|
@ -30,6 +30,7 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
|
@ -183,7 +184,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
|||
}
|
||||
} else {
|
||||
// schedule texture loading on the main thread.
|
||||
TextureLoader.loadTexture(resource, new ThreadDownloadImageETag(
|
||||
TextureLoader.loadTexture(resource, new ThreadDownloadImageData(
|
||||
new File(LiteLoader.getAssetsDirectory(), "hd/" + skinDir + texture.getHash().substring(0, 2) + "/" + texture.getHash()),
|
||||
texture.getUrl(),
|
||||
DefaultPlayerSkin.getDefaultSkinLegacy(),
|
||||
|
|
|
@ -30,6 +30,10 @@ import javax.annotation.Nonnull;
|
|||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* @deprecated Now that legacy includes the etag in the hash, it is no longer required to save it to disk.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThreadDownloadImageETag extends SimpleTexture implements IBufferedTexture {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
|
|
@ -9,21 +9,21 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
|||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Session;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ServerType("legacy")
|
||||
|
@ -83,12 +83,24 @@ public class LegacySkinServer implements SkinServer {
|
|||
}
|
||||
|
||||
private MinecraftProfileTexture loadProfileTexture(GameProfile profile, String url) throws IOException {
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
|
||||
if (urlConnection.getResponseCode() / 100 != 2) {
|
||||
throw new IOException("Bad response code: " + urlConnection.getResponseCode() + ". URL: " + url);
|
||||
try (MoreHttpResponses resp = MoreHttpResponses.execute(HDSkinManager.httpClient, new HttpHead(url))) {
|
||||
if (!resp.ok()) {
|
||||
throw new IOException("Bad response code: " + resp.getResponseCode() + ". URL: " + url);
|
||||
}
|
||||
logger.debug("Found skin for {} at {}", profile.getName(), url);
|
||||
return new MinecraftProfileTexture(url, null);
|
||||
|
||||
Header eTagHeader = resp.getResponse().getFirstHeader(HttpHeaders.ETAG);
|
||||
final String eTag = eTagHeader == null ? "" : StringUtils.strip(eTagHeader.getValue(), "\"");
|
||||
|
||||
// Add the ETag onto the end of the texture hash. Should properly cache the textures.
|
||||
return new MinecraftProfileTexture(url, null) {
|
||||
|
||||
@Override
|
||||
public String getHash() {
|
||||
return super.getHash() + eTag;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,4 +168,5 @@ public class LegacySkinServer implements SkinServer {
|
|||
.append("gateway", gateway)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue