mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-23 09:12:28 +02:00
21 lines
608 B
Java
21 lines
608 B
Java
package ru.nanit.limbo.util;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.UUID;
|
|
|
|
public final class UuidUtil {
|
|
|
|
private UuidUtil() {}
|
|
|
|
public static UUID getOfflineModeUuid(String username) {
|
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username)
|
|
.getBytes(StandardCharsets.UTF_8));
|
|
}
|
|
|
|
public static UUID fromString(String str) {
|
|
if(str.contains("-")) return UUID.fromString(str);
|
|
return UUID.fromString(str.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"));
|
|
}
|
|
|
|
}
|