mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 17:11:39 +03:00
20 lines
627 B
Java
20 lines
627 B
Java
|
public static UUID toUUID(String username) {
|
||
|
ByteBuffer buffer = ByteBuffer.wrap(Arrays.copyOf(username.getBytes(StandardCharsets.US_ASCII), 16));
|
||
|
return new UUID(buffer.getLong(), buffer.getLong()); // MOST, LEAST
|
||
|
}
|
||
|
|
||
|
public static String toUsername(UUID uuid) {
|
||
|
byte[] bytes = ByteBuffer.allocate(16).
|
||
|
putLong(uuid.getMostSignificantBits()).
|
||
|
putLong(uuid.getLeastSignificantBits()).array();
|
||
|
|
||
|
// Find username end
|
||
|
int length = 0;
|
||
|
while(length < bytes.length && bytes[length] != 0) {
|
||
|
length++;
|
||
|
}
|
||
|
|
||
|
// Decode and verify
|
||
|
return VerifyHelper.verifyUsername(new String(bytes, 0, length, StandardCharsets.US_ASCII));
|
||
|
}
|