Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pickandcraftSkin;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import java.awt.image.DataBufferInt;
- import java.awt.image.ImageObserver;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import net.minecraft.util.StringUtils;
- public class PlayerCustom {
- private static String connexion (String adress, String par0Str, String part){
- //on construit l'adresse URL en ajoutant le pseudo + l'extension de l'image (png)
- int code=404;
- //on lance une connexion a l'url afin de savoir si il y a un skin d'uploade
- try {
- URL u = new URL (adress);
- HttpURLConnection huc = ( HttpURLConnection ) u.openConnection ();
- huc.setRequestMethod ("GET");
- huc.connect () ;
- //on recupere le code HTTP retourne par le serveur
- code = huc.getResponseCode() ;
- System.out.println("SKINURL:code "+code);
- //si il y est correct on retourne l'adresse
- if (code == HttpURLConnection.HTTP_OK)
- return adress;
- //sinon si il y a une redirection on teste avec la nouvelle url. Bien sur il faudra retourne en php une chaine de texte formate avec Url du site + le pseudo du joueur + l'extension mais ce n'est pas l'objet de ce tutoriel
- else if (code == HttpURLConnection.HTTP_MOVED_TEMP
- || code == HttpURLConnection.HTTP_MOVED_PERM
- || code == HttpURLConnection.HTTP_SEE_OTHER) {
- //on recupere la nouvelle adresse
- String newUrl = huc.getHeaderField("Location");
- // et on lance une connection avec la nouvelle URL
- huc = (HttpURLConnection) new URL(newUrl).openConnection();
- huc.setRequestMethod ("GET");
- huc.connect ();
- code = huc.getResponseCode();
- System.out.println("SKINURL:code "+code);
- //si cette fois le serveur renvoie un code 200 alors on retourne la nouvelle adresse
- if (code == HttpURLConnection.HTTP_OK)
- return newUrl;
- }
- }
- catch(Exception e){
- System.out.println("SKINURL:Bad Url.");
- }
- //si finalement on ne recoit aucune reponse 200 on retourne l'adresse par defaut
- return String.format("http://skins.minecraft.net/Minecraft"+ part + "/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
- }
- public static String getURLSkinCustom(String par0Str)
- {
- String adress=String.format("http://antibiotique.perso.sfr.fr/skins/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
- return connexion(adress, par0Str, "Skins");
- }
- public static String getURLCapeCustom(String par0Str)
- {
- String adress=String.format("http://antibiotique.perso.sfr.fr/capes/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
- return connexion(adress, par0Str, "Cloaks");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement