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

AsyncChatEvent listener should maintain formatting #118

Open
danthedaniel opened this issue Sep 20, 2023 · 3 comments
Open

AsyncChatEvent listener should maintain formatting #118

danthedaniel opened this issue Sep 20, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@danthedaniel
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When using multiple chat formatters, HexNicks will destroy formatting information

Describe the solution you'd like
When one plugin modifies text color/decoration, HexNicks should respect that.

@danthedaniel danthedaniel added the enhancement New feature or request label Sep 20, 2023
@danthedaniel
Copy link
Contributor Author

This seems like a simple bug:

@EventHandler(priority = EventPriority.LOWEST)

This should be EventPriority.HIGHEST. Or the code can pass through the Component unmodified.

@Majekdor
Copy link
Member

I see your point if there is a situation where someone wants to use some formatting prior to HexNicks formatting the chat. HexNicks' formatter was really only meant to be used by people who had no other chat formatting tool. So the solution in most cases is to just turn off the formatter in the config.

@danthedaniel
Copy link
Contributor Author

I had luck with passing through the Component:

/**
 * Format the chat for all server implementations.
 *
 * @param source  the chatter
 * @param message the message
 * @return formatted chat
 */
private @NotNull Component formatChat(final @NotNull Player source, final @NotNull Component message) {
    final MiniMessageWrapper miniMessageWrapper = MiniMessageWrapper.builder()
            .advancedTransformations(source.hasPermission("hexnicks.chat.advanced"))
            .gradients(source.hasPermission("hexnicks.color.gradient"))
            .hexColors(source.hasPermission("hexnicks.color.hex"))
            .legacyColors(HexNicks.config().LEGACY_COLORS)
            .removeTextDecorations(MiscUtils.blockedDecorations(source))
            .removeColors(MiscUtils.blockedColors(source))
            .build();

    Component ret = miniMessageWrapper
            .mmParse(HexNicks.hooks().applyPlaceHolders(source, HexNicks.config().CHAT_FORMAT))
            // Replace display name placeholder with HexNicks nick
            .replaceText(TextReplacementConfig.builder().matchLiteral("{displayname}")
                    .replacement(HexNicks.core().getDisplayName(source)).build())
            // Replace prefix placeholder with Vault prefix
            .replaceText(TextReplacementConfig.builder().matchLiteral("{prefix}")
                    .replacement(HexNicks.hooks().vaultPrefix(source)).build())
            // Replace suffix placeholder with Vault Suffix
            .replaceText(TextReplacementConfig.builder().matchLiteral("{suffix}")
                    .replacement(HexNicks.hooks().vaultSuffix(source)).build())
            // Replace message placeholder with the formatted message from the event
            .replaceText(TextReplacementConfig.builder().matchLiteral("{message}")
                    .replacement(message).build());
    HexNicks.logging()
            .debug("Formatted message: " + PlainTextComponentSerializer.plainText().serialize(ret));
    return ret;
}

Would you accept such a patch?

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

No branches or pull requests

2 participants