Advertisement
AlexPshkov

Untitled

May 10th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. package ru.alexpshkov.admintoolplugin.remote;
  2.  
  3. import net.skinsrestorer.api.SkinsRestorerAPI;
  4. import org.apache.commons.io.IOUtils;
  5. import org.json.simple.JSONObject;
  6. import org.json.simple.JSONValue;
  7. import org.json.simple.parser.ParseException;
  8.  
  9. import java.io.IOException;
  10. import java.net.URL;
  11.  
  12. public class SkinsRestorerProvider {
  13.     private final SkinsRestorerAPI skinsRestorerAPI;
  14.  
  15.     public SkinsRestorerProvider() {
  16.         skinsRestorerAPI = SkinsRestorerAPI.getApi();
  17.     }
  18.  
  19.     public boolean isSuccessfully() {
  20.         return skinsRestorerAPI != null;
  21.     }
  22.  
  23.     public String getSkinNameOfPlayer(String playerName) {
  24.         String skin = skinsRestorerAPI.getSkinName(playerName);
  25.         if (skin == null) return playerName;
  26.         return skin;
  27.     }
  28.  
  29.     public String getSkinUUIDOfPlayer(String playerName) {
  30.         return getUuid(getSkinNameOfPlayer(playerName));
  31.     }
  32.  
  33.     public String getUuid(String name) {
  34.         String url = "https://api.mojang.com/users/profiles/minecraft/"+name;
  35.         try {
  36.             String UUIDJson = IOUtils.toString(new URL(url));
  37.             if(UUIDJson.isEmpty()) return "invalid name";
  38.             JSONObject UUIDObject = (JSONObject) JSONValue.parseWithException(UUIDJson);
  39.             return UUIDObject.get("id").toString();
  40.         } catch (IOException | ParseException e) {
  41.             e.printStackTrace();
  42.         }
  43.         return "error";
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement