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

Fix for chat prefix/suffix handling and mention pattern issue #338

Open
DimaSergeew opened this issue Nov 29, 2024 · 0 comments
Open

Fix for chat prefix/suffix handling and mention pattern issue #338

DimaSergeew opened this issue Nov 29, 2024 · 0 comments

Comments

@DimaSergeew
Copy link

We encountered an issue where the chat prefixes and suffixes were not displaying correctly due to an invalid regular expression in the mention pattern. The error in the logs was a PatternSyntaxException caused by an unclosed group.

Steps Taken:

Fixed the pattern handling to properly escape special characters in the player's display name.
Updated the mentions.pattern configuration to avoid unclosed groups and ensure compatibility with the regex engine.
Code Fix: In the MentionsTransformStrategy class, modify the patternForPlayer method to properly escape player names in the regex pattern:

private Pattern patternForPlayer(Player player) {
    try {
        // Escape special regex characters in the player's display name
        String escapedUsername = Pattern.quote(player.getDisplayName());
        return playerPatternCache.get(player, () ->
                Pattern.compile(settingsConfig.getMentions().getPattern().replace("{username}", escapedUsername)));
    } catch (ExecutionException e) {
        throw new IllegalStateException("Cannot compile mention pattern", e);
    }
}

This fix ensures that the player's display name is safely inserted into the regular expression without causing syntax errors.

Additional Information: After modifying the pattern handling, the chat now displays prefixes and suffixes correctly, and mentions are processed as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant