Created
January 20, 2019 20:42
-
-
Save pcrunn/147cfd8639d4b6c5fb8286c18e6f8cfc to your computer and use it in GitHub Desktop.
Does this look as dumb as I think?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.pcrunn.uuidfetcher; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.util.UUID; | |
public class UUIDFetcher { | |
public static UUID getUUID(String playerName){ | |
try { | |
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/"+playerName); | |
String response = readURL(url); | |
String[] hbadghdhagdhd = response | |
.replace("{","") | |
.replace("}","") | |
.split(","); | |
String tr = hbadghdhagdhd[0].replace("\"","").split(":")[1]; | |
return UUID.fromString(tr.substring(0, 8) + "-" + tr.substring(8, 12) + "-" + tr.substring(12, 16) + "-" + tr.substring(16, 20) + "-" + tr.substring(20, 32)); | |
} catch (Exception e) { | |
return null; | |
} | |
} | |
// Not sure where I got that method from, But It's not mine. | |
private static String readURL(URL url) { | |
String temp = ""; | |
BufferedReader reader = null; | |
try { | |
reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); | |
for (String s; (s = reader.readLine()) != null; ) { | |
temp += s; | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
if (reader != null) { | |
try { | |
reader.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
return temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment