diff --git a/api/src/main/java/net/luckperms/api/event/player/lookup/UniqueIdDetermineTypeEvent.java b/api/src/main/java/net/luckperms/api/event/player/lookup/UniqueIdDetermineTypeEvent.java index 78bec2de9..faec60cb9 100644 --- a/api/src/main/java/net/luckperms/api/event/player/lookup/UniqueIdDetermineTypeEvent.java +++ b/api/src/main/java/net/luckperms/api/event/player/lookup/UniqueIdDetermineTypeEvent.java @@ -56,6 +56,22 @@ public interface UniqueIdDetermineTypeEvent extends LuckPermsEvent, ResultEvent< */ String TYPE_UNAUTHENTICATED = "unauthenticated"; + /** + * The players UUID most likely belongs to a NPC (non-player character). + * + *
Usually indicated by the UUID being {@link UUID#version() version} 2.
+ * + * @since 5.4 + */ + String TYPE_NPC = "npc"; + + /** + * Unknown UUID type. + * + * @since 5.4 + */ + String TYPE_UNKNOWN = "unknown"; + /** * Gets the {@link UUID unique id} being queried. * diff --git a/common/src/main/java/me/lucko/luckperms/common/util/UniqueIdType.java b/common/src/main/java/me/lucko/luckperms/common/util/UniqueIdType.java index b3dbfdd89..6e19428c2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/util/UniqueIdType.java +++ b/common/src/main/java/me/lucko/luckperms/common/util/UniqueIdType.java @@ -28,7 +28,9 @@ package me.lucko.luckperms.common.util; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; import net.luckperms.api.event.player.lookup.UniqueIdDetermineTypeEvent; import java.util.UUID; @@ -40,16 +42,31 @@ public final class UniqueIdType { public static final UniqueIdType AUTHENTICATED = new UniqueIdType( UniqueIdDetermineTypeEvent.TYPE_AUTHENTICATED, - Component.translatable("luckperms.command.user.info.uuid-type.mojang", NamedTextColor.DARK_GREEN) + NamedTextColor.DARK_GREEN, + "luckperms.command.user.info.uuid-type.mojang", + "luckperms.command.user.info.uuid-type.desc.mojang" ); public static final UniqueIdType UNAUTHENTICATED = new UniqueIdType( UniqueIdDetermineTypeEvent.TYPE_UNAUTHENTICATED, - Component.translatable("luckperms.command.user.info.uuid-type.not-mojang", NamedTextColor.DARK_GRAY) + NamedTextColor.DARK_GRAY, + "luckperms.command.user.info.uuid-type.not-mojang", + "luckperms.command.user.info.uuid-type.desc.not-mojang" ); - private static final String TYPE_NPC = "npc"; - public static final UniqueIdType NPC = new UniqueIdType(TYPE_NPC); + public static final UniqueIdType NPC = new UniqueIdType( + UniqueIdDetermineTypeEvent.TYPE_NPC, + NamedTextColor.GOLD, + "luckperms.command.user.info.uuid-type.npc", + "luckperms.command.user.info.uuid-type.desc.npc" + ); + + public static final UniqueIdType UNKNOWN = new UniqueIdType( + UniqueIdDetermineTypeEvent.TYPE_UNKNOWN, + NamedTextColor.RED, + "luckperms.command.user.info.uuid-type.unknown", + "luckperms.command.user.info.uuid-type.desc.unknown" + ); public static UniqueIdType determineType(UUID uniqueId, LuckPermsPlugin plugin) { // determine initial type based on the uuid version @@ -65,10 +82,10 @@ public final class UniqueIdType { // if the uuid is version 2, assume it is an NPC // see: https://github.com/lucko/LuckPerms/issues/1470 // and https://github.com/lucko/LuckPerms/issues/1470#issuecomment-475403162 - type = TYPE_NPC; + type = UniqueIdDetermineTypeEvent.TYPE_NPC; break; default: - type = "unknown"; + type = UniqueIdDetermineTypeEvent.TYPE_UNKNOWN; break; } @@ -80,8 +97,10 @@ public final class UniqueIdType { return AUTHENTICATED; case UniqueIdDetermineTypeEvent.TYPE_UNAUTHENTICATED: return UNAUTHENTICATED; - case TYPE_NPC: + case UniqueIdDetermineTypeEvent.TYPE_NPC: return NPC; + case UniqueIdDetermineTypeEvent.TYPE_UNKNOWN: + return UNKNOWN; default: return new UniqueIdType(type); } @@ -90,13 +109,30 @@ public final class UniqueIdType { private final String type; private final Component component; - private UniqueIdType(String type) { - this(type, Component.text(type, NamedTextColor.GOLD)); + // constructor used for built-in types + private UniqueIdType(String type, TextColor displayColor, String translationKey, String translationKeyHover) { + this.type = type; + this.component = Component.translatable() + .key(translationKey) + .color(displayColor) + .hoverEvent(HoverEvent.showText(Component.translatable( + translationKeyHover, + NamedTextColor.DARK_GRAY + ))) + .build(); } - private UniqueIdType(String type, Component component) { + // constructor used for types provided via the API + private UniqueIdType(String type) { this.type = type; - this.component = component; + this.component = Component.text() + .content(type) + .color(NamedTextColor.GOLD) + .hoverEvent(HoverEvent.showText(Component.translatable( + "luckperms.command.user.info.uuid-type.desc.api", + NamedTextColor.GRAY + ))) + .build(); } public String getType() { diff --git a/common/src/main/resources/luckperms_en.properties b/common/src/main/resources/luckperms_en.properties index c587e836d..69300a4db 100644 --- a/common/src/main/resources/luckperms_en.properties +++ b/common/src/main/resources/luckperms_en.properties @@ -237,8 +237,15 @@ luckperms.command.generic.contextual-data.null-result=None luckperms.command.user.info.title=User Info luckperms.command.user.info.uuid-key=UUID luckperms.command.user.info.uuid-type-key=type -luckperms.command.user.info.uuid-type.mojang=mojang +luckperms.command.user.info.uuid-type.mojang=official luckperms.command.user.info.uuid-type.not-mojang=offline +luckperms.command.user.info.uuid-type.npc=npc +luckperms.command.user.info.uuid-type.unknown=unknown +luckperms.command.user.info.uuid-type.desc.mojang=This is a unique id for an official Minecraft: Java Edition account (online mode) +luckperms.command.user.info.uuid-type.desc.not-mojang=This is a pseudo unique id generated from the username (offline mode) +luckperms.command.user.info.uuid-type.desc.npc=This is a unique id for a NPC (non-player character) +luckperms.command.user.info.uuid-type.desc.unknown=This is an unknown unique id type +luckperms.command.user.info.uuid-type.desc.api=This is a unique id type specified via the LuckPerms API luckperms.command.user.info.status-key=Status luckperms.command.user.info.status.online=Online luckperms.command.user.info.status.offline=Offline