Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package org.disguise.backend;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5. import java.net.HttpURLConnection;
  6. import java.net.URL;
  7. import java.util.logging.Level;
  8. import net.minecraft.util.com.google.gson.Gson;
  9. import org.disguise.Disguise;
  10.  
  11.  
  12.  
  13. public class GameApisRest
  14. {
  15. private static final Gson gson = new Gson();
  16.  
  17. public static Profile getProfile(String uuidOrName) {
  18. String ip = "https://use.gameapis.net/mc/player/profile/" + uuidOrName;
  19. String json = readJson(ip);
  20. Profile profile = (Profile)gson.fromJson(json, Profile.class);
  21. return (profile != null) ? profile : new Profile();
  22. }
  23.  
  24. private static String readJson(String ip) {
  25. StringBuilder sb = new StringBuilder();
  26. try {
  27. URL url = new URL(ip);
  28. HttpURLConnection http = (HttpURLConnection)url.openConnection();
  29. http.addRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
  30. http.setConnectTimeout(3000);
  31. http.setRequestMethod("GET");
  32.  
  33. BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));
  34.  
  35. String l;
  36. while ((l = reader.readLine()) != null) {
  37. sb.append(l);
  38. }
  39.  
  40. reader.close();
  41. } catch (Exception e) {
  42. Disguise.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
  43. }
  44. return sb.toString();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement