From f095a92008cc71301508bef495f5b868c287ec8f Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:58:35 +0700 Subject: [PATCH] add offline player into UUIDCommand --- .../chayapak1/chomens_bot/commands/UUIDCommand.java | 13 ++++++++++--- .../chayapak1/chomens_bot/util/UUIDUtilities.java | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java index 7950140..2f56598 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/UUIDCommand.java @@ -7,6 +7,7 @@ import me.chayapak1.chomens_bot.command.CommandException; import me.chayapak1.chomens_bot.command.TrustLevel; import me.chayapak1.chomens_bot.data.PlayerEntry; import me.chayapak1.chomens_bot.util.ColorUtilities; +import me.chayapak1.chomens_bot.util.UUIDUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -33,10 +34,16 @@ public class UUIDCommand extends Command { if (!player.isEmpty()) { final PlayerEntry entry = bot.players.getEntry(player); - if (entry == null) throw new CommandException(Component.text("Invalid player name")); + String name; + String uuid; - final String name = entry.profile.getName(); - final String uuid = entry.profile.getIdAsString(); + if (entry == null) { + name = player; + uuid = UUIDUtilities.getOfflineUUID(player).toString(); + } else { + name = entry.profile.getName(); + uuid = entry.profile.getIdAsString(); + } return Component.translatable( "%s's UUID: %s", diff --git a/src/main/java/me/chayapak1/chomens_bot/util/UUIDUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/UUIDUtilities.java index 17274f6..149a933 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/UUIDUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/UUIDUtilities.java @@ -10,6 +10,10 @@ import java.nio.ByteBuffer; public class UUIDUtilities { private UUIDUtilities () {} + public static UUID getOfflineUUID (String username) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes()); + } + public static int[] intArray (UUID uuid) { final ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(0, uuid.getMostSignificantBits());