use of org.spongepowered.common.interfaces.IMixinInitCause in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method createServerChatEvent.
// Server events
private static ServerChatEvent createServerChatEvent(Event event) {
MessageChannelEvent.Chat spongeEvent = (MessageChannelEvent.Chat) event;
Optional<Player> player = spongeEvent.getCause().first(Player.class);
if (!player.isPresent()) {
return null;
}
Text spongeText = spongeEvent.getOriginalMessage();
ITextComponent component = SpongeTexts.toComponent(spongeText);
if (!(component instanceof TextComponentTranslation)) {
component = new TextComponentTranslation("%s", component);
}
// Using toPlain here is fine, since the raw message from the client
// can't have formatting.
ServerChatEvent forgeEvent = new ServerChatEvent((EntityPlayerMP) player.get(), spongeEvent.getOriginalMessage().toPlain(), (TextComponentTranslation) component);
((IMixinInitCause) forgeEvent).initCause(spongeEvent.getCause());
return forgeEvent;
}
Aggregations