Skip to content

Commit

Permalink
Begin work on v3.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Majekdor committed Oct 20, 2022
1 parent d8e10e8 commit 68f068a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.majek</groupId>
<artifactId>hexnicks</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
<packaging>jar</packaging>

<name>HexNicks</name>
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/dev/majek/hexnicks/event/PlayerChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public class PlayerChat implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onChat(final AsyncChatEvent event) {
if (HexNicks.config().CHAT_FORMATTER) {
HexNicks.logging().debug("paper chat event fired");
event.renderer((source, sourceDisplayName, message, viewer) ->
formatChat(source, PlainTextComponentSerializer.plainText().serialize(message))
);
HexNicks.logging().debug("Original message: " + PlainTextComponentSerializer.plainText().serialize(event.message()));
event.message(formatChat(event.getPlayer(), PlainTextComponentSerializer.plainText().serialize(event.message()), true));
}
}

Expand All @@ -40,7 +38,7 @@ public void onChat(final AsyncChatEvent event) {
* @param message the message
* @return formatted chat
*/
private @NotNull Component formatChat(final @NotNull Player source, final @NotNull String message) {
private @NotNull Component formatChat(final @NotNull Player source, final @NotNull String message, boolean justMessage) {
final MiniMessageWrapper miniMessageWrapper = MiniMessageWrapper.builder()
.advancedTransformations(source.hasPermission("hexnicks.chat.advanced"))
.gradients(source.hasPermission("hexnicks.color.gradient"))
Expand All @@ -50,22 +48,29 @@ public void onChat(final AsyncChatEvent event) {
.removeColors(MiscUtils.blockedColors(source))
.build();

return 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(miniMessageWrapper.mmParse(message)).build()
);
Component ret;
if (justMessage) {
ret = miniMessageWrapper.mmParse(message);
} else {
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(miniMessageWrapper.mmParse(message)).build()
);
}
HexNicks.logging().debug("Formatted message: " + PlainTextComponentSerializer.plainText().serialize(ret));
return ret;
}
}

0 comments on commit 68f068a

Please sign in to comment.