From 85964ed624c3d586311bc1c768bac5335e05f9cf Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 17 Apr 2021 00:04:06 +0200 Subject: [PATCH] Cleaner and easier to use OfflineUUID CLI --- .../pandacube/lib/core/util/OfflineUUID.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Core/src/main/java/fr/pandacube/lib/core/util/OfflineUUID.java b/Core/src/main/java/fr/pandacube/lib/core/util/OfflineUUID.java index fa94f0d..91852da 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/util/OfflineUUID.java +++ b/Core/src/main/java/fr/pandacube/lib/core/util/OfflineUUID.java @@ -1,28 +1,45 @@ package fr.pandacube.lib.core.util; import java.nio.charset.Charset; +import java.util.Objects; +import java.util.Scanner; import java.util.UUID; public class OfflineUUID { - public static void main(String[] args) { - for (String arg : args) - System.out.println("" + arg + ":" + getFromNickName(arg)); - if (args.length == 0) - throw new IllegalArgumentException("no argument given. Please give at least one argument."); - } public static UUID getFromNickName(String nickname) { - String str = "OfflinePlayer:" + nickname; - byte[] from_str = str.getBytes(Charset.forName("UTF-8")); + byte[] from_str = ("OfflinePlayer:" + nickname).getBytes(Charset.forName("UTF-8")); return UUID.nameUUIDFromBytes(from_str); } public static UUID[] getFromNickNames(String[] nicknames) { - if (nicknames == null) throw new NullPointerException(); + 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)); + } + } }