diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 8d8a510b2..2274682e8 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -124,13 +124,21 @@ public class ImageDownloadAlt extends SimpleTexture try { - connection = (HttpURLConnection)(new URL(ImageDownloadAlt.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy()); + URL url = new URL(ImageDownloadAlt.this.imageUrl); + connection = (HttpURLConnection)(url).openConnection(Minecraft.getMinecraft().getProxy()); connection.setDoInput(true); connection.setDoOutput(false); connection.setRequestProperty("Content-Type", "image/png"); connection.setRequestProperty("Expect", "100-continue"); //connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0"); - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + + // Set user agent + if (isImgurLink(url)) { + connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"); + } + else { + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + } connection.connect(); if (connection.getResponseCode() / 100 != 2) @@ -175,4 +183,9 @@ public class ImageDownloadAlt extends SimpleTexture this.imageThread.setDaemon(true); this.imageThread.start(); } + + // Check if the URL is an Imgur link + private static boolean isImgurLink(URL url) { + return url.getHost().endsWith("imgur.com"); + } }