Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package de.tails.citybuild.npc;
  2. import java.net.URL;
  3. import java.net.URLConnection;
  4. import java.util.Scanner;
  5. import java.util.logging.Level;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.json.simple.JSONArray;
  9. import org.json.simple.JSONObject;
  10. import org.json.simple.parser.JSONParser;
  11.  
  12. public class Skin {
  13.  
  14. String uuid;
  15. String name;
  16. String value;
  17. String signatur;
  18.  
  19. Skin(String uuid) {
  20. this.uuid = uuid;
  21. load();
  22. }
  23.  
  24. private void load() {
  25. try {
  26. URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
  27. URLConnection uc = url.openConnection();
  28. uc.setUseCaches(false);
  29. uc.setDefaultUseCaches(false);
  30. uc.addRequestProperty("User-Agent", "Mozilla/5.0");
  31. uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
  32. uc.addRequestProperty("Pragma", "no-cache");
  33.  
  34. @SuppressWarnings("resource")
  35. String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next();
  36. JSONParser parser = new JSONParser();
  37. Object obj = parser.parse(json);
  38. JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties");
  39. for(int i = 0; i < properties.size(); i++) {
  40. try {
  41. JSONObject property = (JSONObject) properties.get(i);
  42. String name = (String) property.get("name");
  43. String value = (String) property.get("value");
  44. String signature = property.containsKey("signature") ? (String) property.get("signature") : null;
  45.  
  46. this.name = name;
  47. this.value = value;
  48. this.signatur = signature;
  49.  
  50.  
  51. } catch (Exception e) {
  52. Bukkit.getLogger().log(Level.WARNING, "Failed to apply auth property", e);
  53. }
  54. }
  55. } catch (Exception e) {
  56. ;
  57. }
  58. }
  59.  
  60. public String getSkinValue() {
  61. return value;
  62. }
  63.  
  64. public String getSkinName() {
  65. return name;
  66. }
  67.  
  68. public String getSkinSignatur() {
  69. return signatur;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement