Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.disguise.backend;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.logging.Level;
- import net.minecraft.util.com.google.gson.Gson;
- import org.disguise.Disguise;
- public class GameApisRest
- {
- private static final Gson gson = new Gson();
- public static Profile getProfile(String uuidOrName) {
- String ip = "https://use.gameapis.net/mc/player/profile/" + uuidOrName;
- String json = readJson(ip);
- Profile profile = (Profile)gson.fromJson(json, Profile.class);
- return (profile != null) ? profile : new Profile();
- }
- private static String readJson(String ip) {
- StringBuilder sb = new StringBuilder();
- try {
- URL url = new URL(ip);
- HttpURLConnection http = (HttpURLConnection)url.openConnection();
- http.addRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
- http.setConnectTimeout(3000);
- http.setRequestMethod("GET");
- BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));
- String l;
- while ((l = reader.readLine()) != null) {
- sb.append(l);
- }
- reader.close();
- } catch (Exception e) {
- Disguise.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement