forked from ChomeNS/chomens-bot-java
add offline player into UUIDCommand
This commit is contained in:
parent
ee2fdcd8bd
commit
f095a92008
2 changed files with 14 additions and 3 deletions
|
@ -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",
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue