use of io.github.nucleuspowered.nucleus.modules.chat.config.ChatTemplateConfig in project Nucleus by NucleusPowered.
the class ChatListener method onPlayerChatInternal.
private void onPlayerChatInternal(MessageChannelEvent.Chat event, Player player) {
if (!event.getContext().get(EventContexts.SHOULD_FORMAT_CHANNEL).orElse(true) || event.getChannel().isPresent() && event.getChannel().get() instanceof NucleusNoFormatChannel && !((NucleusNoFormatChannel) event.getChannel().get()).formatMessages()) {
if (((NucleusNoFormatChannel) event.getChannel().get()).removePrefix()) {
event.getFormatter().setHeader(Text.EMPTY);
}
// Not interested in applying these transforms.
return;
}
MessageEvent.MessageFormatter eventFormatter = event.getFormatter();
Text rawMessage = eventFormatter.getBody().isEmpty() ? event.getRawMessage() : eventFormatter.getBody().toText();
Text prefix = Text.EMPTY;
// Avoid adding <name>.
if (!chatConfig.isOverwriteEarlyPrefixes() && !prefixPattern.matcher(eventFormatter.getHeader().toText().toPlain()).matches()) {
prefix = eventFormatter.getHeader().toText();
}
Text footer = chatConfig.isOverwriteEarlySuffixes() ? Text.EMPTY : event.getFormatter().getFooter().toText();
final ChatTemplateConfig ctc;
if (chatConfig.isUseGroupTemplates()) {
ctc = templateUtil.getTemplateNow(player);
} else {
ctc = chatConfig.getDefaultTemplate();
}
event.setMessage(Text.join(prefix, ctc.getPrefix().getForCommandSource(player)), chatConfig.isModifyMainMessage() ? useMessage(player, rawMessage, ctc) : rawMessage, Text.join(footer, ctc.getSuffix().getForCommandSource(player)));
}
Aggregations