SHOW:
|
|
- or go back to the newest paste.
1 | - | package com.FisheyLP.Clans; |
1 | + | |
2 | import java.io.InputStreamReader; | |
3 | import java.net.URL; | |
4 | import java.util.Date; | |
5 | import java.util.UUID; | |
6 | ||
7 | public class UUIDParser { | |
8 | ||
9 | /* | |
10 | * UUIDParser by FisheyLP | |
11 | */ | |
12 | ||
13 | private String name; | |
14 | private UUID uuid; | |
15 | private Date lastChanged; | |
16 | protected String content; | |
17 | ||
18 | public UUIDParser(String name) { | |
19 | content = getURlContent("https://api.mojang.com/users/profiles/minecraft/"+name+"?at"); | |
20 | this.name = new UUIDParser(getUUID()).getName(); | |
21 | lastChanged = genLastChanged(); | |
22 | } | |
23 | ||
24 | public UUIDParser(UUID uuid) { | |
25 | content = getURlContent("https://api.mojang.com/user/profiles/"+uuid.toString().replace("-", "")+"/names"); | |
26 | this.uuid = uuid; | |
27 | lastChanged = genLastChanged(); | |
28 | } | |
29 | ||
30 | public UUID getUUID() { | |
31 | return genUUID(); | |
32 | } | |
33 | public String getName() { | |
34 | return genName(); | |
35 | } | |
36 | public Date getLastChanged() { | |
37 | return lastChanged; | |
38 | } | |
39 | ||
40 | private UUID genUUID() { | |
41 | if(uuid != null) return uuid; | |
42 | for(String key : content.split(",")) { | |
43 | if(key.startsWith("id")) { | |
44 | String uuid = key.split(":")[1]; | |
45 | uuid = uuid.substring(0, 8) + "-" + uuid.substring(8, 12) + "-" | |
46 | + uuid.substring(12, 16) + "-" + uuid.substring(16, 20) | |
47 | + "-" + uuid.substring(20, 32); | |
48 | return UUID.fromString(uuid); | |
49 | } | |
50 | } | |
51 | return null; | |
52 | } | |
53 | ||
54 | private String genName() { | |
55 | if(name != null) return name; | |
56 | for(String p : content.split("\\}\\,\\{")) { | |
57 | if(p.contains("changedToAt")) { | |
58 | for(String t : p.split(",")) { | |
59 | if(t.startsWith("name:")) | |
60 | return t.split(":")[1]; | |
61 | } | |
62 | } else { | |
63 | return p; | |
64 | } | |
65 | } | |
66 | return null; | |
67 | } | |
68 | ||
69 | private Date genLastChanged() { | |
70 | if(lastChanged != null) return lastChanged; | |
71 | if(uuid == null) { | |
72 | return new UUIDParser(getUUID()).getLastChanged(); | |
73 | } | |
74 | if(content == null || !content.contains("changedToAt")) return null; | |
75 | ||
76 | String[] array = content.split("\\},\\{"); | |
77 | for(String p : array) { | |
78 | if(p.contains("changedToAt")) { | |
79 | for(String t : p.split(",")) { | |
80 | if(t.startsWith("changedToAt:")) | |
81 | return new Date(Long.parseLong(t.substring(0, t.length() - 1).split(":")[1])); | |
82 | } | |
83 | } | |
84 | } | |
85 | return null; | |
86 | } | |
87 | private String getURlContent(String website) { | |
88 | String contents = ""; | |
89 | try { | |
90 | URL url = new URL(website); | |
91 | BufferedReader in = new BufferedReader(new InputStreamReader( | |
92 | url.openStream())); | |
93 | ||
94 | String inputLine; | |
95 | while ((inputLine = in.readLine()) != null) | |
96 | contents = contents + inputLine; | |
97 | in.close(); | |
98 | ||
99 | } catch(Exception e) {} | |
100 | return getRightContent(contents); | |
101 | } | |
102 | private String getRightContent(String str) { | |
103 | str = str.substring(1, str.length() - 1).replace("\"", "").replace("\n", ""); | |
104 | ||
105 | String[] arrays = str.split("\\}\\,\\{"); | |
106 | for(String s : arrays) { | |
107 | if(s.contains("name:") && (s.contains("changedToAt:") || s.contains("id"))) { | |
108 | return s; | |
109 | } | |
110 | } | |
111 | return null; | |
112 | } | |
113 | } |