Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add '.' to valid usernames to support GeyserMC #416

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
9 changes: 7 additions & 2 deletions crates/valence_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,21 @@ impl fmt::Display for Username {
/// Returns whether or not the given string is a valid Minecraft username.
///
/// A valid username is 3 to 16 characters long with only ASCII alphanumeric
/// characters. The username must match the regex `^[a-zA-Z0-9_]{3,16}$` to be
/// characters. The username must match the regex `^[a-zA-Z0-9_\.]{3,16}$` to be
/// considered valid.
///
/// Although the dot character is not valid in Java edition, the GeyserMC
/// plugin uses it to differentiate Bedrock players, which means a dot is
/// possible if Valence is behind a proxy with GeyserMC support
///
/// # Examples
///
/// ```
/// # use valence_client::is_valid_username;
///
/// assert!(is_valid_username("00a"));
/// assert!(is_valid_username("jeb_"));
/// assert!(is_valid_username(".jeb"));
///
/// assert!(!is_valid_username("notavalidusername"));
/// assert!(!is_valid_username("NotValid!"));
Expand All @@ -496,7 +501,7 @@ pub fn is_valid_username(username: &str) -> bool {
(3..=16).contains(&username.len())
&& username
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_')
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '.')
}

#[derive(Component, Clone, PartialEq, Eq, Default, Debug)]
Expand Down
Loading