PandaLib/pandalib-util/src/main/java/fr/pandacube/lib/util/OfflineUUID.java

46 lines
1.0 KiB
Java
Raw Normal View History

package fr.pandacube.lib.util;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Scanner;
import java.util.UUID;
public class OfflineUUID {
public static UUID getFromNickName(String nickname) {
byte[] from_str = ("OfflinePlayer:" + nickname).getBytes(StandardCharsets.UTF_8);
return UUID.nameUUIDFromBytes(from_str);
}
2019-10-26 23:15:49 +02:00
public static UUID[] getFromNickNames(String[] nicknames) {
Objects.requireNonNull(nicknames);
UUID[] uuids = new UUID[nicknames.length];
for (int i = 0; i < nicknames.length; i++)
uuids[i] = getFromNickName(nicknames[i]);
return uuids;
}
public static void main(String[] args) {
if (args.length == 0) {
try (Scanner s = new Scanner(System.in)) {
for(;;) {
System.out.print("Please input a player name: ");
if (!s.hasNext())
break;
String line = s.nextLine();
System.out.println(getFromNickName(line));
}
}
}
else {
for (String arg : args)
System.out.println("" + arg + ":" + getFromNickName(arg));
}
}
}