Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mcplaza.auth;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.math.BigInteger;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.json.simple.JSONObject;
- import org.json.simple.parser.JSONParser;
- import net.mcplaza.auth.UUIDFetcher.Response;
- public class UUIDFetcher {
- public static Map<String, UUID> uuidStore = new HashMap<String, UUID>();
- public static Map<UUID, String> nameStore = new HashMap<UUID, String>();
- private static final String agent = "Mozilla/5.0";
- public static Response getResponse(String name) {
- if(uuidStore.containsKey(name)) {
- Response r = new Response();
- r.name = name;
- r.uuid = uuidStore.get(name);
- return r;
- }
- HttpClient client = new DefaultHttpClient();
- HttpGet get = new HttpGet("https://use.gameapis.net/mc/player/profile/" + name);
- get.addHeader("User-Agent", "Mozilla/5.0");
- try {
- HttpResponse response = client.execute(get);
- BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- JSONParser parser = new JSONParser();
- JSONObject object = (JSONObject)parser.parse(reader);
- String uuid = (String) object.get("id");
- String targetName = (String) object.get("name");
- UUID id = new UUID(new BigInteger(uuid.substring(0, 16), 16).longValue(), new BigInteger(uuid.substring(16), 16).longValue());
- Response r = new Response();
- r.name = targetName;
- r.uuid = id;
- uuidStore.put(name, id);
- nameStore.put(id, name);
- return r;
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
- public static Response getResponse(UUID uuid) {
- if(nameStore.containsKey(uuid)) {
- Response r = new Response();
- r.name = nameStore.get(uuid);
- r.uuid = uuid;
- return r;
- }
- HttpClient client = new DefaultHttpClient();
- HttpGet get = new HttpGet("https://use.gameapis.net/mc/player/profile/" + uuid.toString().replaceAll("-", ""));
- get.addHeader("User-Agent", "Mozilla/5.0");
- try {
- HttpResponse response = client.execute(get);
- BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- JSONParser parser = new JSONParser();
- JSONObject object = (JSONObject)parser.parse(reader);
- String name = (String) object.get("name");
- Response r = new Response();
- r.name = name;
- r.uuid = uuid;
- uuidStore.put(name, uuid);
- nameStore.put(uuid, name);
- return r;
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
- public static class Response {
- public String name;
- public UUID uuid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement