Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add allowedInKey(char) method to check character validity for keys
  • Loading branch information
NonSwag committed Aug 12, 2025
commit a163e07e80b5ff7e7477ff2d49e09edfd195dc40
11 changes: 11 additions & 0 deletions key/src/main/java/net/kyori/adventure/key/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ static boolean parseableValue(final @NotNull String value) {
return OptionalInt.empty();
}

/**
* Checks if {@code character} is a valid character in a key.
*
* @param character the character to check
* @return {@code true} if {@code character} is a valid character in a key, {@code false} otherwise
* @since 4.25.0
*/
static boolean allowedInKey(final char character) {
return KeyImpl.allowedInKey(character);
}

/**
* Checks if {@code value} is a valid character in a namespace.
*
Expand Down
4 changes: 4 additions & 0 deletions key/src/main/java/net/kyori/adventure/key/KeyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ private static void checkError(final String name, final String checkPart, final
}
}

static boolean allowedInKey(final char character) {
return character == ':' || allowedInNamespace(character) || allowedInValue(character);
}

static boolean allowedInNamespace(final char character) {
return character == '_' || character == '-' || (character >= 'a' && character <= 'z') || (character >= '0' && character <= '9') || character == '.';
}
Expand Down