Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
1,193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package de.yarotu.nick.utils.skin;
  2.  
  3. import java.net.URL;
  4. import java.net.URLConnection;
  5. import java.util.Scanner;
  6. import java.util.logging.Level;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.json.simple.JSONArray;
  10. import org.json.simple.JSONObject;
  11. import org.json.simple.parser.JSONParser;
  12.  
  13. public class Skin {
  14.  
  15.     String uuid;
  16.     String name;
  17.     String value;
  18.     String signatur;
  19.    
  20.     public Skin(String uuid){
  21.         this.uuid = uuid;
  22.         load();
  23.     }
  24.    
  25.     private void load() {
  26.         try {
  27.            
  28.             URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
  29.             URLConnection urlConnection = url.openConnection();
  30.             urlConnection.setUseCaches(false);
  31.             urlConnection.setDefaultUseCaches(false);
  32.            
  33.             urlConnection.addRequestProperty("Cache-Control", "no-chache, no-store, must-revalidate");
  34.             urlConnection.addRequestProperty("Pragma", "no-chache");
  35.            
  36.             Scanner scanner = new Scanner(urlConnection.getInputStream(), "UTF-8");
  37.             String json = scanner.useDelimiter("\\A").next();
  38.             scanner.close();
  39.             JSONParser parser = new JSONParser();
  40.             Object object = parser.parse(json);
  41.             JSONArray properties = (JSONArray) ((JSONObject) object).get("propertis");
  42.            
  43.                 for(int i = 0; i < properties.size(); i++) {
  44.                     try {
  45.                         JSONObject property = (JSONObject) properties.get(i);
  46.                         String name = (String) property.get("name");
  47.                         String value = (String) property.get("value");
  48.                         String signature = property.containsKey("signature") ? (String) property.get("signature") : null;
  49.                        
  50.                         this.name = name;
  51.                         this.value = value;
  52.                         this.signatur = signature;
  53.                     } catch (Exception e) {
  54.                         Bukkit.getLogger().log(Level.WARNING, "Fehler bei der Auth property", e);
  55.                     }
  56.                 }
  57.            
  58.            
  59.         } catch (Exception e) {
  60.             System.out.println("Fehler bei der Skin.java");
  61.             e.printStackTrace();
  62.         }
  63.     }
  64.    
  65.     public String getSkinvalue() {
  66.         return value;
  67.     }
  68.    
  69.     public String getSkinName() {
  70.         return name;
  71.     }
  72.    
  73.     public String getSkinSignatur() {
  74.         return signatur;
  75.     }
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement