Advertisement
Guest User

Untitled

a guest
Jul 5th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. package pickandcraftSkin;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.image.BufferedImage;
  5. import java.awt.image.DataBufferInt;
  6. import java.awt.image.ImageObserver;
  7. import java.net.HttpURLConnection;
  8. import java.net.URL;
  9.  
  10. import net.minecraft.util.StringUtils;
  11.  
  12. public class PlayerCustom {
  13.  
  14.  
  15. private static String connexion (String adress, String par0Str, String part){
  16. //on construit l'adresse URL en ajoutant le pseudo + l'extension de l'image (png)
  17. int code=404;
  18. //on lance une connexion a l'url afin de savoir si il y a un skin d'uploade
  19. try {
  20. URL u = new URL (adress);
  21. HttpURLConnection huc = ( HttpURLConnection ) u.openConnection ();
  22. huc.setRequestMethod ("GET");
  23. huc.connect () ;
  24. //on recupere le code HTTP retourne par le serveur
  25. code = huc.getResponseCode() ;
  26. System.out.println("SKINURL:code "+code);
  27.  
  28. //si il y est correct on retourne l'adresse
  29. if (code == HttpURLConnection.HTTP_OK)
  30. return adress;
  31.  
  32. //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
  33. else if (code == HttpURLConnection.HTTP_MOVED_TEMP
  34. || code == HttpURLConnection.HTTP_MOVED_PERM
  35. || code == HttpURLConnection.HTTP_SEE_OTHER) {
  36. //on recupere la nouvelle adresse
  37. String newUrl = huc.getHeaderField("Location");
  38.  
  39. // et on lance une connection avec la nouvelle URL
  40. huc = (HttpURLConnection) new URL(newUrl).openConnection();
  41. huc.setRequestMethod ("GET");
  42. huc.connect ();
  43. code = huc.getResponseCode();
  44. System.out.println("SKINURL:code "+code);
  45. //si cette fois le serveur renvoie un code 200 alors on retourne la nouvelle adresse
  46. if (code == HttpURLConnection.HTTP_OK)
  47. return newUrl;
  48. }
  49. }
  50. catch(Exception e){
  51. System.out.println("SKINURL:Bad Url.");
  52. }
  53. //si finalement on ne recoit aucune reponse 200 on retourne l'adresse par defaut
  54. return String.format("http://skins.minecraft.net/Minecraft"+ part + "/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
  55. }
  56.  
  57.  
  58. public static String getURLSkinCustom(String par0Str)
  59. {
  60. String adress=String.format("http://antibiotique.perso.sfr.fr/skins/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
  61. return connexion(adress, par0Str, "Skins");
  62. }
  63.  
  64. public static String getURLCapeCustom(String par0Str)
  65. {
  66. String adress=String.format("http://antibiotique.perso.sfr.fr/capes/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
  67. return connexion(adress, par0Str, "Cloaks");
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement