Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.FisheyLP.Clans;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.util.Date;
- import java.util.UUID;
- public class UUIDParser {
- /*
- * UUIDParser by FisheyLP
- */
- private String name;
- private UUID uuid;
- private Date lastChanged;
- protected String content;
- public UUIDParser(String name) {
- content = getURlContent("https://api.mojang.com/users/profiles/minecraft/"+name+"?at");
- this.name = new UUIDParser(getUUID()).getName();
- lastChanged = genLastChanged();
- }
- public UUIDParser(UUID uuid) {
- content = getURlContent("https://api.mojang.com/user/profiles/"+uuid.toString().replace("-", "")+"/names");
- this.uuid = uuid;
- lastChanged = genLastChanged();
- }
- public UUID getUUID() {
- return genUUID();
- }
- public String getName() {
- return genName();
- }
- public Date getLastChanged() {
- return lastChanged;
- }
- private UUID genUUID() {
- if(uuid != null) return uuid;
- for(String key : content.split(",")) {
- if(key.startsWith("id")) {
- String uuid = key.split(":")[1];
- uuid = uuid.substring(0, 8) + "-" + uuid.substring(8, 12) + "-"
- + uuid.substring(12, 16) + "-" + uuid.substring(16, 20)
- + "-" + uuid.substring(20, 32);
- return UUID.fromString(uuid);
- }
- }
- return null;
- }
- private String genName() {
- if(name != null) return name;
- for(String p : content.split("\\}\\,\\{")) {
- if(p.contains("changedToAt")) {
- for(String t : p.split(",")) {
- if(t.startsWith("name:"))
- return t.split(":")[1];
- }
- } else {
- return p;
- }
- }
- return null;
- }
- private Date genLastChanged() {
- if(lastChanged != null) return lastChanged;
- if(uuid == null) {
- return new UUIDParser(getUUID()).getLastChanged();
- }
- if(content == null || !content.contains("changedToAt")) return null;
- String[] array = content.split("\\},\\{");
- for(String p : array) {
- if(p.contains("changedToAt")) {
- for(String t : p.split(",")) {
- if(t.startsWith("changedToAt:"))
- return new Date(Long.parseLong(t.substring(0, t.length() - 1).split(":")[1]));
- }
- }
- }
- return null;
- }
- private String getURlContent(String website) {
- String contents = "";
- try {
- URL url = new URL(website);
- BufferedReader in = new BufferedReader(new InputStreamReader(
- url.openStream()));
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- contents = contents + inputLine;
- in.close();
- } catch(Exception e) {}
- return getRightContent(contents);
- }
- private String getRightContent(String str) {
- str = str.substring(1, str.length() - 1).replace("\"", "").replace("\n", "");
- String[] arrays = str.split("\\}\\,\\{");
- for(String s : arrays) {
- if(s.contains("name:") && (s.contains("changedToAt:") || s.contains("id"))) {
- return s;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement