Search in sources :

Example 1 with NucleusNoFormatChannel

use of io.github.nucleuspowered.nucleus.api.chat.NucleusNoFormatChannel 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)));
}
Also used : ChatTemplateConfig(io.github.nucleuspowered.nucleus.modules.chat.config.ChatTemplateConfig) NucleusNoFormatChannel(io.github.nucleuspowered.nucleus.api.chat.NucleusNoFormatChannel) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Text(org.spongepowered.api.text.Text)

Aggregations

NucleusNoFormatChannel (io.github.nucleuspowered.nucleus.api.chat.NucleusNoFormatChannel)1 ChatTemplateConfig (io.github.nucleuspowered.nucleus.modules.chat.config.ChatTemplateConfig)1 MessageEvent (org.spongepowered.api.event.message.MessageEvent)1 Text (org.spongepowered.api.text.Text)1