use of org.spongepowered.api.event.message.MessageEvent.DefaultHeaderApplier in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method createMessageChannelEventChat.
public static MessageChannelEvent.Chat createMessageChannelEventChat(ServerChatEvent forgeEvent) {
final ITextComponent forgeComponent = forgeEvent.getComponent();
final MessageFormatter formatter = new MessageFormatter();
MessageChannel channel;
Text[] chat = SpongeTexts.splitChatMessage((TextComponentTranslation) forgeComponent);
if (chat[1] == null) {
// Move content from head part to body part
chat[1] = chat[0] != null ? chat[0] : SpongeTexts.toText(forgeComponent);
chat[0] = null;
}
if (chat[0] != null) {
formatter.getHeader().add(new DefaultHeaderApplier(chat[0]));
}
formatter.getBody().add(new DefaultBodyApplier(chat[1]));
Text rawSpongeMessage = Text.of(forgeEvent.getMessage());
MessageChannel originalChannel = channel = ((Player) forgeEvent.getPlayer()).getMessageChannel();
Sponge.getCauseStackManager().pushCause(forgeEvent.getPlayer());
return SpongeEventFactory.createMessageChannelEventChat(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.ofNullable(channel), formatter, rawSpongeMessage, false);
}
Aggregations