Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xyz.olympiccode.tools.ocbot.others;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import com.google.gson.JsonObject;
- import com.google.gson.JsonParser;
- public class JsonGet {
- private static String BASE_URL = "https://eu.mc-api.net/v3/uuid/";
- public static String getJson(final String player) {
- String url = BASE_URL + player;
- String content = "";
- try {
- HttpURLConnection con = createConnection(url);
- BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String input;
- while ((input = br.readLine()) != null) {
- content = content + input;
- }
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return content;
- }
- public static String getUUID(String player) {
- JsonObject jobject = new JsonObject();
- JsonParser parser = new JsonParser();
- String json = JsonGet.getJson(player);
- jobject = (JsonObject)parser.parse(json);
- String puuid = null;
- try
- {
- puuid = jobject.get("uuid").getAsString();
- }
- catch (Exception e) {}
- return puuid;
- }
- private static HttpURLConnection createConnection(String s) throws Exception {
- URL url = new URL(s);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setUseCaches(true);
- connection.addRequestProperty("User-Agent", "Mozilla/4.76");
- connection.setDoOutput(true);
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement